(***************************************************
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 = '