[FR] import en grand nombre via Allociné France big picture
Posted: 2004-02-03 17:03:58
Bonjour,
voivi une minuscule modif que j'ai faite pour automatiser, comme sur le cite de umdb us, l'import de données.
Uniquement interessant pur ceux qui n'ont pas envie de modifier un scritpt... (ou pour amélioration)
le code:
C'est absolument rien du tout puisque j'ai juste mis quelques trucs en commentaire afin que le script ne pose plus de question.
Il prend donc le premier de la liste qu'il trouve (on peut modifier ça facilement pour affiner un peu). Ca permet juste de dégrossir le travail.
On peut aussi imaginer que la saisie ce fasse automatiquement uniquement si une seule reponse est trouvée (moins risquer), cela reste à faire (facilement....)
P.S: je n'ai pas vu ce que ca donner si aucune reponse n'est donnée (plante??)
voivi une minuscule modif que j'ai faite pour automatiser, comme sur le cite de umdb us, l'import de données.
Uniquement interessant pur ceux qui n'ont pas envie de modifier un scritpt... (ou pour amélioration)
le code:
C'est absolument rien du tout puisque j'ai juste mis quelques trucs en commentaire afin que le script ne pose plus de question.
Il prend donc le premier de la liste qu'il trouve (on peut modifier ça facilement pour affiner un peu). Ca permet juste de dégrossir le travail.
On peut aussi imaginer que la saisie ce fasse automatiquement uniquement si une seule reponse est trouvée (moins risquer), cela reste à faire (facilement....)
P.S: je n'ai pas vu ce que ca donner si aucune reponse n'est donnée (plante??)
Code: Select all
// GETINFO SCRIPTING
// Allociné France import with big picture
(***************************************************
* Movie importation script for: *
* Allociné France, http://www.allocine.fr *
* *
* (c) 2002-2004 Antoine Potten *
* software@antp.be *
* Improvements made by Soltan *
* Modifications by Wallys to import big picture *
* *
* For use with Ant Movie Catalog 3.4.0 *
* 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 Allocine_FR;
const
ExternalPictures = False;
{ True: Les images seront stockées en tant que fichiers dans le même dossier que le catalogue
False: Les images seront stockées dans le catalogue (seulement pour les fichiers .amc) }
test_perf = False;
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
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);
AddMoviesTitles(Line, Address);
AnalyzePage(Line);
end
else
if test_perf then
begin
PickTreeClear;
PickTreeAdd('Film nom trouvé', '');
if PickTreeExec(Address) then not_auto = false;
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
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/medias/nmedia', 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);
Pageaff := TStringList.Create;
Pageaff.Text := GetPage('http://www.allocine.fr' + Value);
LineNr := FindLine('img5.allocine.fr/acmedia/medias', Pageaff, 0);
if LineNr = -1 then
LineNr := FindLine('img5.allocine.fr/acmedia//medias', Pageaff, 0);
if LineNR > -1 then
begin
Line := Pageaff.GetString(LineNr);
BeginPos := pos('<IMG border=0 src="', Line) + 19;
Delete(Line, 1, BeginPos);
EndPos := Pos('"', Line);
Delete(Line, EndPos, Length(Line));
GetPicture(Line, ExternalPictures);
end;
Pageaff.Free;
end
else // cas où l'image réduite n'est pas un lien : il faut chercher le lien "Photos" et prendre la première image de la page qui suit
begin
LineNr := FindLine('/bouton_photos.gif', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('><A HREF="', Line) + 10;
if BeginPos > 10 then
begin
EndPos := pos('"><IMG', Line);
Value := Copy(Line, BeginPos, EndPos - BeginPos);
Pageaff := TStringList.Create;
Pageaff.Text := GetPage('http://www.allocine.fr' + Value);
LineNr := FindLine('img5.allocine.fr/acmedia/medias', Pageaff, 0);
if LineNr = -1 then
LineNr := FindLine('img5.allocine.fr/acmedia//medias', Pageaff, 0);
if LineNr > -1 then
begin
Line := Pageaff.GetString(LineNr);
BeginPos := Pos('<IMG border=0 src="', Line) + 19;
Delete(Line, 1, BeginPos);
EndPos := Pos('"', Line);
Delete(Line, EndPos, Length(Line));
GetPicture(Line, ExternalPictures);
end;
end;
end;
end;
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></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
BeginPos := pos('Class="size2"', Line);
if (BeginPos > 0) and (pos('Class="size2">Durée', Line) > BeginPos) 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 := '';
if Pos('"size2">', Line) > 0 then
begin
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) or (EndPos < BeginPos) 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;
end;
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; Adresse : string);
var
MovieTitle, MovieAddress, b, temp: string;
titre :TStringList;
StartPos, EndPos, i, max, counter,n: Integer;
begin
try
titre:= TStringList.Create ;
PickTreeClear;
i:=0; max:=0; counter:=0;
repeat
StartPos := pos(' ', MovieName);
if StartPos > 1 then
begin
titre.add(copy(MovieName,1, StartPos-1));
delete(MovieName,1, StartPos);
i:=i+1;
end
until (StartPos < 1) ;
titre.add( MovieName);
repeat
// recherche première occurence d'une fiche de film...
StartPos := pos('<LI><A HREF="/film/fichefilm', Line);
if StartPos > 0 then
begin
// supprime la partie : <LI><A HREF=...
Delete(Line, 1, StartPos + 12);
// recupère la référnec de la fiche qui se termine par : "><FONT color=#003399>
MovieAddress := copy(Line, 1, pos('"><FONT color=#003399>', Line) - 1);
// suprime le texte :#003399> (indiquant la couleur) qui separe l'adresse de la fiche du nom du film
// avec le nom du realisateur et des acteurs...
StartPos := pos('#003399>', Line) + 8;
MovieTitle := copy(Line, StartPos, pos('</TD>', Line) - StartPos);
// sypprime la mise en forme du texte à la html (font...
HTMLRemoveTags(MovieTitle);
for i := 0 to titre.Count-1 do
begin
n := pos( titre.GetString(i),MovieTitle) ;
if n>0 then
counter:=counter+1;
end
if counter>max then
begin
temp:= copy(Line, 1, pos('"><FONT color=#003399>', Line) - 1);
max:=counter;
end;
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 test_perf then
Showmessage(' Résultat: ' +temp);
Line :=temp;
titre.Free;
except
Writeln(ExceptionParam);
end;
end;
//------------------------------------
begin
if CheckVersion(3,4,0) then
begin
MovieName := GetField(fieldOriginalTitle);
if MovieName = '' then
MovieName := GetField(fieldTranslatedTitle);
if Pos('.allocine.', MovieName) > 0 then
AnalyzePage(MovieName)
else
AnalyzePage('http://www.allocine.fr/recherche/default.html?motcle='+UrlEncode(MovieName));
end else
ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.0)');
end.