Le Veilleur .:. .:. | Code :
- // GETINFO SCRIPTING
- // Allociné France import
- (***************************************************
- * Movie importation script for: *
- * Allociné France, http://www.allocine.fr *
- * *
- * (c) 2002 Antoine Potten antoine@buypin.com *
- * Improvements made by Soltan *
- * *
- * 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_FR;
- 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
- Line, Value: string;
- LineNr, IntValue: Integer;
- BeginPos, EndPos: Integer;
- begin
- // 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></FONT>', Line) = 0 then
- begin
- EndPos := pos('</FONT>', Line);
- Value := copy(Line, BeginPos, EndPos - BeginPos);
- SetField(fieldOriginalTitle, Value);
- end else
- begin
- EndPos := pos('<font >(', Line);
- Value := copy(Line, BeginPos, EndPos - BeginPos - 1);
- SetField(fieldTranslatedTitle, Value);
- BeginPos := EndPos + 8;
- EndPos := pos(')</font>', Line);
- 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;
- // Comments
- if pos('mn.', Line) > 0 then
- begin
- Value := copy(Line, pos('mn.', Line) + 4, pos('</TD>', Line) - 1);
- HTMLRemoveTags(Value);
- HTMLDecode(Value);
- SetField(fieldComments, Value);
- 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, Trim(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, Trim(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 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é.fr Import', 'Entrez le titre du film ou l''adresse de la page :', MovieName) then
- begin
- if Pos('.allocine.', MovieName) > 0 then
- AnalyzePage(MovieName)
- else
- AnalyzePage('http://www.allocine.fr/recherche/default.html?motcle='+UrlEncode(MovieName));
- // 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.
|
|