//SCRIPT_VERSION: 0.1.0.7 //DATE: 14-1-2013 //AUTHOR: Thiezar //UPDATES: Ivek23 //Some useful constants const //Script types stMovies = 0; stPeople = 1; stPoster = 2; //Script modes smSearch = 0; smNormal = 1; smCast = 2; smReview = 3; smCredits = 4; smPoster = 5; smFinished = 6; //Parse results prError = 0; prFinished = 1; prList = 2; prListImage = 3; prDownload = 4; //Download methods dmGET = 0; dmPOST = 1; //Prefix modes pmNone = 0; pmEnd = 1; pmBegin = 2; pmRemove = 3; //Movie fields mfURL = 0; mfTitle = 1; mfOrigTitle = 2; mfAka = 3; mfYear = 4; mfGenre = 5; mfCategory = 6; mfCountry = 7; mfStudio = 8; mfMPAA = 9; mfRating = 10; mfTags = 11; mfTagline = 12; mfDescription = 13; mfDuration = 14; mfFeatures = 15; //People fields pfURL = 0; pfName = 1; pfTransName = 2; pfAltNames = 3; pfBirthday = 4; pfBirthplace = 5; pfGenre = 6; pfBio = 7; pfDeathDate = 8; //Credits types ctActors = 0; ctDirectors = 1; ctWriters = 2; ctComposers = 3; ctProducers = 4; //Image types imgPosters = 0; imgScreenshots = 1; imgFrontcover = 2; imgDiscimage = 3; imgPhoto = 4; //Script data SCRIPT_VERSION = '0.1.0.7'; SCRIPT_NAME = 'mymovies.it'; SCRIPT_DESC = '[IT] Get movie information from MyMovies.it'; SCRIPT_LANG = $10; //Italian SCRIPT_TYPE = stMovies; BASE_URL = 'http://www.mymovies.it'; RATING_NAME = 'MyMovies'; SEARCH_STR = 'http://www.mymovies.it/database/ricerca/avanzata/?titolo=%s&titolo_orig=®ista=&attore=&id_genere=-1&nazione=&clausola1=-1&anno_prod=&clausola2=-1&stelle=-1&id_manif=-1&anno_manif=&disponib=-1&ordinamento=0&submit=Inizia+ricerca+%BB'; CODE_PAGE = 0; //Use 0 for Autodetect //OPTIONS GET_POSTER = True; GET_AWARDS = True; //Global variables var Mode : Byte; ExtraLinks : array [smCast..smPoster] of String; ELI : Integer; //Functions //--Obligatory functions 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 GetBaseURL : AnsiString; begin Result := BASE_URL; end; function GetScriptLang: Cardinal; begin Result := SCRIPT_LANG; end; function GetScriptType : Byte; begin Result := SCRIPT_TYPE; end; function GetCurrentMode : Byte; begin Result := Mode; end; function GetDownloadURL : AnsiString; begin if (Mode = smSearch) then Result := SEARCH_STR else Result := ExtraLinks[Mode]; end; //--Optional functions function GetRatingName : String; begin Result := RATING_NAME; end; function GetCodePage : Cardinal; begin Result := CODE_PAGE; end; function GetDownloadMethod : Byte; begin Result := dmGET; end; function GetPrefixMode : Byte; begin Result := pmBegin; end; procedure ParseMovie(MovieURL : String; HTML : String); var curPos, EndPos : Integer; InfoStr : String; begin LogMessage('Parsing movie...'); curPos := Pos('

', HTML); EndPos := PosFrom('', InfoStr) + Length('

'); EndPos := PosFrom('

', InfoStr, curPos); AddFieldValueXML('title', Trim(Copy(InfoStr, curPos, EndPos - curPos))); LogMessage('Title:' + Trim(Copy(InfoStr, curPos, EndPos - curPos))); //Original title if PosFrom('Titolo originale ', InfoStr,curPos)>0 then begin curPos := PosFrom('Titolo originale ', InfoStr,curPos) + Length('Titolo originale '); EndPos := PosFrom('', InfoStr, curPos); AddFieldValueXML('origtitle', Copy(InfoStr, curPos, EndPos - curPos)); LogMessage('Original Title:' + Copy(InfoStr, curPos, EndPos - curPos)); end; //Genre curPos := PosFrom('', InfoStr,EndPos); curPos := PosFrom('">', InfoStr,curPos)+2; EndPos := PosFrom('', InfoStr, curPos); AddFieldValueXML('genre', Copy(InfoStr, curPos, EndPos - curPos)); LogMessage('Genre:' + Copy(InfoStr, curPos, EndPos - curPos)); //Duration if PosFrom('durata', InfoStr,curPos)>0 then begin curPos := PosFrom('durata ', InfoStr,EndPos)+Length('durata '); EndPos := PosFrom(' min.', InfoStr, curPos); AddFieldValueXML('length', FloatToStr(StrToFloat(Copy(InfoStr, curPos, EndPos - curPos))*60)); LogMessage('Duration:' + FloatToStr(StrToFloat(Copy(InfoStr, curPos, EndPos - curPos))*60)); end; //Country curPos := PosFrom('- ', InfoStr,EndPos)+2; EndPos := PosFrom(' ', InfoStr, curPos); AddFieldValueXML('country', Copy(InfoStr, curPos, EndPos - curPos)); LogMessage('Country:' + Copy(InfoStr, curPos, EndPos - curPos)); //Year curPos := PosFrom(' 0 then begin curPos := PosFrom('- ', InfoStr,curPos)+2; EndPos := PosFrom('', InfoStr, curPos); AddFieldValueXML('studio', Trim(Copy(InfoStr, curPos, EndPos - curPos))); LogMessage('Studio:' + Trim(Copy(InfoStr, curPos, EndPos - curPos))); end; //Release date if PosFrom('uscita', InfoStr,curPos)>0 then begin curPos := PosFrom('uscita', InfoStr,curPos); curPos := PosFrom('data=', InfoStr,curPos)+Length('data='); EndPos := PosFrom('>', InfoStr,curPos); AddFieldValueXML('rdate', Copy(InfoStr, curPos, EndPos - curPos)); LogMessage('Release Date:' + Copy(InfoStr, curPos, EndPos - curPos)); end; //Rating if PosFrom('valutazione media:', InfoStr,EndPos)>0 then begin curPos := PosFrom('valutazione media:', InfoStr,EndPos); curPos := PosFrom('', InfoStr,curPos)+Length(''); EndPos := PosFrom('', InfoStr, curPos); AddFieldValueXML('orname', 'MyMovies'); AddFieldValueXML('orating', FloatToStr(StrToFloat(Copy(InfoStr, curPos, EndPos - curPos))*2)); //rating is multiplied by 2 because MyMovies max rating is 5, not 10 LogMessage('Rating:' + FloatToStr(StrToFloat(Copy(InfoStr, curPos, EndPos - curPos))*2)); end; //Tagline if Pos('',HTML)>0 then begin curPos := Pos('',HTML)+Length(''); EndPos := PosFrom('',HTML,curPos); AddFieldValueXML('tagline', Trim(RemoveTags(HTMLToText(Copy(HTML, curPos, EndPos - curPos)),true))); LogMessage('Tagline:' + Trim(RemoveTags(HTMLToText(Copy(HTML, curPos, EndPos - curPos)),true))); end; //Recensione if Pos('
',HTML)>0 then begin curPos := Pos('
',HTML); curPos := PosFrom('

',HTML,curPos)+3; EndPos := PosFrom('

',HTML,curPos); AddFieldValueXML('description', Trim(RemoveTags(HTMLToText(Copy(HTML, curPos, EndPos - curPos)),true))); LogMessage('Description:' + Trim(RemoveTags(HTMLToText(Copy(HTML, curPos, EndPos - curPos)),true))); end; //Gatering extra links to cast and poster curPos := Pos ('
', HTML); //Cast URL if PosFrom('">Cast',HTML,curPos)>0 then begin EndPos := PosFrom('">Cast',HTML,curPos); curPos := PrevPos('href="',HTML,EndPos)+Length('href="'); ExtraLinks[smCast] := Copy(HTML, curPos, EndPos - curPos); end; //Poster URL if PosFrom('">Poster',HTML,curPos)>0 then begin EndPos := PosFrom('">Poster',HTML,curPos); curPos := PrevPos('href="',HTML,EndPos)+Length('href="'); ExtraLinks[smPoster] := Copy(HTML, curPos, EndPos - curPos); end; end; procedure ParseCast(HTML : String); var curPos, EndPos, auxPos : Integer; Name, Role, URL : String; begin LogMessage('Parsing cast...'); EndPos := Pos('cast',HTML); while PosFrom('
',HTML,EndPos)>0 do begin curPos := PosFrom('
',HTML,EndPos); curPos := PosFrom('', HTML,curPos); curPos := EndPos + 2; EndPos := PosFrom('', HTML,curPos); Name := Trim(Copy(HTML,curPos, EndPos-curPos)); //Person Name if PosFrom('
', HTML, EndPos)>0 then begin AuxPos := PosFrom('
', HTML,EndPos); curPos := PosFrom('
', HTML, EndPos)+Length('
'); if AuxPos > curPos then begin EndPos := PosFrom('
', HTML,curPos); Role := StringReplace(StringReplace(Trim(Copy(HTML,curPos, EndPos-curPos)),'','(',false,false,false),'',')',false,false,false); //Person Role end else Role := ''; end else Role := ''; if Role = 'Regista' then begin AddMoviePerson(Name,'','', URL, ctDirectors); LogMessage(' Director: '+Name); end else if ((Role = 'Produzione') or (Role = 'Produttore esecutivo')) then begin AddMoviePerson(Name,'','', URL, ctProducers); LogMessage(' Producer: '+Name); end else if Role = 'Sceneggiatura' then begin AddMoviePerson(Name,'','', URL, ctWriters); LogMessage(' Writer: '+Name); end else if Role = 'Musica' then begin AddMoviePerson(Name,'','', URL, ctComposers); LogMessage(' Composer: '+Name); end else if ((Role = 'Soggetto') or (Role = 'Produzione - altri') or (Role = 'Fotografia') or (Role = 'Scenografia') or (Role = 'Costumi') or (Role = 'Trucco') or (Role = 'Casting') or (Role = 'Art Director') or (Role = 'Montaggio')) then begin LogMessage(' '+Name+ ' ('+Role+') - SKIPPED!'); end else begin AddMoviePerson(Name,'',Role, URL, ctActors); LogMessage(' Actor: '+Name+' ('+Role+')'); end; end; end; procedure ParsePosters(HTML : String); var curPos, EndPos : Integer; URL :String; begin curPos := Pos('
',HTML); if curPos<1 then Exit; LogMessage('Parsing posters...'); curPos := PosFrom('src="',HTML,curPos)+5; EndPos := PosFrom('" />',HTML,curPos); URL:=StringReplace(Copy(HTML, curPos, EndPos - curPos),'imm.jpg','locandina.jpg',false,false,false); AddImageURL(imgPosters, URL); LogMessage('Added poster: '+URL); URL:=StringReplace(Copy(HTML, curPos, EndPos - curPos),'imm.jpg','locandinapg1.jpg',false,false,false); AddImageURL(imgPosters, URL); LogMessage('Added poster: '+URL); end; procedure ParseSearchResults(HTML : String); var curPos, EndPos, AuxPos : Integer; Title, Year, Director, URL, InfoStr : String; begin curPos := Pos('Film', HTML); if curPos < 1 then Exit; LogMessage('Parsing search results...'); curPos := PosFrom('
', HTML, curPos); while curPos > 0 do begin EndPos := PosFrom('
',HTML,curPos); AuxPos := EndPos; InfoStr := Copy(HTML, curPos, EndPos - curPos); curPos := Pos('

', InfoStr); //Get url curPos := PosFrom('', InfoStr, curPos); curPos := curPos+2; EndPos := PosFrom('', InfoStr, curPos); Title := Copy(InfoStr, curPos, EndPos - curPos); //Get director If PosFrom('Un film di', InfoStr, EndPos) > 0 then begin curPos := PosFrom('Un film di', InfoStr, EndPos) + Length('Un film di'); EndPos := PosFrom('con', InfoStr, curPos); Director := Trim(RemoveTags(Copy(InfoStr, curPos, EndPos - curPos),true)); end else Director := ''; //Get year curPos := PosFrom('', InfoStr, curPos); Year := Copy(InfoStr, curPos, EndPos - curPos); AddSearchResult(Title+' ['+Director+']', '', Year, URL, ''); LogMessage(' - Added result: '+Title+' ('+Year+')'); curPos := PosFrom('
', HTML, AuxPos); end; 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) do if ExtraLinks[I] <> '' then begin Result := I; Break; end; end; function ParsePage(HTML : String; URL : AnsiString) : Cardinal; begin HTML := HTMLToText(HTML); if Pos('

Ricerca MYmovies

', HTML) > 0 then begin //Results page ParseSearchResults(HTML); Result := prList; Exit; end else if Pos('

', HTML) > 0 then //Movie page ParseMovie(URL, HTML) else if Pos('cast', HTML) > 0 then //Cast page ParseCast(HTML) else if ((Pos('
', HTML) > 0) and GET_POSTER) then //Posters page ParsePosters(HTML); Mode := NextMode(Mode); if Mode <> smFinished then Result := prDownload else Result := prFinished; end; begin Mode := smSearch; for ELI := Low(ExtraLinks) to High(ExtraLinks) do ExtraLinks[ELI] := ''; end.