//_____________________________________________________________________________________\\ //------ SCRIPT : Allocine_Movie_Pass1 \\ //------ Author : Pra15 \\ //------ Date : 08/02/2015 \\ //_____________________________________________________________________________________\\ const pauseBeforeLoad = 2000; // Pause before loading (in millisecond) const //Script modes smSearch = 0; smNormal = 1; //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(Pass 1)'; SCRIPT_DESC = '[FR] Get movie information from Allocine.com'; SCRIPT_LANG = $0c; //French SCRIPT_TYPE = 0; //Movies CODE_PAGE = 0; //Autodetect RATING_NAME = 'ADE'; BASE_URL = 'http://www.allocine.fr'; SEARCH_STR = BASE_URL +'/recherche/1/?q=%s'; var Mode: Byte; 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 GetDownloadURL: AnsiString; begin Result := SEARCH_STR end; function GetScriptType: Byte; begin Result := SCRIPT_TYPE; end; function GetCurrentMode: Byte; begin Result := Mode; end; //////////////////////////////////////////////////////////////////////////// procedure ParseMovie(MovieURL : String; HTML : String); Var CurPos,EndPos, EndSearch : Integer; Title, Director, Genre : String; Begin LogMessage('Parse Movie Demarre'); //Ajout 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)); AddFieldValue(2, Title); //Réalisateur : CurPos := Pos('Réalisé par',HTML); CurPos := PosFrom('title="',HTML,CurPos)+7; EndPos := PosFrom('" href="',HTML,CurPos); Director := Trim(Copy(HTML,CurPos,EndPos-CurPos)); AddMoviePerson(Director, '', '', '', ctDirectors); //Genre : CurPos := PosFrom('Genre',HTML,EndPos); EndSearch := PosFrom('Nationalit',HTML,CurPos); While CurPos < EndSearch do begin CurPos := PosFrom('"genre">',HTML,EndPos)+8; EndPos := PosFrom('',HTML,CurPos); Logmessage('Genre avant:' + Genre); Genre := Genre + ', ' + Trim(Copy(HTML,CurPos,EndPos-CurPos)); CurPos := PosFrom('itemprop=',HTML,EndPos)+8; end; AddFieldValueXML('genre',Genre); //Nationalité Allociné: end; /////////////////////////////////////////////////////////////////////////////////// procedure ParseSearchResults(HTML: string); Var CurPos, EndPos, EndSearch, nbResult, PosEssai1, PosEssai2 : Integer; Year, MovieURL, ThumbURL, Title : String; Begin NbResult := 0; CurPos := Pos('Films',HTML); If CurPos < 1 then Exit; //Addresse Thumbnail : CurPos := PosFrom('src=',HTML,CurPos)+5; EndPos := PosFrom('.jpg',HTML,CurPos)+4; ThumbURL := Trim(Copy(HTML,CurPos,EndPos-CurPos)); //Addresse page 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,'
',' (fr) / ',True,True,True); LogMessage('Titre Recherche: ' + Title); //Année : CurPos := PosFrom('fs11">',HTML,EndPos)+6; EndPos := PosFrom('
',HTML,CurPos); Year := Copy(HTML,CurPos,EndPos-CurPos); LogMessage('Annee: ' + Year); //Ajout du film dans la liste des résultats : AddSearchResult(Title,'', Year, MovieURL, ThumbURL); End; ////////////////////////////////////////////////////////////////////////////////// ///////////////////////// PARSE PAGE //////////////////////////// function ParsePage(HTML: string; URL: AnsiString): Cardinal; begin LogMessage('Parse Page Demarre'); Wait (pauseBeforeLoad); if Pos ('data-entities=', HTML) > 0 then begin LogMessage('parse movie page'); ParseMovie(URL, HTML); Mode := smNormal; Result := prFinished; end else if Pos ('Recherche Allo', HTML)>0 then begin ParseSearchResults(HTML); Result := prListImage; end else begin LogMessage('Aucun Film Trouvé'); Result := prError; end; end; ////////////////// INITIALISATION DU SCRIPT /////////////////////// begin Mode := smSearch; end.