//SCRIPT INFO: (* Following until 'SCRIPT BEGINS HERE...' is documentation. Please see 'USER OPTIONS' in the body of the script. --------------------------------------------- SCRIPT: AllMovie.com_new CO-AUTHORS: Ivek23 VERSION: 0.1.2.3 DATE: 29/05/2015 --------------------------------------------- CHANGE LOG: v 0.1.1.0 Ivek23: initial "public" release to auto-update system only change is in version number (was 0.1.0.1) previous versions posted at forum topic: http://www.videodb.info/forum_en/index.php/topic,3154.msg16297.html#msg16297 v 0.1.1.1 Ivek23: small correction code in ParseReview procedure per forum post: http://www.videodb.info/forum_en/index.php/topic,3154.msg16551.html#msg16551 v 0.1.1.3 Ivek23: big correction code in ParseReview procedure per forum post: http://www.videodb.info/forum_en/index.php/topic,3154.msg16832.html#msg16832 v 0.1.1.4 Ivek23: several small corrections in the ~Mood links~ code in ParseMovie procedure per forum post: http://www.videodb.info/forum_en/index.php/topic,3154.msg18424.html#msg18424 v 0.1.1.5 Ivek23: added ~Alternate title~ in ParseMovie procedure per forum post: http://www.videodb.info/forum_en/index.php/topic,3154.msg18425.html#msg18425 v 0.1.2.0 Ivek23: added List of other page site number where search page code in ParseSearchResults procedure per forum post: http://www.videodb.info/forum_en/index.php/topic,3154.msg18885.html#msg18885 --------------------------------------------- FIELD USE: Field names in comments are enclosed in "~" so they are easier to find in the script. Use with your editor's search function to find applicable code sections. AllMovie data: PVD field: FN: Type/Comments: -------------- --------- -- ------------- Actors ~ctActors~ 1, 3 credits (if GET_ACTORS true) Alternate title ~Alternate title~ memo AMG ID ~AMG ID~ short text Awards ~AllMovie Awards~ memo (link to AllMovie Awards tab) Cast ~Cast~ memo Crew ~Crew~ memo Category ~Category.AllMovie~ multiselect list —not to be confused with ~mfCategory~ (used for 'Themes') Characteristics ~Moods~ 2 multiselect list (from 'Characteristics') AND ~Mood links~ memo (hyperlinks to AllMovie mood pages —if available in web archive ~Keywords~ 2 memo (from 'Characteristics') ~Attributes~ 2 multiselect list (from 'Characteristics') Themes from 'Characteristics' ~mfCategory~ 1 standard multiselect list (if GET_THEMES true) (from 'Characteristics') OR ~Themes~ 2 multiselect list (from 'Characteristics') AND ~Themes links~ 2 memo (hyperlinks to AllMovie themes pages) Country ~mfCountry~ 1 standard multiselect list OR ~Country~ 2 multiselect list Cover-art ~Poster~ 1, 3 standard (if GET_POSTER true) Directed by ~ctDirectors~ 1 standard multiselect list Flags ~Flags~ multiselect list Genres ~mfGenre~ 1 standard multiselect list OR ~Genres~ 2 multiselect list AND ~Genre links~ memo (links to AllMovie Genre page) MPAA rating ~MPAA rating~ short text Produced by ~mfStudio~ 1 standard short text OR ~Produced by~ 2 multiselect list Review ~Review~ memo Release date ~Released~ short text (multiple dates) //OR Released ~Released~ short //text (more common single date) Releases ~mfFeatures~ 1 standard memo (link to AllMovie Releases tab) Released by ~Released by~ short text Rovi rating ~mfRating~ 1, 3 'Additional rating' named 'AllMovie.new' (if GET_RATING true) OR ~AllMovie rating~ 2 rating Run time ~mfDuration~ 1, 3 standard number (if GET_DURATION true) OR ~Run time~ 2 number (minutes) Synopsis ~mfDescription~ standard memo —use PVD preference to save in ANY available memo field Sub-Genres ~Sub-Genres~ multiselect list OR ~Sub-Genre links~ memo (links to AllMovie page) Title ~mfTitle~ 1 standard short text OR ~Title~ 2 short text Year ~mfYear~ 1 standard number (from AllMovie 'Title (Year)' heading) OR ~Year~ 2 short string Updated ~Updated~ long text URL ~mfURL~ 1 standard memo OR ~URL~ 2 memo AllMovie data are once again available: Keywords Keywords AllMovie data no longer available: Color type Color type From book Book Set in Set in Tones mfTags Footnotes: 1. Control the use of standard fields using the "Overwrite Fields" plugin preferences in the main program. 2. Where data is saved to a standard field, the script also saves the data to custom field. This allows a number of options: i) Use the data saved to the standard field (normally the default) and ignore the custom field. Data saved to a non-existent custom field goes nowhere. ii) Ignore the data entirely by disabling the standard field in the "Overwrite fields" options. iii) Add the custom field to PVD and disable the standard field so it's free for use by another plugin or script. Some of these optional custom fields are named the same as their standard counterparts. To avoid confusion, you may wish to rename them (i.e., in the script, in PVD and your skin). For example, change "Year" to "AllMovie Year"—so as to not be confused with the standard field used by another source. 3. 'User Options' are set in the body of the script below. Recommended: Leave them all set to 'True' and use Preferences > Plugins > AllMovie > Overwrite fields to control how these items are to be updated. 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; smDVDReleases = 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; //This is 'Additional rating', not 'Rating' 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.2.3'; SCRIPT_NAME = 'AllMovie.com_new'; SCRIPT_DESC = '[EN] Get Movie Information from AllMovie.com_new page'; SCRIPT_LANG = $09; //English SCRIPT_TYPE = stMovies; BASE_URL = 'http://www.allmovie.com'; RATING_NAME = 'AllMovie'; SEARCH_STR = 'http://www.allmovie.com/search/movies/%s'; CODE_PAGE = 65001; //Use 0 for Autodetect //User Options GET_ACTORS = True; //Set to False to ensure ~ctActors~ not added even if 'Overwrite fields' setting allows GET_DURATION = True; //Set to False to ensure ~mfDuration~ not set even if 'Overwrite fields' setting allows //Note the program will overwrite this with the actual media duration in any case GET_POSTER = True; //Set to False if posters not wanted (or to handle bad image URL causing HTTP 404 error) GET_RATING = True; //Set to False to ensure ~mfRating~ not set even if 'Overwrite setting' fields setting allows GET_THEMES = True; //Set to False to ensure ~mfCategory~ not added even if 'Overwrite fields' setting allows //Global variables var ELI, I : Integer; MovieName, PageSite : String; Mode : Byte; ExtraLinks : array [smCast..smPoster] of String; TabMovieName, TabNumber, TabPageSite, TabPage : TwideArray; //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 RemoveTagsEx(AText : String) : String; var B, E : Integer; begin Result := AText; B := PosFrom('<', Result, 1); E := PosFrom('>', Result, B); while (B > 0) AND (B < E) do begin Delete(Result, B, E - B + 1); B := Pos('<', Result); E := Pos('>', Result); end; end; function RemoveTagsEx1(AText : String) : String; var B, E : Integer; begin Result := AText; B := PosFrom('(', Result, 1); E := PosFrom(')', Result, B); while (B > 0) AND (B < E) do begin Delete(Result, B, E - B + 1); B := Pos('(', Result); E := Pos(')', Result); end; end; procedure ParseMovie(MovieURL : String; HTML : String); var curPos, endPos, topPos, debug_pos1, L, H, R : Integer; MovieName1, Title1, Title, Name, URL, URL1, TmpStr, TmpStr0, TmpStr1, TmpStr2, TmpStr3, TmpStr4, TmpStr5 : String; begin //Date ~Updated~ (choose simple or verbose version) //AddCustomFieldValueByName('Updated', DateToStr(CurrentDateTime)); // Simple //AddCustomFieldValueByName('Updated', DateToStr(CurrentDateTime) + ' at ' + TimeToStr(CurrentDateTime)); // Verbose AddCustomFieldValueByName('Updated', DateToStr(CurrentDateTime) + ' at ' + TimeToStr(CurrentDateTime) + ' • ' + SCRIPT_NAME + ' ' + SCRIPT_VERSION); // Annoying //Get ~mfURL~ or ~URL~ //endPos := Pos('">overview', HTML); //if endPos > 0 then begin // curPos := PrevPos('href="/movie', HTML, endPos); // AddFieldValue(mfURL, BASE_URL + Copy(HTML, curPos + 6, endPos - curPos - 6)); //end else AddFieldValue(mfURL, MovieURL); AddCustomFieldValueByName('URL', '' + MovieURL + ''); //Get Review URL curPos := Pos('
', HTML, curPos) + 3; endPos := PosFrom('
', HTML, curPos); TmpStr := Copy(HTML, curPos, endPos - curPos); TmpStr1 := StringReplace(TmpStr, ' -- ', '—', True, True, False); TmpStr2 := StringReplace(TmpStr1, ' --- ', '—', True, True, False); TmpStr := StringReplace(TmpStr2, '--', '—', True, True, False); TmpStr1 := StringReplace(TmpStr, #13#13#13#13, #13#10#13#10, True, True, False); TmpStr2 := RemoveTagsEx(TmpStr1); AddCustomFieldValueByName('Review', TmpStr2 + #13 + ' ' + TmpStr3); end; //~Cast~ or ~ctActors~ //save entire Cast tab to custom memo field, as well as individual actors. procedure ParseCast(HTML : String); var curPos, endPos : Integer; TmpStr : String; Name, Role, URL : String; begin curPos := Pos('