(*************************************************** Ant Movie Catalog importation script www.antp.be/software/moviecatalog/ [Infos] Authors=Peter Varju (varjupe@gmail.com) & bad4u Title=port.hu Description=Imports hungarian titles and description from port.hu site Site=port.hu Language=HU Version=3.4 Requires=3.5.0 Comments=Last modification: 2009.11.23 License=This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. | GetInfo=1 [Options] Alapértelmezett nyelv=1|1|1=Nincs alapértelemezett|2=Magyar|3=Angol ***************************************************) program PortHU; var MovieName, MovieURL: string; BeginPos, EndPos: Integer; function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer; var i: Integer; begin result := -1; if StartAt < 0 then StartAt := 0; for i := StartAt to List.Count-1 do if Pos(Pattern, List.GetString(i)) <> 0 then begin result := i; Break; end; end; function GetName(Page: TStringList; SearchStr: string): string; var i: Integer; Line, Value, Temp: string; LineNr: Integer; BeginPos, EndPos: Integer; begin result := ''; LineNr := FindLine('' + SearchStr + ':', Page, 0); if LineNr > -1 then begin Line := Page.GetString(LineNr); BeginPos := pos('' + SearchStr + ':', Line)+33+Length(SearchStr); Delete(Line, 1, BeginPos-1); EndPos := pos('
', Line)-1; Value := copy(Line, 0, EndPos); if (value='') then begin Line := Page.GetString(LineNr); BeginPos := pos('' + SearchStr + ':', Line)+20+Length(SearchStr); Delete(Line, 1, BeginPos-1); repeat If (Value<>'') then Value := Value + ', '; BeginPos := pos(' target="_top">', Line)+15; Delete(Line, 1, BeginPos-1); EndPos := pos('', Line)-1; Value := Value + copy(Line, 0, EndPos); Temp := copy(Line, EndPos+1, 12); until (Temp <> ','); end; HTMLRemoveTags(Value); result := Value; end; end; procedure AnalyzePage(Address: string); var Page: TStringList; begin Page := TStringList.Create; //Showmessage('AnalyzePage. Address:' + Address); Page.Text := GetPage(Address); if pos('Nincs ilyen című film', Page.Text) <> 0 then showmessage('Nincs ilyen című film a PORT adatbázisban.') else begin if pos('navigation string', Page.Text) = 0 then begin MovieURL := Address; AnalyzeMoviePage(Page); end else begin PickTreeClear; AddMoviesTitles(Page,'/pls/fi/films.film_page'); if PickTreeExec(Address) then begin UrlEncode(Address); Address := StringReplace(Address, '&', 'xxampxx'); Address := StringReplace(Address, '&', 'xxampxx'); HTMLDecode(Address); Address := StringReplace(Address, 'xxampxx', '&'); AnalyzePage(Address); end; end; end; Page.Free; end; procedure AnalyzeMoviePage(Page: TStringList); var Line, Line2, Temp, Value, Value2, FullValue, CommentString, Lang: string; LineNr: Integer; BeginPos, EndPos: Integer; i: Integer; tries: Integer; begin //Showmessage('Analyzing...'); //URL setField(fieldURL, MovieURL); //hungarian title LineNr := FindLine('blackbigtitle">', Page, 0); if LineNr > -1 then begin Line := Page.GetString(LineNr); BeginPos := pos('blackbigtitle">', Line)+15; EndPos := pos('
', Line); Value := copy(Line, BeginPos, EndPos - BeginPos); HTMLRemoveTags(Value); SetField(fieldTranslatedTitle, Value); SetField(fieldOriginalTitle, Value); end; //original title LineNr := LineNr + 1; Line := Page.GetString(LineNr); BeginPos := pos('"txt">(', Line)+7; EndPos := pos(')', Line); if pos('"txt">(', Line) <> 0 then Value := copy(Line, BeginPos, EndPos - BeginPos); if ( Value<>'') then begin HTMLRemoveTags(Value); SetField(fieldOriginalTitle, Value); end; //year LineNr := FindLine('perc, ', Page, 0); if LineNr > -1 then begin Line := Page.GetString(LineNr); BeginPos := pos('perc, ', Line)+6; Value := copy(Line, BeginPos, 4); Value2 := Copy(Value, 1, 2); if (Value2='19') or (Value2='20') or (Value2='21') then SetField(fieldYear, Value); end; //category, country LineNr := FindLine('"btxt">', Page, 0); if LineNr > -1 then begin Line := Page.GetString(LineNr); BeginPos := pos('"btxt">', Line)+7; EndPos := pos('
', Line); Value := copy(Line, BeginPos, EndPos - BeginPos); Value := stringReverse(Value); Value2:=Value; //cutting year EndPos := pos(',', Value); Delete(Value, EndPos, Length(Value)-1); Value := stringReverse(Value); Value := Copy(trim(Value), 0, 2); if (Value='19') or (Value='20') or (Value='21') then Value2:=Copy(Value2, 7, Length(Value2)); //movie length Value := Value2; if Copy(Value,0,5)='crep ' then begin EndPos := pos(',', Value); Value:=Copy(Value, 6, EndPos-7); Value:=stringReverse(Value); SetField(fieldLength, Value); end; //cutting time Value := Value2; if Copy(Value,0,5)='crep ' then begin EndPos := pos(',', Value); Delete(Value, 1, EndPos); end; Value := stringReverse(Value); //cutting colors if pos('színes, fekete-fehér, ',Value)=1 then begin Delete(Value, 1, 22); end else if (pos('fekete-fehér, ',Value)=1) or (pos('színes, ',Value)=1) then begin EndPos := pos(' ', Value); Delete(Value, 1, EndPos); end; //cutting language type if (pos('magyarul beszélő, ',Value)=1) then begin Delete(Value, 1, 18); end; if (pos('hangalámondásos, ',Value)=1) then begin Delete(Value, 1, 17); end; if (pos('feliratos, ',Value)=1) then begin Delete(Value, 1, 11); end; if (pos('némafilm, ',Value)=1) then begin Delete(Value, 1, 10); end; Value2:=Copy(Value,0,pos(' ',Value)-1); Value:=Copy(Value,pos(' ',Value)+1,Length(Value)); SetField(fieldCategory, AnsiUpFirstLetter(Value)); SetField(fieldCountry, AnsiUpFirstLetter(Value2)); end; //actors LineNr := FindLine('szereplő(k):', Page, 0); if LineNr > -1 then begin i:=1; Value := ''; repeat Line := Page.GetString(LineNr+i); EndPos := pos('', Line); Value := Value + Line; i:=i+1; until ((EndPos>0) or (i>50)); (* BeginPos := pos('szereplő(k):', Line)+24; Delete(Line, 1, BeginPos-1); EndPos := pos('', Line)-1; Value := copy(Line, 0, EndPos); *) Value := StringReplace(Value, '
', #13#10); HTMLRemoveTags(Value); SetField(fieldActors, Value); end; //description BeginPos:=0; Line := ''; tries:=0; repeat LineNr := FindLine('
', Page, BeginPos); Line := Page.GetString(LineNr+1); //debug: Showmessage('1:'+Line); //debug: Showmessage('2:'+inttostr(LineNr)); BeginPos := LineNr+1; //debug: Showmessage('2:'+inttostr(pos('', Line))); until (Line = ' ') or (pos('', Line) > 0) or (LineNr=-1); //debug: Showmessage('3:'+Line); if (LineNr>-1) then begin Line := Page.GetString(LineNr+1); if ((copy(Line, 0, 18)<>'') or (copy(Line, 19, 1)=' ') or (copy(Line, 19, 7)='')) then Line := '' else LineNr:=0; end else begin Line := ''; end; if Line <> '' then begin BeginPos := pos('"txt">', Line)+6; Delete(Line, 1, BeginPos-1); EndPos := pos('', Line)-1; Value := copy(Line, 0, EndPos); Value := StringReplace(Value, '
', #13#10); HTMLRemoveTags(Value); SetField(fieldDescription, Value); end; //director SetField(fieldDirector, GetName(Page, 'rendező')); //producer SetField(fieldProducer, GetName(Page, 'producer')); //comments CommentString := ''; //comments - writer Value := GetName(Page, 'író'); if Value<>'' then CommentString := CommentString+'Író: '+Value+#13#10; //comments - screenwriter Value := GetName(Page, 'forgatókönyvíró'); if Value<>'' then CommentString := CommentString+'Forgatókönyvíró: '+Value+#13#10; //comments - cameraman Value := GetName(Page, 'operatőr'); if Value<>'' then CommentString := CommentString+'Operatőr: '+Value+#13#10; //comments - ?? designer Value := GetName(Page, 'díszlettervező'); if Value<>'' then CommentString := CommentString+'Díszlettervező: '+Value+#13#10; //comments - costum designer Value := GetName(Page, 'jelmeztervező'); if Value<>'' then CommentString := CommentString+'Jelmeztervező: '+Value+#13#10; //comments - music Value := GetName(Page, 'zene'); if Value<>'' then CommentString := CommentString+'Zene: '+Value+#13#10; //comments - executive producer Value := GetName(Page, 'executive producer'); if Value<>'' then CommentString := CommentString+'Executive producer: '+Value+#13#10; //comments - cutter Value := GetName(Page, 'vágó'); if Value<>'' then CommentString := CommentString+'Vágó: '+Value+#13#10; //comments - ?? Value := GetName(Page, 'látványtervező'); if Value<>'' then CommentString := CommentString+'Látványtervező: '+Value+#13#10; SetField(fieldComments, CommentString); //picture LineNr := FindLine('class="object_picture" src', Page, 0); if LineNr = -1 then LineNr := FindLine('src="http://media.port-network.com/picture/instance_', Page, 0); if LineNr > -1 then begin Line := Page.GetString(LineNr); BeginPos := pos('src="http://media.port-network.com/picture/instance_', Line) + 5; Delete(Line, 1, BeginPos-1); EndPos := pos('"', Line); Value := copy(Line, 1, EndPos - 1); if pos('http://media.port-network.com/picture/instance_', Value)<>0 then begin Value := StringReplace(Value, '_2', '_1'); Value := StringReplace(Value, '_3', '_1'); Value := StringReplace(Value, '_4', '_1'); end; //Showmessage(Value); GetPicture(Value); // False = do not store picture externally ; store it in the catalog file end; //Default language (if you want) case GetOption('Alapértelmezett nyelv') of 2: SetField(fieldLanguages, 'Magyar'); 3: SetField(fieldLanguages, 'Angol'); end; end; Function stringReverse(S : String): String; Var i : Integer; Begin Result := ''; For i := Length(S) DownTo 1 Do Begin Result := Result + Copy(S,i,1) ; End; End; procedure AddMoviesTitles(Page: TStringList; Tag: string); var Line: string; LineNr: Integer; MovieTitle, OriTitle, MovieAddress, MovieInfo: string; StartPos, EndPos: Integer; begin LineNr := FindLine(tag, Page, 0); if LineNr > -1 then begin PickTreeAdd('Találatok:', ''); Line := Page.GetString(LineNr); repeat StartPos := pos('"btxt">', Line) + 14; MovieTitle := Copy(Line, StartPos, Pos('', Line) - StartPos); StartPos := Pos('', Line) + 5; if ( Pos(' (',Line)>0) then begin OriTitle := Copy(Line, (StartPos+1), Pos(')
', Line) - (StartPos+1)); end else begin OriTitle := MovieTitle; end; MovieInfo:=''; StartPos := Pos('"txt"> (', Line) +8; Delete(Line, 1, StartPos-1); EndPos := Pos(') ', Line); MovieInfo := copy(Line, 1, EndPos-1); MovieTitle:=MovieTitle+' ('+OriTitle+'), '+MovieInfo; HTMLDecode(Movietitle); PickTreeAdd(MovieTitle, 'http://port.hu' + MovieAddress); LineNr := FindLine(tag, Page, LineNr+1); if LineNr > -1 then Line := Page.GetString(LineNr) else Line := ''; until Line = ''; end; end; begin if CheckVersion(3,5,0) then begin // trim the disk number MovieName := GetField(fieldOriginalTitle); MovieName := StringReplace(MovieName,' - cd1',''); MovieName := StringReplace(MovieName,' - CD1',''); MovieName := StringReplace(MovieName,'-CD1',''); MovieName := StringReplace(MovieName,'-cd1',''); if MovieName = '' then MovieName := GetField(fieldTranslatedTitle); if Input('Port.hu import', 'A keresendő film címe:', MovieName) then begin MovieName := StringReplace(MovieName, '&', 'xxampxx'); MovieName := UrlEncode(MovieName); MovieName := StringReplace(MovieName, 'xxampxx', '%26'); AnalyzePage('http://www.port.hu/pls/ci/cinema.film_list?i_film_title=' + MovieName + '&i_city_id=3372&i_county_id=-1'); end; end else ShowMessage('A szkript futtatásához szükség van az Ant Movie Catalog legújabb verziójára (De legalább a 3.5.0-esre) !'); end.