(* SCRIPT INFO: Following until 'SCRIPT BEGINS HERE...' is documentation. Please see 'USER OPTIONS' in the body of the script. --------------------------------------------- SCRIPT: _Imdb Top 250, IMDb Rating and Studio SOURCE: Imdb Movie Additional Information AUTHOR: Ivek23 VERSION: 0.1.1.4 DATE: 01/02/2016 //UP-DATE: 20/03/2018 UPDATE: 30/04/2018 --------------------------------------------- TYPES AND FUNCTIONS Additional types and functions that can be used in scripts: Types TWIDEARRAY : array of String Field functions procedure AddSearchResult(Title1, Title2, Year, URL, PreviewURL : String) procedure AddFieldValue(AField: Integer; AValue : String) procedure AddMoviePerson(Name, TransName, Role, URL : String; AType : Byte) procedure AddPersonMovie(Title, OrigTitle, Role, Year, URL : String; AType : Byte) procedure AddAward(Event, Award, Category, Recipient, Year: String; const Won : Boolean) procedure AddAwardEx(Event, Award, Category, RecipientVal1, RecipientVal2, Year : String; const Won : Boolean); procedure AddConnection(Title, OrigTitle, Category, URL, Year: String) procedure AddEpisode(Title, OrigTitle, Description, URL, Year, Season, Episode : String) String functions function Pos(Substr : String; Str: String): Integer function PosFrom(const SubStr, Str : String; FromIndex : Integer) : Integer function LastPos(const SubStr, Str : String) : Integer function PrevPos(const SubStr, Str : String; APos : Integer) : Integer function RemoveTags(AText : String; doLineBreaks : Boolean) : String function ExplodeString(AText : String; var Items : TWideArray; Delimiters : String) : Integer function Copy(S: String; Index, Count: Integer): String procedure Delete(var S: String; Index, Count: Integer) procedure Insert(Source: String; var Dest: String; Index: Integer) function Length(S: String): Integer function Trim(S: String): String function CompareText(S1, S2: String): Integer function CompareStr(S1, S2: String): Integer function UpperCase(S: String): String function LowerCase(S: String): String function AnsiString(S, OldPattern, NewPattern: String; All : Boolean; IgnoreCase : Boolean; WholeWord: Boolean): String function StrToInt(const S: String): Integer function IntToStr(const Value: Integer): String function StrToFloat(const S: String): Extended function FloatToStr(const Value: Extended): String function CurrentDateTime : Extended function DateToStr(Value : Extended) : String function TimeToStr(Value : Extended) : String function HTMLValues(const HTML : String; ABegin, AEnd, ItemBegin, ItemEnd : String; ValDelim : String; var Pos : Integer) : String function HTMLValues2(const HTML : String; ABegin, AEnd, ItemBegin, ItemEnd : String; ValDelim : String; var Pos : Integer) : String function TextBetween(const HTML : String; ABegin, AEnd : String; doLineBreaks : Boolean; var Pos : Integer) : String function HTMLToText(const HTML : String) : String procedure ShowMessage(const Msg, Head : String) *) //SCRIPT BEGINS HERE... //Some useful constants const //Script types stMovies = 0; stPeople = 1; stPoster = 2; //Script modes smSearch = 0; smNormal = 1; smCast = 2; smReview = 3; smCredits = 4; smBusiness = 5; smPoster = 6; smFinished = 7; //Parse results prError = 0; prFinished = 1; prList = 2; prListImage = 3; prDownload = 4; //Prefix modes pmNone = 0; pmEnd = 1; pmBegin = 2; pmRemove = 3; //Download methods dmGET = 0; dmPOST = 1; //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; //Script data SCRIPT_VERSION = '0.1.1.4'; SCRIPT_NAME = '_Imdb Top 250, IMDb Rating and Studio (2)'; SOURCE_NAME = '_Imdb Movie Additional Information'; //SCRIPT_DESC = '_Imdb Top 250, IMDb Rating and Studio'; SCRIPT_DESC = '_Imdb Top 250, IMDb Rating and Studio (2)'; SCRIPT_LANG = $09; //English SCRIPT_TYPE = stMovies; BASE_URL = 'http://www.imdb.com'; RATING_NAME = 'Imdb Movie Script'; RATING_NAME1 = 'Metascore'; //SEARCH_STR = 'http://www.imdb.com/find?q=%s&s=tt&exact=true&ref_=fn_tt_ex'; SEARCH_STR = 'http://www.imdb.com/find?q=%s&s=tt'; //SEARCH_STR = 'http://www.imdb.com/find?s=tt&q=%s'; CODE_PAGE = 65001; //Use 0 for Autodetect //User Options GET_THEMES = True; //Set to False to ensure ~mfCategory~ not added even if 'Overwrite fields' setting allows GET_POSTER = False; //Set to False or True //Global variables var ELI : Integer; //MovieID, fullinfo, fullinfo4, fullinfo5 : String; Mode : Byte; ExtraLinks : array [smCast..smPoster] of String; //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 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 if (Mode = smSearch) then Result := SEARCH_STR else Result := ExtraLinks[Mode]; end; function GetDownloadMethod : Byte; begin Result := dmGET; end; function GetPrefixMode : Byte; begin Result := pmBegin; end; function GetScriptType : Byte; begin Result := SCRIPT_TYPE; end; function GetCurrentMode : Byte; begin Result := Mode; end; function RemoveTagsEx1(AText : String) : String; var B, E : Integer; begin Result := AText; B := PosFrom('
', Result, B); while (B > 0) AND (B < E) do begin Delete(Result, B, E - B + 3); B := Pos('', Result); end; end; procedure ParseMovie(MovieURL : String; HTML : String); var curPos, endPos, debug_pos1 : Integer; TmpStr, TmpStr00, TmpStr0, TmpStr1, TmpStr2, TmpStr3, TmpStr4, TmpStr5, TmpStr6, TmpStr7, TmpStr8, TmpStr9, TmpStr10, TmpStr11, TmpStr12, TmpStr13, TmpStr14, TmpStr15,TmpStr16, TmpStr17, TmpStr18, TmpStr19, TmpStr20, TmpStr21, TmpStr22, TmpStr23, TmpStr24, TmpStr25, TmpStr26, TmpStr27, TmpStr28, TmpStr29, TmpStr30, TmpStr31, TmpStr32, TmpStr33,TmpStr34, TmpStr35, TmpStr36, TmpStr37, TmpStr38, TmpStr39, TmpStr40 : String; Date : String; DateParts: TWideArray; begin //Date ~Updated~ (choose simple or verbose version) Date := DateToStr(CurrentDateTime); if Date <> '' then begin ExplodeString(Date, DateParts, '-'); Date := DateParts[2] +'.'+ DateParts[1] +'.'+ DateParts[0]; Date := StringReplace(Date, '01.', '1.', True, True, False); Date := StringReplace(Date, '02.', '2.', True, True, False); Date := StringReplace(Date, '03.', '3.', True, True, False); Date := StringReplace(Date, '04.', '4.', True, True, False); Date := StringReplace(Date, '05.', '5.', True, True, False); Date := StringReplace(Date, '06.', '6.', True, True, False); Date := StringReplace(Date, '07.', '7.', True, True, False); Date := StringReplace(Date, '08.', '8.', True, True, False); Date := StringReplace(Date, '09.', '9.', True, True, False); //AddCustomFieldValueByName('IUpdated', Date); // Simple AddCustomFieldValueByName('Updated0', Date + ' at ' + TimeToStr(CurrentDateTime) + ' • ' + SCRIPT_NAME + ' ' + SCRIPT_VERSION); // Annoying end else LogMessage('date not found'); //AddCustomFieldValueByName('Updated', DateToStr(CurrentDateTime)); // Simple // AddCustomFieldValueByName('IUpdated', DateToStr(CurrentDateTime)); // Simple // AddCustomFieldValueByName('IUpdated', DateToStr(CurrentDateTime) + ' at ' + TimeToStr(CurrentDateTime)); // Verbose //AddCustomFieldValueByName('IUpdated', DateToStr(CurrentDateTime) + ' at ' + TimeToStr(CurrentDateTime) + ' • ' + SCRIPT_NAME + ' ' + SCRIPT_VERSION); // Annoying //Get ~mfURL~ or ~IMDb Url~ //endPos := Pos('/ "> 0 then begin // curPos := PrevPos('"canonical" href="', HTML, endPos); // AddFieldValue(mfURL, Copy(HTML, curPos + 18, endPos - curPos - 18)); //end else AddFieldValue(mfURL, MovieURL); TmpStr := StringReplace(MovieURL, 'http://www.imdb.com/title/', '', false, false, false ); TmpStr := StringReplace(TmpStr, '?ref_=fn_tt_tt_', '', true, false, true); TmpStr := StringReplace(TmpStr, '/', '', true, false, true); AddCustomFieldValueByName('IMDbID', TmpStr); //Get ~Awards URL~ //endPos := Pos('class="quicklink quicklinkGray" >Awards', HTML); //if endPos > 0 then begin // curPos := PrevPos('Awards' + ' '; //end; // Main information Page //~Rating~ curPos := PosFrom('', HTML, EndPos); if curPos > 0 then begin EndPos := curPos; TmpStr := FloatToStr((StrToFloat(TextBetween(HTML, '', '', True, curPos)) * 1)); AddFieldValueXML('imdbrating', TmpStr); end; //~Votes~ curPos := PosFrom('', HTML, EndPos); if curPos > 0 then begin EndPos := curPos; TmpStr1 := TextBetween(HTML, '', '', True, curPos); TmpStr1 := StringReplace(TmpStr1, ',', '', true, false, true); AddCustomFieldValueByName('IMDB Votes', TmpStr1); end; //~Top 250~ curPos := PosFrom('> Top Rated ', HTML, EndPos); if curPos > 0 then begin curPos := curPos + Length('> Top Rated '); EndPos := PosFrom(' ', HTML, curPos); TmpStr1 := Copy(HTML, curPos, endPos - curPos); TmpStr1 := StringReplace(TmpStr1, 'Movies #', '', true, false, true); TmpStr1 := StringReplace(TmpStr1, 'TV #', '', true, false, true); AddCustomFieldValueByName('Top 250:', TmpStr1); end; //~Bottom 100~ curPos := PosFrom('> Bottom Rated ', HTML, EndPos); if curPos > 0 then begin curPos := curPos + Length('> Bottom Rated '); EndPos := PosFrom(' ', HTML, curPos); TmpStr2 := Copy(HTML, curPos, endPos - curPos); TmpStr2 := StringReplace(TmpStr2, 'Movies #', '', true, false, true); TmpStr2 := StringReplace(TmpStr2, 'TV #', '', true, false, true); AddCustomFieldValueByName('Bottom 100', TmpStr2); end; //~Year~ //If Pos('

', HTML) > 0 then begin //EndPos := Pos('

', HTML); //curPos := PosFrom('(', HTML, EndPos); //if curPos > 0 then begin // curPos := curPos + Length('('); // EndPos := PosFrom(')', HTML, curPos); // TmpStr34 := Trim(Copy(HTML, curPos, endPos - curPos)); // AddFieldValue(mfYear, TmpStr34); // end; //end; //~Year~ If Pos('

(', ')', True, curPos); // AddFieldValue(mfYear, TmpStr3); end; end; //~Category~ If Pos('>See all in-', ' titles on IMDbPro

', True, curPos); TmpStr15 := StringReplace(TmpStr15, 'development', 'Development', True, True, False); if TmpStr15 <> '' then AddFieldValueXML('code', TmpStr15); //AddFieldValueXML('category', TmpStr15); //AddCustomFieldValueByName('Imdb Genres', TmpStr15); end; (* //~TV Series & etc ... ~ curPos := PosFrom('title="See more release dates" >', HTML, EndPos); if curPos > 0 then begin curPos := curPos + Length('title="See more release dates" >'); EndPos := PosFrom('', HTML, EndPos); if curPos > 0 then begin curPos := curPos + Length('title="See more release dates" >'); // EndPos := PosFrom('', HTML) > 0 then begin EndPos := Pos('

', HTML); curPos := PosFrom('

', HTML, EndPos); EndPos := PosFrom('', HTML, curPos); TmpStr3 := RemoveTags(Trim(Copy(HTML, curPos, endPos - curPos)), false); TmpStr3 := StringReplace(TmpStr3, ' ', ' ', True, True, False); TmpStr3 := StringReplace(TmpStr3, ' ', '', True, True, False); // if TmpStr3 <> '' then AddCustomFieldValueByName('Imdb Title', TmpStr3); end; If Pos('
', HTML) > 0 then begin EndPos := Pos('
', HTML); curPos := PosFrom('

', HTML) > 0 then begin EndPos := Pos('
', HTML); curPos := PosFrom('
', HTML, EndPos); EndPos := PosFrom(')
', HTML, curPos)+1; TmpStr2 := RemoveTags(Trim(Copy(HTML, curPos, endPos - curPos)), false); // TmpStr := StringReplace(TmpStr, ' (', ' (', True, True, False); // TmpStr := StringReplace(TmpStr, ' (', ' (', True, True, False); // TmpStr := StringReplace(TmpStr, ' (', ' (', True, True, False); // TmpStr := StringReplace(TmpStr, ') (', ') (', True, True, False); // TmpStr2 := StringReplace(TmpStr3, ' ', '
', True, True, False); // TmpStr := StringReplace(TmpStr, ' "', '
', True, True, False); // TmpStr := StringReplace(TmpStr, '" (original title)', ' (original title)', True, True, False); // if TmpStr2 <> '' then AddCustomFieldValueByName('Imdb Title', TmpStr2); end; if (TmpStr2 = '') AND (TmpStr <> '') then AddCustomFieldValueByName('Imdb Title', TmpStr); if (TmpStr2 <> '') AND (TmpStr <> '') then AddCustomFieldValueByName('Imdb Title', TmpStr + #13 + TmpStr2); //~Original title~ //If Pos('
', HTML) > 0 then begin //EndPos := Pos('
', HTML); //curPos := PosFrom('

(', HTML, curPos); //if (EndPos < 1) OR (EndPos > PosFrom('

', HTML, curPos)) then // EndPos := PosFrom('

', HTML, curPos); // TmpStr40 := RemoveTags(Trim(Copy(HTML, curPos, endPos - curPos)), false); // if TmpStr40 <> '' then AddFieldValueXML('origtitle', TmpStr40); //end //~Original title~ If Pos('
', HTML) > 0 then begin EndPos := Pos('
', HTML); curPos := PosFrom('

(', HTML, curPos); if (EndPos < 1) OR (EndPos > PosFrom('

', HTML, curPos)) then EndPos := PosFrom('

', HTML, curPos); TmpStr0 := RemoveTags(Trim(Copy(HTML, curPos, endPos - curPos)), false); // if TmpStr0 <> '' then AddFieldValueXML('origtitle', TmpStr0); end; If Pos('
', HTML) > 0 then begin EndPos := Pos('
', HTML); curPos := PosFrom('
', HTML, EndPos); EndPos := PosFrom(' (original title)
', HTML, curPos); //if (EndPos < 1) OR (EndPos > PosFrom('', HTML, curPos)) then // EndPos := PosFrom('', HTML, curPos); TmpStr1 := RemoveTags(Trim(Copy(HTML, curPos, endPos - curPos)), false); TmpStr1 := StringReplace(TmpStr1, ' ', ' ', True, True, False); TmpStr1 := StringReplace(TmpStr1, ' (', ' (', True, True, False); //TmpStr1 := StringReplace(TmpStr1, ' (', '(', True, True, False); //TmpStr1 := StringReplace(TmpStr1, ')', ') ', True, True, False); //TmpStr1 := StringReplace(TmpStr1, ' (I) (', ' (I) (', True, True, False); // TmpStr1 := StringReplace(TmpStr1, ' (I)', ' (I)', True, True, False); TmpStr1 := StringReplace(TmpStr1, ' (I)', ' (I)', True, True, False); // AddFieldValueXML('origtitle', TmpStr1); end; if (TmpStr1 = '') AND (TmpStr0 <> '') then AddFieldValueXML('origtitle', TmpStr0); if (TmpStr1 <> '') AND (TmpStr0 <> '') then AddFieldValueXML('origtitle', TmpStr1); //~Year~ endPos := PosFrom('title="See more release dates" >', HTML, curPos); curPos := PosFrom('title="See more release dates" >', HTML, endPos); endPos := PosFrom('
', HTML, curPos); //TmpStr27 := StringReplace(TmpStr27, 'TV Series (', '', True, True, False); curPos := curPos + 43; // curPos := endPos - 12; TmpStr27 := Copy(HTML, curPos, 4); if (TmpStr27 = '') AND (TmpStr3 <> '') then AddFieldValue(mfYear, TmpStr3); if (TmpStr27 <> '') AND (TmpStr3 = '') then AddFieldValue(mfYear, TmpStr27); if (TmpStr27 <> '') AND (TmpStr3 <> '') then AddFieldValue(mfYear, TmpStr3); //~Imdb rate~ curPos := Pos('
', HTML); EndPos := curPos; TmpStr3 := HTMLValues(HTML, '
', '
', '', '
', EndPos); if TmpStr3 <> '' then AddCustomFieldValueByName('Imdb rate2', TmpStr3); curPos := Pos('', 'class="us_', 'titlePageSprite absmiddle"', '
', EndPos); TmpStr2 := StringReplace(TmpStr2, 'pg_13', 'PG-13', true, false, true); TmpStr2 := StringReplace(TmpStr2, '_', '-', true, false, true); if TmpStr2 <> '' then AddCustomFieldValueByName('Imdb rate7', UpperCase(TmpStr2)); //~TV Series & etc ... ~ //~Runtime~ '
' curPos := Pos('
', HTML); EndPos := curPos; curPos := PosFrom('', HTML, curPos); // TmpStr := IntToStr(StrToInt(RemoveTags(Trim(Copy(HTML, curPos, endPos - curPos)), false)) * 60); // if TmpStr <> '' then AddFieldValueXML('length', TmpStr); //end; //~Metascore:~ curPos := PosFrom('>
', HTML, EndPos); if curPos > 0 then begin curPos := curPos + Length('>
'); EndPos := PosFrom('', HTML, curPos); TmpStr := RemoveTags(Copy(HTML, curPos, endPos - curPos+2), false); TmpStr := StringReplace(TmpStr, '0', HTML) > 0 then begin EndPos := Pos('
', HTML); curPos := PosFrom('
', HTML, EndPos); EndPos := PosFrom('
', HTML, curPos); TmpStr0 := RemoveTags(Trim(Copy(HTML, curPos, endPos - curPos)), false); TmpStr0 := StringReplace(TmpStr0, 'Add a Plot »', '', true, false, true); TmpStr0 := StringReplace(TmpStr0, 'See full summary »', '', true, false, true); debug_pos1:=Pos('var ue_t0=ue_t0||+new Date();var ',TmpStr0); if debug_pos1 >0 then TmpStr0 := Copy(TmpStr0,0,debug_pos1-1); //debug_pos1:=Pos('See ',TmpStr0); //if debug_pos1 >0 then TmpStr0 := Copy(TmpStr0,0,debug_pos1-1); if TmpStr0 <> '' then AddFieldValueXML('comment', TmpStr0); end; //~Description~ If Pos('

Storyline

', HTML) > 0 then begin //EndPos := Pos('
', HTML); EndPos := Pos('

Storyline

', HTML); curPos := PosFrom('

Storyline

', HTML, EndPos)+23; //EndPos := PosFrom('

', HTML, curPos); //if (EndPos < 1) OR (EndPos > PosFrom(' ', HTML, curPos)) then EndPos := PosFrom(' ', HTML, curPos); TmpStr10 := RemoveTags(Trim(Copy(HTML, curPos, endPos - curPos)), false); TmpStr10 := StringReplace(TmpStr10, 'Industry information at your fingertips', '', true, false, true); TmpStr10 := StringReplace(TmpStr10, 'Some parts of this page won'+#39+'t work property. Please reload or try later.', '', true, false, true); debug_pos1:=Pos('Written by',TmpStr10); if debug_pos1 >0 then TmpStr10 := Copy(TmpStr10,0,debug_pos1-1); //debug_pos1:=Pos('Written by',TmpStr10); //if debug_pos1 >0 then TmpStr10 := Copy(TmpStr10,0,debug_pos1-1); //debug_pos1:=Pos('See ',TmpStr00); //if debug_pos1 >0 then TmpStr00 := Copy(TmpStr00,0,debug_pos1-1); if TmpStr10 <> '' then AddFieldValueXML('description', TmpStr10); //AddFieldValueXML('comment', TmpStr00); end; //~Description~ //If Pos('

Storyline

', HTML) > 0 then begin //EndPos := Pos('
', HTML); //curPos := PosFrom('

', HTML, EndPos); // EndPos := PosFrom('', HTML, curPos); // TmpStr30 := RemoveTags(Trim(Copy(HTML, curPos, endPos - curPos)), false); //if TmpStr30 <> '' then AddFieldValueXML('description', TmpStr30); //end; //~Genres~ curPos := PosFrom('

Genres:

', HTML, EndPos); if curPos > 0 then begin curPos := curPos + Length('

Genres:

'); EndPos := PosFrom('
', HTML, curPos); //if (EndPos < 1) OR (EndPos > PosFrom('