//_____________________________________________________________________________________\\ //------ SCRIPT : Allocine_Movie_Essai \\ //------ Author : Pra15 \\ //------ Date : 12/02/2015 \\ //_____________________________________________________________________________________\\ // const pauseBeforeLoad = 2000; // Pause before loading (in millisecond) nMaxAffiches = 6; // Nombre Maximum de photos affiches a télécharger nMaxPhotos = 2; // Nombre Maximum de photos a telecharger const //Script modes smSearch = 0; smNormal = 1; smCasting = 2; smBA = 3; smSecrets = 4; smAwards = 5; smPrePhoto = 6; smPhoto = 7; smFinished = 8; //Parse results prError = 0; prFinished = 1; prList = 2; prListImage = 3; prDownload = 4; //Credits types ctActors = 0; ctDirectors = 1; ctWriters = 2; ctComposers = 3; ctProducers = 4; //Script data SCRIPT_VERSION = '0.0.0.1'; SCRIPT_NAME = 'Allocine.fr(Essai)'; SCRIPT_DESC = '[FR] Get movie information from Allocine.com'; SCRIPT_LANG = $0c; //French SCRIPT_TYPE = 0; //Movies CODE_PAGE = 65001; //Autodetect 65001 RATING_NAME = 'ADE'; BASE_URL = 'http://www.allocine.fr'; SEARCH_STR = BASE_URL +'/recherche/1/?q=%s'; //Global Variables : var Mode: Byte; ELI, countPhoto : Integer; numMovie : String; ExtraLinks : Array [smCasting..smPhoto] of string; LinksPreAffiche, LinksAffiche, LinksPrePhoto, LinksPhoto : Array of String; function GetScriptVersion: string; begin Result := SCRIPT_VERSION; end; function GetScriptName: string; begin Result := SCRIPT_NAME; end; function GetScriptDesc: string; begin Result := SCRIPT_DESC; end; function GetRatingName: string; begin Result := RATING_NAME; end; function GetScriptLang: Cardinal; begin Result := SCRIPT_LANG; end; function GetCodePage: Cardinal; begin Result := CODE_PAGE; end; function GetBaseURL: AnsiString; begin Result := BASE_URL; end; function GetScriptType: Byte; begin Result := SCRIPT_TYPE; end; function GetCurrentMode: Byte; begin Result := Mode; end; function GetDownloadURL: AnsiString; begin LogMessage('GetdownloadURL demarre'); if Mode = smSearch then begin Result := SEARCH_STR end else if Mode = smPhoto then begin If countPhoto <= High(LinksPreAffiche) then begin Result := LinksPreAffiche[countPhoto]; end else if (countPhoto > High(LinksPreAffiche)) AND (countPhoto <= High(LinksPrePhoto)) then begin Result := LinksPrePhoto[countPhoto]; end; end else begin Result := ExtraLinks[Mode]; end; LogMessage('Mode sortie getdownloadURL:' + IntTostr(Mode)); end; function NextMode(curMode : Integer) : Integer; var I : Integer; begin Result := smFinished; if curMode < Low(ExtraLinks) - 1 then curMode := Low(ExtraLinks) - 1; for I := curMode + 1 to (High(ExtraLinks)-1) do if ExtraLinks[I] <> '' then begin Result := I; Break; end; If curMode = smPhoto then begin If countPhoto < (High(LinksPreAffiche)+High(LinksPrePhoto)) then begin Result := curMode; end else begin Result := curMode+1; end; end; end; ////////// PARSE FIRST PAGE ////////// procedure ParseFirstPage(MovieURL : String; HTML : String); Var CurPos, EndPos : Integer; Title : String; BEGIN LogMessage('Informations sur page principale du film:'); //Titre : //Addresse du film : AddFieldValueXML('url', MovieURL); //Titre du Film : CurPos := Pos('/breadcrumbs -->',HTML); CurPos := PosFrom('content="',HTML,CurPos)+9; EndPos := PosFrom('" />',HTML,CurPos); Title := Trim(Copy(HTML,CurPos,EndPos-CurPos)); LogMessage('Titre du Film: ' + Title); AddFieldValue(2, Title); //Numero Index du Film : CurPos := Pos('',HTML,StartSearch); CurPos := PosFrom('',HTML,CurPos); CurPos := PosFrom('',HTML,CurPos); LinksPrePhoto[i] := BASE_URL + Copy(HTML,CurPos,EndPos-CurPos); LogMessage('Lien Photo n° ' + IntToStr(i) +' '+ LinksPrePhoto[i]); CurPos := PosFrom('',HTML); CurPos := PosFrom(', HTML, CurPos)-1;
 
	If (countPhoto <= High(LinksPreAffiche)) then begin
		LinksAffiche[CountPhoto] := BASE_URL + copy(HTML,CurPos,EndPos-CurPos);
	end else if (countPhoto > High(LinksPreAffiche)) AND (countPhoto < (High(LinksPreAffiche) + High(LinksPrePhoto))) then begin
		LinksPhoto[CountPhoto] := BASE_URL + copy(HTML,CurPos,EndPos-CurPos);
	end else if countPhoto = (High(LinksPreAffiche) + High(LinksPrePhoto)) then begin
		LinksPhoto[CountPhoto] := BASE_URL + copy(HTML,CurPos,EndPos-CurPos);
		For i := 0 to (High(LinksPreAffiche)) do begin
			AddImageURL(0,LinksAffiche[i]);
		end;
		For i := (High(LinksPreAffiche)+1) to (High(LinksPreAffiche)+High(LinksPrePhoto)) do begin
			AddImageURL(1,LinksPhoto[i]);
		end;
	end;
 END;
//////////////////////////////
 
//////////////////////////////////////////////////////////////////////////////////////// 
procedure ParseSearchResults(HTML: string);
Var
CurPos, EndPos, EndSearch, nbResult, PosEssai1, PosEssai2 : Integer;
Year, MovieURL, ThumbURL, Title : String;

Begin
NbResult := 0;
CurPos := Pos(',HTML); If CurPos < 1 then Exit; CurPos := PosFrom('
',HTML,CurPos); //Addresse Thumbnail : CurPos := PosFrom('src=',HTML,CurPos)+5; EndPos := PosFrom('alt=',HTML,CurPos)-2; ThumbURL := Trim(Copy(HTML,CurPos,EndPos-CurPos)); //Addresse page Film : CurPos := PosFrom('1 0) AND (curPos < PosFrom('', HTML, endPos)) do begin EndPos := PosFrom('.html',HTML,CurPos)+5; MovieURL := BASE_URL + Trim(Copy(HTML,CurPos,EndPos-CurPos)); Logmessage('MovieURL : ' + MovieURL); //Nom Film : CurPos := PosFrom('>',HTML,EndPos)+1; EndPos := PosFrom('
',HTML,CurPos); Title := Copy(HTML,CurPos,EndPos-CurPos); Title := StringReplace(Title,'','',True,True,True); Title := StringReplace(Title,'','',True,True,True); Title := StringReplace(Title,'
',' / ',True,True,True); LogMessage('Titre Recherche: ' + Title); //Année : CurPos := PosFrom('',HTML,EndPos); if Curpos > 0 then begin Year := TextBetween(HTML, '', '
', True, CurPos); LogMessage('Annee: ' + Year); end else begin Year := ''; curPos := endPos; end; //AddFieldValue(5,Year); //Ajout du film dans la liste des résultats : AddSearchResult(Title,'', Year, MovieURL, ThumbURL); //Addresse Thumbnail : CurPos := PosFrom('src=',HTML,CurPos)+5; EndPos := PosFrom('alt=',HTML,CurPos)-2; ThumbURL := Trim(Copy(HTML,CurPos,EndPos-CurPos)); LogMessage('ThumbURL :' + ThumbURL); CurPos := PosFrom('0 then begin ParseSearchResults(HTML); Result := prListImage; Exit; end else if Pos ('Voir la bande-annonce', HTML) > 0 then begin //Page Principale du Film LogMessage('Parse Page Page principale'); ParseFirstPage(URL,HTML); end else if Pos ('Directeur de la photographie', HTML) > 0 then begin //Page détaillée du casting (ex entete: Casting Le Silence des agneaux : réalisateurs, acteurs - AlloCiné) LogMessage('Parse page casting'); ParseCasting(URL,HTML); end else if Pos('couvrez une vidéo li', HTML) > 0 then begin //Page Bande Annonce LogMessage('Parse Page Liens vers Bande Annonce'); ParseBA(URL,HTML); end else if Pos('Anecdotes, potins, actus', HTML) > 0 then begin //Page Secrets de tournage LogMessage('Parse Page secrets de tournage'); ParseSecrets(URL,HTML); end else if Pos('nominations dans les festivals ', HTML) > 0 then begin //Page recompense LogMessage('Parse Page Recompenses'); ParseAwards(URL,HTML); end else if Pos('Photos et affiches - AlloCin',HTML) > 0 then begin //Page principale photos LogMessage('Parse Page Page Principale Photos'); ParseLinksPrePhoto(URL,HTML); CountPhoto := 1; end else if Pos('Voir toutes les photos de ce film',HTML) > 0 then begin //Page Lien Photo LogMessage('Parse page Recherche Lien Photo'); ParsePhoto(URL,HTML); countPhoto := countPhoto + 1; end else begin LogMessage('Aucun Film Trouvé'); Result := prError; end; Mode := NextMode(Mode); LogMessage('Mode sortie ParsePage: ' + Inttostr(Mode)); if Mode <> smFinished then Result := prDownload else Result := prFinished; END; ////////////////// INITIALISATION DU SCRIPT /////////////////////// begin Mode := smSearch; for ELI := Low(ExtraLinks) to High(ExtraLinks) do ExtraLinks[ELI] := ''; end.