Je me suis essayé aux scripts


Voici le script :
Code: Select all
// GETINFO SCRIPTING
// Allociné France & DVDFR import with big picture
(***************************************************
* Movie importation script for: *
* Allociné France, http://www.allocine.fr *
* DVDFR, http://dvdfr.solexine.fr *
* *
* (c) 2002 Antoine Potten antoine@buypin.com *
* Improvements made by FrenchFrog_2 *
* *
* For use with Ant Movie Catalog 3.4.0 *
* www.ant.be.tf/moviecatalog ··· www.buypin.com *
* *
* 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 Allocine_DVDFR;
var
MovieName: string;
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
Page: TStringList;
LineNr: Integer;
Line: string;
BeginPos: Integer;
begin
Page := TStringList.Create;
Page.Text := GetPage(Address);
if pos('<TITLE>Recherche', Page.Text) = 0 then
AnalyzeMoviePage(Page)
else
begin
PickTreeClear;
LineNr := FindLine('AlloCiné</A> : <b>Recherche</b>', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('dans les titres de films', Line);
if BeginPos > 0 then
begin
Delete(Line, 1, BeginPos);
PickTreeAdd('Films déjà sortis', '');
AddMoviesTitles(Line);
end;
BeginPos := pos('dans les films déjà sortis (de ou avec)', Line);
if BeginPos > 0 then
begin
Delete(Line, 1, BeginPos);
PickTreeAdd('Films déjà sortis (de ou avec)', '');
AddMoviesTitles(Line);
end;
BeginPos := pos('dans les prochaines sorties de films', Line);
if BeginPos > 0 then
begin
Delete(Line, 1, BeginPos);
PickTreeAdd('Prochaines sorties', '');
AddMoviesTitles(Line);
end;
BeginPos := pos('dans les prochaines sorties de films (de ou avec)', Line);
if BeginPos > 0 then
begin
Delete(Line, 1, BeginPos);
PickTreeAdd('Prochaines sorties (de ou avec)', '');
AddMoviesTitles(Line);
end;
Line := Page.GetString(LineNr);
BeginPos := pos('<LI><A HREF="rubrique.html?typerecherche=3&', Line);
if BeginPos > 0 then
begin
Delete(Line, 1, BeginPos + 12);
PickTreeMoreLink('http://www.allocine.fr/recherche/' + copy(Line, 1, pos('"', Line) - 1));
end;
if PickTreeExec(Address) then
AnalyzePage(Address);
end;
end;
Page.Free;
end;
procedure AnalyzeMoviePage(Page: TStringList);
var
Pageaff: TStringList;
Line, Value: string;
LineNr: Integer;
IntValue: Integer;
BeginPos: Integer;
EndPos: Integer;
begin
// Picture
LineNr := FindLine('allocine.fr/acmedia/images/affiches', Page, 0);
if LineNr = -1 then
LineNr := FindLine('&big=1&page=1.html"><', Page, 0);
if LineNR > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('><A HRef="', Line) + 10;
if BeginPos > 10 then
begin
EndPos := pos('">', Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
end;
Pageaff := TStringList.Create;
Pageaff.Text := GetPage('http://www.allocine.fr' + Value);
LineNr := FindLine('.html"><IMG border=0 src="', Pageaff, 0);
if LineNR > -1 then
begin
Line := Pageaff.GetString(LineNr);
BeginPos := pos('.html"><IMG border=0 src="', Line) + 26;
if BeginPos > 10 then
begin
EndPos := pos('" Zalt=', Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
GetPicture(Value, False);
end;
end;
Pageaff.Free;
end;
// Original & Translated Title
LineNr := FindLine('<FONT Class="titrePage">', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('<FONT Class="titrePage">', Line) + 24;
if pos('<font size=2>', Line) = 0 then
begin
EndPos := pos('</FONT>', Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
SetField(fieldOriginalTitle, Value);
end else
begin
EndPos := pos('<font size=2>', Line);
Value := copy(Line, BeginPos, EndPos - BeginPos - 1);
if Value := '' then
begin
Value := GetField(fieldOriginalTitle)
end;
SetField(fieldTranslatedTitle, Value);
BeginPos := EndPos + 14;
EndPos := pos('</font>', Line) - 1;
Value := copy(Line, BeginPos, EndPos - BeginPos);
SetField(fieldOriginalTitle, Value);
end;
//Country
if pos('<FONT Class="size2">', Line) > 0 then
begin
Delete(Line, 1, pos('<FONT Class="size2">', Line) + 19);
EndPos := pos('</FONT>', Line);
Value := copy(Line, 1, EndPos - 1);
SetField(fieldCountry, Value);
Delete(Line, 1, pos('</FONT>', Line));
end;
// Year
if pos('(', Line) > 0 then
begin
Delete(Line, 1, pos('(', Line));
EndPos := pos(')', Line) - 1;
Value := copy(Line, 1, EndPos);
SetField(fieldYear, Value);
end;
// Category
if pos('Class="size2"', Line) > 0 then
begin
Delete(Line, 1, pos('">', Line) + 1);
EndPos := pos('</FONT>', Line);
Value := copy(Line, 1, EndPos - 1);
SetField(fieldCategory, Value);
end;
// Length
if pos('Durée ', Line) > 0 then
begin
Delete(Line, 1, pos(': ', Line) + 6);
IntValue := StrToInt(copy(Line, 1, 1), 0) * 60;
if pos('mn.', Line) > 0 then
IntValue := IntValue + StrToInt(copy(Line, 4, 2), 0);
SetField(fieldLength, IntToStr(IntValue));
end;
// Actors
if pos('"titreDescription">Avec', Line) > 0 then
begin
Delete(Line, 1, pos('Class="titreDescription">Avec', Line) + 34);
EndPos := pos('Plus...', Line);
if EndPos = 0 then
EndPos := pos('</TD>', Line);
Value := copy(Line, 1, EndPos - 1);
HTMLRemoveTags(Value);
HTMLDecode(Value);
SetField(fieldActors, Value);
end;
// Director
if pos('"titreDescription">Réalisé par', Line) > 0 then
begin
Delete(Line, 1, pos('Class="titreDescription">Réalisé par', Line) + 48);
EndPos := pos('Plus...', Line);
if (EndPos = 0) or (EndPos > pos('</TD>', Line)) then
EndPos := pos('</TD>', Line);
Value := copy(Line, 1, EndPos - 1);
HTMLRemoveTags(Value);
HTMLDecode(Value);
SetField(fieldDirector, Value);
end;
end;
// Description
LineNr := FindLine('>Synopsis<', Page, LineNr);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
Value := '';
repeat
BeginPos := pos('"size2">', Line);
if BeginPos > 0 then
BeginPos := BeginPos + 8
else
BeginPos := 1;
EndPos := pos('</FONT></DIV>', Line);
if EndPos = 0 then
EndPos := pos('<br>', Line);
if EndPos = 0 then
EndPos := Length(Line) + 1;
if EndPos > 0 then
Value := Value + copy(Line, BeginPos, EndPos - BeginPos) + #13#10;
EndPos := pos('</FONT></DIV>', Line);
if EndPos = 0 then
begin
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
EndPos := Pos('<SCRIPT', Line);
end;
until EndPos > 0;
HTMLRemoveTags(Value);
SetField(fieldDescription, Value);
end;
// URL
LineNr := FindLine('class="link10" target=_blank>', Page, LineNr);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('class="link10" target=_blank>', Line) + 29;
EndPos := pos('</A></TD></TR>', Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
SetField(fieldURL, Value);
end;
DisplayResults;
end;
procedure AnalyzePage2(Address: string);
var
Page: TStringList;
LineNr: Integer;
Line, Tags, Caption: string;
BeginPos, EndPos: Integer;
begin
Line := GetPage(Address);
if Pos('<title>Dvdfr.com - Recherche DVDFr', Line) > 0 then
begin
PickTreeClear;
if Pos('Vos critères de recherche n''ont produit aucun résultat.', Line) = 0 then
begin
Page := TStringList.Create;
EndPos := Pos('TITLE="Page précédente"', Line) + 5;
if EndPos > 5 then
begin
BeginPos := EndPos - 70;
Tags := Copy(Line, BeginPos, EndPos - BeginPos);
BeginPos := Pos('="..', Tags) + 4;
EndPos := Pos('" TITLE', Tags);
PickTreeAdd('Page précédente', 'http://dvdfr.solexine.fr' + Copy(Tags, BeginPos, EndPos - BeginPos));
end;
EndPos := Pos('TITLE="Page suivante"', Line) + 5;
if EndPos > 5 then
begin
BeginPos := EndPos - 70;
Tags := Copy(Line, BeginPos, EndPos - BeginPos);
BeginPos := Pos('="..', Tags) + 4;
EndPos := Pos('" TITLE', Tags);
PickTreeAdd('Page suivante', 'http://dvdfr.solexine.fr' + Copy(Tags, BeginPos, EndPos - BeginPos));
end;
BeginPos := Pos('<table class="tableSearchResult"', Line);
Delete(Line, 1, BeginPos + Length(Tags) - 1);
BeginPos := Pos('</TR>', Line);
Delete(Line, 1, BeginPos + 5);
EndPos := Pos('</table>', Line);
Delete(Line, EndPos, Length(Line));
while Pos('<TR', Line) > 0 do
begin
BeginPos := Pos('<TR', Line);
EndPos := Pos('</TR>', Line);
Tags := Copy(Line, BeginPos, EndPos - BeginPos);
if Pos('CLASS="tableHeaderLine"', Tags) > 0 then
begin // "Letter"
EndPos := Pos('</span>', Tags);
PickTreeAdd('Films commençant par "' + Copy(Tags, EndPos - 1, 1) + '" :', '');
end else
begin // Movie
Page.Text := Tags;
Tags := Page.GetString(2);
Delete(Tags, 1, 1);
BeginPos := Pos('="..', Tags) + 4;
EndPos := Pos('">', Tags);
Address := Copy(Tags, BeginPos, EndPos - BeginPos);
HTMLRemoveTags(Tags);
Caption := Trim(Tags);
Tags := Page.GetString(3);
Delete(Tags, 1, 1);
HTMLRemoveTags(Tags);
Tags := Trim(Tags);
if Tags <> ' ' then
Caption := Caption + ' (' + Tags + ')';
Tags := Page.GetString(4);
Delete(Tags, 1, 1);
HTMLRemoveTags(Tags);
Tags := Trim(Tags);
if Tags <> ' ' then
Caption := Caption + ', ' + Tags;
PickTreeAdd(Caption, 'http://dvdfr.solexine.fr' + Address);
end;
Delete(Line, 1, Pos('</TR>', Line) + 5);
end;
Page.Free;
end;
if PickTreeExec(Address) then
begin
AnalyzePage2(Address);
end;
end else
if Pos('<title>Dvdfr.com - Fiche DVD', Line) > 0 then
begin
SetField(fieldURL, Address);
AnalyzeMoviePage2(Line);
end;
end;
procedure AnalyzeMoviePage2(PageContents: string);
var
Line, Value: string;
LineNr, BeginPos, EndPos, BeginPos2, EndPos2, i : Integer;
Page: TStringList;
begin
// Producer
Delete(Line, 1, EndPos - 1);
HTMLRemoveTags(Line);
SetField(fieldProducer, Line);
// Note
LineNr := FindLine('/images/vote_dvdfr.gif', Page, LineNr);
if LineNr > -1 then
begin
Value := Trim(Page.GetString(LineNr));
HTMLRemoveTags(Value);
Value := StringReplace(Value, ' ', '');
EndPos := Pos(',', Value);
Line := value;
if EndPos > 0 then
Line := Copy(Value, 1, EndPos - 1);
SetField(fieldRating, Line);
end;
// Discs
LineNr := FindLine('<img alt="Nombre de disques"', Page, LineNr);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr + 1);
BeginPos := Pos('>', Line) + 1;
EndPos := Pos('</', Line);
Value := Copy(Line, BeginPos, EndPos - BeginPos);
SetField(fieldDisks, Value);
end;
// Bitrate
LineNr := FindLine('<img alt="Bitrate moyen"', Page, LineNr);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr + 1);
BeginPos := Pos('<td>', Line) + 4;
EndPos := Pos(' ', Line);
Value := Copy(Line, BeginPos, EndPos - BeginPos);
Value := StringReplace(Value, ',', '') + '0';
SetField(fieldVideoBitrate, Value);
end;
// Media type
SetField(fieldMediaType, 'DVD');
// Comments
Line := Page.Text;
BeginPos := Pos('</span><br>', Line) + 12;
Delete(Line, 1, BeginPos);
EndPos := Pos('<br>', Line);
Value := Copy(Line, 1, EndPos - 1);
HTMLRemoveTags(Value);
Value := 'Suppléments:' + #13#10 + Trim(Value);
SetField(fieldComments, Value);
// Video format
SetField(fieldResolution, '720x576');
SetField(fieldFramerate, '24');
// Zone
LineNr := FindLine('title="Zone(s) du DVD"', Page, LineNr);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr + 2);
BeginPos := Pos('alt="', Line) + 5;
EndPos := Pos('alt="', Line) + 15;
Value := 'DVD ' + Copy(Line, BeginPos, EndPos - BeginPos);
SetField(fieldVideoFormat, Value);
end;
// Audio format
LineNr := FindLine('title="Spécifications audio"', Page, LineNr);
if LineNr > -1 then
begin
BeginPos := LineNr + 2;
LineNr := FindLine('</table></td></tr>', Page, LineNr);
if LineNr > -1 then
begin
EndPos := LineNr;
Value := '';
Line := 'DVD ';
for i := BeginPos to EndPos do
begin
BeginPos2 := Pos('<small>', Page.GetString(i));
EndPos2 := Pos('</small>', Page.GetString(i));
if ((BeginPos2 > 0) and (EndPos2 > 0)) then
begin
if not(Value = '') then
Value := Value + ' - ';
Value := Value + Copy(Page.GetString(i), BeginPos2 + 7, EndPos2 - (BeginPos2 + 7));
end;
BeginPos2 := Pos('alt="', Page.GetString(i));
EndPos2 := Pos('" title="', Page.GetString(i));
if ((BeginPos2 > 0) and (EndPos2 > 0)) then
begin
if not(Line = 'DVD ') then
Line := Line + ' - ';
Line := Line + Copy(Page.GetString(i), BeginPos2 + 5, EndPos2 - (BeginPos2 + 5));
end;
end;
SetField(fieldAudioFormat, Line);
SetField(fieldLanguages, 'Français & Anglais');
end;
end;
// Sous-titres
LineNr := FindLine('title="Sous-titres disponibles"', Page, LineNr);
if LineNr > -1 then
begin
Line := StringReplace(Trim(Page.GetString(LineNr + 3)), #9, '');
HTMLRemoveTags(Line);
SetField(fieldSubtitles, Line);
end;
//
Page.Free;
end;
procedure FindReplaceCaps;
begin
SetField(fieldOriginalTitle, AnsiUpFirstLetter(AnsiLowerCase(GetField(fieldOriginalTitle))));
SetField(fieldOriginalTitle, AnsiMixedCase(GetField(fieldOriginalTitle),' '));
SetField(fieldTranslatedTitle, AnsiUpFirstLetter(AnsiLowerCase(GetField(fieldTranslatedTitle))));
SetField(fieldTranslatedTitle, AnsiMixedCase(GetField(fieldTranslatedTitle),' '));
end;
procedure AddMoviesTitles(var Line: string);
var
MovieTitle, MovieAddress: string;
StartPos, EndPos: Integer;
begin
repeat
StartPos := pos('<LI><A HREF="/film/fichefilm', Line);
if StartPos > 0 then
begin
Delete(Line, 1, StartPos + 12);
MovieAddress := copy(Line, 1, pos('"><FONT color=#003399>', Line) - 1);
StartPos := pos('#003399>', Line) + 8;
MovieTitle := copy(Line, StartPos, pos('</TD>', Line) - StartPos);
HTMLRemoveTags(MovieTitle);
PickTreeAdd(MovieTitle, 'http://www.allocine.fr' + MovieAddress);
end;
until (StartPos < 1) or ((pos('<LI><A HREF="/film/fichefilm', Line) > pos('<FONT class=size2 color=#AA0000>', Line)) and (pos('<FONT class=size2 color=#AA0000>', Line) > 0));
if (pos('Plus...',Line) > 0) and (pos('Plus...',Line) < pos('<FONT class=size4 color=#003399><B>',Line)) and (pos('Plus...',Line) < pos('<FONT class=size2 color=#AA0000><B>',Line)) then
begin
StartPos := pos('rubrique.html', Line);
EndPos := pos('Plus...',Line) - 16;
MovieAddress := copy(Line, StartPos, EndPos - StartPos);
PickTreeAdd('Plus... ', 'http://www.allocine.fr/recherche/' + MovieAddress);
end;
end;
begin
if CheckVersion(3,4,0) then
begin
MovieName := GetField(fieldOriginalTitle);
if MovieName = '' then
MovieName := GetField(fieldTranslatedTitle);
if Input('Allociné/DVDFR Import', 'Entrez le titre du film :', MovieName) then
begin
AnalyzePage('http://www.allocine.fr/recherche/default.html?motcle='+UrlEncode(MovieName));
AnalyzePage2('http://dvdfr.solexine.fr/search/search.php?multiname='+UrlEncode(MovieName));
DisplayResults;
// AnalyzePage('http://www.allocine.fr/recherche/rubrique.html?typerecherche=3&motcle='+UrlEncode(MovieName));
end;
end else
ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.0)');
end.