//SCRIPT INFO================================================================================================== BlockOpen (*Following until 'SCRIPT CONSTANTS...' is documentation. Please see 'USER OPTIONS' in the body of the script. --------------------------------------------- SCRIPT: TheMovieDB_[EN][API] API URL: http://docs.themoviedb.apiary.io/ CO-AUTHORS: VVV Contact Web: http://contactbyweb.com/vvv-easy --------------------------------------------- CHANGE LOG : V 1.0.0.7 (29/03/2026) Ivek23: Many improvements in the script v 0.1.0.0 VVV: initial "public" release --------------------------------------------- *) //SCRIPT INFO================================================================================================== BlockClose //SCRIPT CONSTANTS============================================================================================= BlockOpen Const //Script types----------------------------------------------------------------------------------------------------------- stMovies = 0; stPeople = 1; stPoster = 2; stScreenShots = 3; stCover = 4; //Script Obligatory Infos---------------------------------------------------------------------------------------------- SCRIPT_NAME = 'TheMovieDB [EN][API]'; //The recomended script of the big open community SCRIPT_DESC = 'TheMovieDB download Movie info (API Script) [EN]'; SCRIPT_VERSION = '1.0.0.7'; SCRIPT_TYPE = stMovies; SCRIPT_LANG = $09; //$07=DE-German, $09=EN-English, $0a=ES-Spanish, $0c=FR-French RATING_NAME = 'TheMovieDB'; //PVD has ~orname~,~orating~ for this value.May be in user ~rating~ CODE_PAGE = 65001; //Script Options------------------------------------------------------------------------------------------------------- //Retreive Data Config PEOPLE_LIMIT = 25; //Limit of number of actors (cast) retrieved. PEOPLE_CREW_LIMIT = 250; //Limit of number of of credits (crew) retrieved. GET_BACKDROP = True ; //Get the first BackDrop as ScreenShot (interesting for FanArt) //Process Data Config SET_AS_USER_RATING = True ; //Set TheMovieDB rating as PVD user rating. TRANSLATED_OVERVIEW = True ; //Download only the overview in the script language. Otherwise downloads all the info even if not exist in the script language. //Process Behaviour Config BYPASS_SILENT = True ; //Ensure critical ShowMessage alerts bypassing Silent PVdB preferences POSTER_IN_SEARCH = True ; //Download and show movie posters in the list of the SearchResult CHECK_WEBSITE = True ; //Add to SearchResult List the true HTTPS links 'Just to check the website' with the browser //Script data------------------------------------------------------------------------------------------------------------ //Used Web URL LANG_API_STR = '&language=en'; //'&language=de', '&language=en', '&language=es', '&language=fr' //WEB_SPECIFIC BASE_URL_MOVIE = 'http://www.themoviedb.org/movie/'; //WEB_SPECIFIC. Used to make the link to movie ID and script detect if the record already has a link and for make it. BASE_URL_PERSON = 'http://www.themoviedb.org/person/'; //WEB_SPECIFIC. Used to make the link to movie ID and script detect if the record already has a link and for make it. BASE_URL_IMAGE = 'http://image.tmdb.org/t/p/original';//WEB_SPECIFIC. (no finish in /) The http of TheMovieDB base URL for the images. May be finish in w45,w92,w185,w300,w342,original. BASE_URL_TRUE = 'https://www.themoviedb.org/movie/'; //WEB_SPECIFIC. Used to get movie ID if the record already has a link and for make it -> NOT Used. https don't work. BASE_API_URL_PREFIX = 'http://api.themoviedb.org/3/movie/'; //WEB_SPECIFIC BASE_API_URL_SUFIX = '?append_to_response=alternative_titles,credits,keywords,images&api_key=0a4782bd3877917501a2d45e1198f809'; //WEB_SPECIFIC //?append_to_response=alternative_titles,credits,keywords,images,videos&language=en&api_key=0a4782bd3877917501a2d45e1198f809 BASE_API_URL_SEARCH_PROV = 'http://api.themoviedb.org/3/search/movie?query=%s&api_key=0a4782bd3877917501a2d45e1198f809'; //WEB_SPECIFIC '%s' title changed by PVD BASE_API_URL_SEARCH_IMDB= 'http://api.themoviedb.org/3/find/%IMDB_ID?external_source=imdb_id&api_key=0a4782bd3877917501a2d45e1198f809'; //WEB_SPECIFIC BASE_URL_IMDB_MOVIE= 'http://www.imdb.com/title/'; //+ IMDB_Id + '/' BASE_URL_IMDB_NAME= 'http://www.imdb.com/name/'; //+ IMDB_Id + '/' //Download HTTPS needed parameters BASE_URL_RONDABOUT = 'RONDABOUT'; //Used for cheat GET PVdB funtion and rondabout the "https" fail. //Script movie modes.---------------------------------------------------------------------------------------------------- smSearch = 0; smNormal = 1; smCast = 2; smReview = 3; smCredits = 4; smDVDReleases = 5; smPoster = 6; smFinished = 7; //Parse results (return of Script)--------------------------------------------------------------------------------------- prError = 0; prFinished = 1; prList = 2; prListImage = 3; prDownload = 4; //Download methods------------------------------------------------------------------------------------------------------- dmGET = 0; dmPOST = 1; //Credits types---------------------------------------------------------------------------------------------------------- ctActors = 0; ctDirectors = 1; ctWriters = 2; ctComposers = 3; ctProducers = 4; //Image types------------------------------------------------------------------------------------------------------------ itPoster = 0; itScreenShot = 1; itFrontCover = 2; itDiscImage = 3; itPhoto = 4; //SCRIPT CONSTANTS============================================================================================= BlockClose //SCRIPT GLOBAL VARIABLES=======================================================================================BlockOpen Var Mode:Byte; DownloadURL:String; StoredURL:String; //SCRIPT GLOBAL VARIABLES=======================================================================================BlockClose //OBLIGATORY CALLBACK FUNCTIONS=================================================================================BlockOpen Function GetScriptVersion:String; //BlockOpen begin Result:=SCRIPT_VERSION; end; //BlockClose Function GetScriptName:String; //BlockOpen begin Result:=SCRIPT_NAME; end; //BlockClose Function GetScriptDesc:String; //BlockOpen begin Result:=SCRIPT_DESC; end; //BlockClose Function GetBaseURL:AnsiString; //BlockOpen begin Result:=BASE_URL_RONDABOUT; end; //BlockClose Function GetScriptLang:Cardinal; //BlockOpen begin Result:=SCRIPT_LANG; end; //BlockClose Function GetScriptType:Byte; //BlockOpen begin Result:=SCRIPT_TYPE; end; //BlockClose Function GetCurrentMode:Byte; //BlockOpen begin Result:=Mode; end; //BlockClose Function GetDownloadURL:AnsiString; //BlockOpen var curPos:Integer; MovieID:String; begin LogMessage('Function GetDownloadURL|'); LogMessage('Global Var-Mode|'+IntToStr(Mode)+'|'); LogMessage('Global Var-DownloadURL|'+DownloadURL+'|'); if (Mode=smSearch) then begin // DownloadURL has not movie URL. Result:=BASE_API_URL_SEARCH_PROV+LANG_API_STR; //Default search: PVD remplaces automaticaly %s by the ~origtitle~ or ~title~ //Rondabout: Code used to get movie ID if the record already has a link because GET PVdB funtion fails with "https" links. //Get stored URL if exist. StoredURL:=GetFieldValueXML('url'); LogMessage('Stored URL is:'+StoredURL+'||'); //Standarize the URL StoredURL:=LowerCase(StoredURL); StoredURL:=StringReplace(StoredURL,'https','http',True,True,False); StoredURL:=StringReplace(StoredURL,' ','/',True,True,False)+'/'; //Asure that the URLs always finish '/' (even in the last position) //Get TheMoviedb_ID if exist. curPos:=Pos(BASE_URL_MOVIE,StoredURL); if (01) then begin //There are several results. //'{"page":1,"total_results":12,"total_pages":1,"results":[{...,"id":240,...,"title":"t...",...,"poster_path":"\/dfEQ.jpg",...,"original_title":"T...",...,"release_date":"1972-03-14"}, // ,{...}]} LogMessage(' Several Movies: Parsing'); ItemList:=TextBetWeenFirst(HTML,'"results":[','}]')+'}'; //WEB_SPECIFIC. //LogMessage(' Parse results List results:'+ItemList+'||'); if (2TheMoviedbAPIPage TMDb_API Search '); MovieURL:=BASE_URL_MOVIE+MovieURL; AddCustomFieldValueByName('TMDb.com','TMDb.com TMDb WaybackArchive'); AddCustomFieldValueByName('TMDb Posters','TMDb.com Posters TMDb.com Release Dates'); if ( (0=Pos(BASE_URL_IMDB_MOVIE,StoredURL)) and (2'+TextBetWeenFirst(ItemArray[index],'"title":"','"'); // WEB_SPECIFIC. //LogMessage(' Parse results aka:'+ItemValue+'||'); end; AddFieldValueXML('aka',ItemValue); AddCustomFieldValueByName('TheMoviedb Aka',ItemValue); LogMessage(' Get results aka:'+ItemValue+'||'); end; //Get ~rdate~,~year~ //'"release_date":"1966-12-23","' ItemValue:=TextBetWeenFirst(HTML,'"release_date":',',"'); //WEB_SPECIFIC. if (2'; AddFieldValueXML('length',IntToStr(60*StrToInt(ItemValue))); //~length~ Value in seconds. LogMessage(' Get result Original Runtime:'+ItemValue+'||'); End; //Get ~origlang~ (language ISO 639-1 code, https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes ) // "original_language":"en" ItemValue:=TextBetWeenFirst(HTML,'"original_language":',',"'); //WEB_SPECIFIC. ItemValue:=StringReplace(ItemValue,'"','',True,True,False); //Eliminate "" If (0'; AddFieldValueXML('origlang',UpperCase(ItemValue)); //~length~ Value in seconds. LogMessage(' Get result Original Language (ISO 639-1 code):'+ItemValue+'||'); End; //Get "Spoken Languages" (several values in a comma separated list) // '"spoken_languages":[{"iso_639_1":"it","name":"Italiano"}, ... ],' ItemValue:=TextBetWeenFirst(HTML,'"spoken_languages":[',']'); //WEB_SPECIFIC. ItemValue:=StringReplace(ItemValue,',','_',True,True,False); //Change ',' by '_' in order to avoid ',' separator conflicts //LogMessage(' Parse results List langs:'+ItemValue+'||'); if (2'; LogMessage(' Get results Spoken Languages:'+ItemValue+'||'); end; if (Length(ItemList)>0) then begin AddFieldValueXML('features',ItemList); LogMessage(' Get result Movie Features:'+ItemList+'||'); End; if (Length(ItemList)>0) then begin AddCustomFieldValueByName('TMDb Features',ItemList); if ItemValue <> '' then LogMessage(' Get result Movie Features:'+ItemList+'||'); End; //Get ~budget~ // '"budget":1200000,' ItemValue:=TextBetWeenFirst(HTML,'"budget":',',"'); //WEB_SPECIFIC. if (0 '' then LogMessage(' Get result Set:'+ItemValue+'||'); ItemValue0:=TextBetWeenFirst(ItemList,'"id":',',"'); //WEB_SPECIFIC. if (2'+ItemValue+''); AddCustomFieldValueByName('Part of the:', ''+ItemValue+''); end; if ItemValue <> '' then LogMessage(' Get result Set URL:'+ItemValue+' ||'); //Get ~Networks~ (Custom Field) // '"networks":[{"id":2,"name":"ABC","logo_path":"/2uy2ZWcplrSObIyt4x0Y9rkG6qO.png","origin_country":"US"}]' ItemList:=TextBetWeenFirst(HTML,'"networks":[{','}]'); // WEB_SPECIFIC. ItemList:=StringReplace(ItemList,',','_',True,True,False); //Change ',' by '_' in order to avoid ',' separator conflicts //LogMessage(' Parse results List Networks:'+ItemList+'||'); if (2. Changed Script constant option GET-ACTORS-INFO-URL. v 0.1.2.0 VVV: Corrections: Duration (field name and length in seconds). Improvements: RemoveTags (Simplify the Web delimitators choice) Search only in movies v 0.1.1.0 VVV: Minor corrections and improvements v 0.1.0.0 VVV: initial "public" release --------------------------------------------- FIELD USE: This is a script designed to be easy to understand and to adapt. For this reason may be missing some fields and the programming may not be smart. It's a only "One Pass" Script and get data in API SEQUENTIAL ORDER. The Personal Video DataBase field names in comments are enclosed in "~" so they are easier to find in the script. The WEB_SPECIFIC commentary points out the specific text for Web fields. Use Log PVdB debug Window for looking search errors. (Due a PVdB "GET" scripts funtions seems doesn't work with 'https' URL de v.0.2.0.0 works with API web dialog. See 'FilmAffinity_[ES]_2014' script for no API (take information direct from web page) scraper.) FOOTNOTES: 1.Control the use of standard fields using the "Overwrite Fields" plugin preferences in the main program PVD: Preferences > Plugins > 'Script Name' > Overwrite fields to control how these items are to be updated. 2.Hits for adapt the Script. 2.1. Search WEB_SPECIFIC comentary for adapt the specific Web text of fields. 2.2. Script execution: 0) Get results of "Obligatory callback Functions" 1) GetDownloadURL (Obligatory callback Functions) = This function should return URL (Global Var DownloadURL) that should be downloaded by the main application and then passed to the script’s ParsePage function as text. It has several modes selon the Script mode (Global Var Mode = smSearch, smNormal, smFinished). 2) ParsePage (Obligatory callback Functions) = This function receives the text of the download web page passed to the main application in the GetDownloadURL function. It has several modes selon the Script mode (Global Var Mode = smSearch, smNormal, smFinished). KNOWN ISSUES: 1. For compiling cuestions functions must be defined in the script before use (not in order of execution). 2. For the search texts for locating the fields in Web page Null '' value it's not valid. You must replaces all escaped HTML characters (like <>&") with normal characters (like <, >,$, "). 3. It's a only "One Pass" Script: It DOES NOT makes several calls to the main program to scrape information from various pages of the movie in the same site. It only do that for searching mode in a movie list results. 4. It has a Rondabout in BASE_URL (BASE_URL_MOVIE or BASE_URL_PERSON, BASE_URL_RONDABOUT) for "cheat" GET PVdB funtion and rondabout the "https" fail. 5. Get ~langs~ is inhibited because it put the values in Audio Stream. 6. If desired, you needs Custom Field ~TheMoviedb_Votes~ for storing the number of votes. SCRIPT STRUCTURE: 1.Script data and user options constants 2.Some useful generic constants 3.Global variables 4.Obligatory PVD callback Functions GetScriptVersion, GetScriptName, GetScriptDesc, GetBaseURL, GetScriptLang, GetScriptType, GetCurrentMode, GetDownloadURL. (Note: ParsePage is at the end of the file for compiling cuestions). 5.Optional PVD callback Functions GetRatingName ,GetCodePage, GetDownloadMethod, GetPrefixMode; 6.User Functions an procedures (with their constans): Not used. 7.Obligatory PVD callback function ParsePage (at the end of the file for compiling cuestions) --------------------------------------------- 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) --------------------------------------------- }