Code: Select all
// GETINFO SCRIPTING
// Moviecovers (FR) import
(***************************************************
* Movie importation script for: *
* Moviecovers, http://www.moviecovers.com *
* *
* (c) 2003 Antoine Potten software@antp.be *
* *
* For use with Ant Movie Catalog 3.4.2 *
* www.antp.be/software/moviecatalog *
* *
* The source code of the script can be used in *
* another program only if full credits to *
* script author and a link to Ant Movie Catalog *
* website are given in the About box or in *
* the documentation of the program *
***************************************************)
program MovieCovers;
const
LargePicture = True; // set it to True to import large picture
var
MovieName: string;
LineNr: 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;
procedure AnalyzePage(Address: string);
var
Line, Value: string;
LastLine, BeginPos, EndPos: Integer;
Page: TStringList;
begin
Line := GetPage(Address);
if Pos('il n''y a pas de film correspondant à ce(s) critère(s) dans <B>MOVIECOVERS</B>', Line) > 0 then
begin
ShowMessage('No movie found');
Exit;
end;
PickTreeClear;
BeginPos := Pos('<FONT size="+1" color="#000000"><B>', Line);
Delete(Line, 1, BeginPos - 1);
EndPos := Pos('</FONT>', Line);
Value := Copy(Line, 1, EndPos - 1);
HTMLRemoveTags(Value);
HTMLDecode(Value);
BeginPos := Pos(' <TABLE border=0 cellspacing=0 cellpadding=6 align="center" width="100%">', Line) + 1;
Delete(Line, 1, BeginPos);
EndPos := Pos(' <TABLE border=0 cellspacing=0 cellpadding=6 align="center" width="100%">', Line) + 1;
Delete(Line, EndPos, Length(Line));
Page := TStringList.Create;
Page.Text := Line;
Value := Trim(Value) + ' : ' + Trim(Page.GetString(2));
PickTreeAdd(Value, '');
for LineNr := 3 to Page.Count-1 do
begin
Line := Page.GetString(LineNr);
if Pos('<LI><A', Line) > 0 then
begin
BeginPos := Pos('/film/titre', Line);
EndPos := Pos('">', Line);
Value := 'http://www.moviecovers.com' + Copy(Line, BeginPos, EndPos - BeginPos);
HTMLRemoveTags(Line);
PickTreeAdd(Trim(Line), Value);
end;
end;
if PickTreeExec(Address) then
AnalyzeMoviePage(Address);
Page.Free;
end;
function TwoLinesAfter(Pattern: string; Page: TStringList): string;
begin
LineNr := FindLine(Pattern, Page, LineNr);
Result := Page.GetString(LineNr+2);
HTMLRemoveTags(Result);
HTMLDecode(Result);
Result := Trim(Result);
end;
procedure AnalyzeMoviePage(Address: string);
var
Line, Value: string;
BeginPos, EndPos, IntValue: Integer;
Page: TStringList;
begin
SetField(fieldURL, Address);
Page := TStringList.Create;
Page.Text := GetPage(Address);
LineNr := FindLine('<FONT color="#000000" size="+2">', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
HTMLRemoveTags(Line);
SetField(fieldTranslatedTitle, Line);
end;
SetField(fieldOriginalTitle, TwoLinesAfter('<TH align="right" valign="top">Titre original</TH>', Page));
if GetField(fieldOriginalTitle) = '' then
SetField(fieldOriginalTitle, GetField(fieldTranslatedTitle));
SetField(fieldDirector, TwoLinesAfter('<TH align="right" valign="top">Réalisateur</TH>', Page));
SetField(fieldYear, TwoLinesAfter('<TH align="right" valign="top">Année</TH>', Page));
SetField(fieldCountry, TwoLinesAfter('<TH align="right" valign="top">Nationalité</TH>', Page));
SetField(fieldCategory, TwoLinesAfter('<TH align="right" valign="top">Genre</TH>', Page));
Value := TwoLinesAfter('<TH align="right" valign="top">Durée</TH>', Page);
BeginPos := Pos('H', Value);
IntValue := (StrToInt(Copy(Value, 1, BeginPos - 1), 0) * 60) + (StrToInt(Copy(Value, BeginPos + 1, Length(Value)), 0));
SetField(fieldLength, IntToStr(IntValue));
SetField(fieldActors, TwoLinesAfter('<TH align="right" valign="top">Acteurs principaux</TH>', Page));
SetField(fieldProducer, TwoLinesAfter('<TH align="right" valign="top">Distribution</TH>', Page));
if LargePicture then
begin
LineNr := FindLine('<A href="/getjpg.html/', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := Pos('/getjpg.html/', Line)+13;
Value := Copy(Line, BeginPos, Length(Line));
Delete(Value, Length(Value)-1, 1);
GetPicture('http://data.moviecovers.com/DATA/zipcache/' + Value, False);
end;
end
else
begin
LineNr := FindLine('hspace=20 vspace=4 src="http://www.moviecovers.com/DATA/thumbs', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := Pos('http://', Line);
EndPos := Pos('"></A>', Line);
Value := Copy(Line, BeginPos, EndPos - BeginPos);
GetPicture(Value, False);
end;
end;
Page.Free;
DisplayResults;
end;
begin
if CheckVersion(3,4,2) then
begin
MovieName := GetField(fieldTranslatedTitle);
if MovieName = '' then
MovieName := GetField(fieldOriginalTitle);
if Input('MovieCovers import', 'Entrez le titre du film :', MovieName) then
begin
AnalyzePage('http://www.moviecovers.com/multicrit.html?titre=' + UrlEncode(MovieName) + '&slow=1&listes=1');
end;
end else
ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.2)');
end.
//begin
// MovieName := GetField(fieldOriginalTitle);
// if MovieName = '' then
// MovieName := GetField(fieldTranslatedTitle);
//end.