(*************************************************** Ant Movie Catalog importation script www.antp.be/software/moviecatalog/ [Infos] Authors=HappyTalk (Modified version of original script by Antoine Potten & KaraGarga) Title=Auto.IMDB.com Description=Import data & picture from IMDB (optional large image from Amazon.com) Site=us.imdb.com Language=EN Version=2.05 Requires=3.5.0 Comments=Based on the script made for version 3.x by Antoine Potten, Danny Falkov, Kai Blankenhorn, lboregard, Ork, Trekkie, Youri Heijnen||Modified by HappyTalk to fix large amazon pic import, and a few other things License=This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. GetInfo=1 [Options] ImageKind=0|1|0=No image|1=Import from Amazon.com. Prompt with movie selector|2=Import from Amazon.com. No prompts, use first movie cover BatchMode=0|0|0=Normal working mode, prompts user when needed|1=Does not display any window, takes the first movie found|2=Same as 1, but it uses the URL field if available to update movie information|3=Only updates using current URL field PopularSearches=1|1|0=Do not use the popular searches page, directly show full search results|1=Show popular searches first, I'll click on "Find more" if needed (much faster) ActorsLayout=0|2|0=Only actor names, separated by commas|1=Only actor names, separated by linebreaks|2=Actors names with character names between parenthesis separated by commas|3=Actors names with character names between parenthesis separated by linebreaks|4=Actor names like on IMDB page, with "...." and separated by linebreaks MultipleValuesCountry=0|0|0=Only take first value for Country|1=Take full list, separated by commas|2=Take full list, separated by slashes MultipleValuesCategory=1|0|0=Only take first value for Category|1=Take full list, separated by commas|2=Take full list, separated by slashes MultipleValuesLanguages=0|0|0=Only take first value for Languages|1=Take full list, separated by commas|2=Take full list, separated by slashes DescriptionSelection=2|1|0=Take the short summary, from main page (faster)|1=Show a list of available summaries|2=Take the longest summary|3=Take the shortest summary GetTagline=0|0|0=Do not get tagline|1=Put it in Description field, before the summary|2=Put it in the Comment field, before the comments Trivia=0|0|0=Do not import trivia|1=Import trivia to Description field, after the summary|2=Import trivia to Comments field, after the comments AmazonReview=0|0|0=Do not get Amazon Review|1=Get Amazon Review CommentType=2|0|0=Standard Type (Only one comment from main page)|1=Detailed Type (10 most useful comments from comments page)|2=No user comment Awards=0|0|0=Do not import awards|1=Import awards to Description field, after the summary|2=Import awards to Comments field, after comments ***************************************************) program Auto_IMDB_com; uses StringUtils1, AutoUtils; const // IMDB_URL = 'http://us.imdb.com'; IMDB_URL = 'http://former.imdb.com'; var MovieName: string; MovieURL: string; MovieNumber: string; // ***** analyzes the results page that asks to select a movie from a list ***** procedure AnalyzeResultsPage(Address: string); var PageText: string; Value: string; begin PageText := GetPage(Address); if pos('IMDb', PageText) = 0 then begin AnalyzeMoviePage(PageText) end else begin if Pos('<b>No Matches.</b>', PageText) > 0 then begin if GetOption('BatchMode') = 0 then ShowMessage('No movie found for this search'); Exit; end; if GetOption('BatchMode') = 0 then begin PickTreeClear; repeat Value := TextBefore(PageText, '<ol>', '<b>'); if Value <> '' then begin HTMLRemoveTags(Value); HTMLDecode(Value); PickTreeAdd(Value, ''); end; Value := TextBetween(PageText, '<ol>', '</ol>'); PageText := RemainingText; until not AddMovieTitles(Value); Value := TextBefore(PageText, '"><b>more titles</b></a>', '<a href="'); if Value <> '' then PickTreeMoreLink(IMDB_URL + Value); if PickTreeExec(Address) then AnalyzeResultsPage(Address); end else begin Value := TextBetween(TextBetween(PageText, '<ol>', '</ol>'), '<li>', '</li>'); if Value <> '' then AnalyzeResultsPage(TextBetween(Value, '<a href="', '">')); end; end; end; // ***** adds the titles contained in <ol>'s items ***** function AddMovieTitles(List: string): Boolean; var Value: string; Address: string; begin Result := False; Value := TextBetween(List, '<li>', '</li>'); List := RemainingText; while Value <> '' do begin Address := TextBetween(Value, '<a href="', '">'); HTMLRemoveTags(Value); HTMLDecode(Value); PickTreeAdd(Value, IMDB_URL + Address); Result := True; Value := TextBetween(List, '<li>', '</li>'); List := RemainingText; end; end; // ***** analyzes the page containing movie information ***** procedure AnalyzeMoviePage(PageText: string); var Value, Value2, Value3, FullValue, sMovieTitle: string; p: Integer; begin MovieNumber := TextBetween(PageText, '<input type="hidden" name="auto" value="legacy/title/tt', '/"><input'); MovieURL := 'http://imdb.com/title/tt' + MovieNumber; // URL if CanSetField(fieldURL) then begin //if (GetField(fieldSource) = '') and (CanSetField(fieldSource)) then SetField(fieldSource, GetField(fieldURL)); /// now done in other routine after import SetField(fieldURL, MovieURL); // XXX Original Title & Year end; // fieldOriginalTitle Value := TextBetween(PageText, '<title>', ''); Value2 := TextBefore(Value, ' (', ''); Value := RemainingText; HTMLDecode(Value2); sMovieTitle := value2; if CanSetField(fieldOriginalTitle) then SetField(fieldOriginalTitle, sMovieTitle); // fieldYear if Pos('/', Value) > 0 then Value2 := TextBefore(Value, '/', '') else Value2 := TextBefore(Value, ')', ''); if CanSetField(fieldYear) then SetField(fieldYear, Value2); // Rating if CanSetField(fieldRating) then begin Value := TextBetween(PageText, '/rating-stars/', '/rating-vote/'); SetField(fieldRating, TextBetween(Value, '', '/')); end; // Picture if CanSetPicture then begin case GetOption('ImageKind') of 1: ImportAmazonPicture(sMovieTitle, true); 2: ImportAmazonPicture(sMovieTitle, false); end; end; // Director if CanSetField(fieldDirector) then begin Value := TextBetween(PageText, 'Directed by
', '
' + #13); Value := StringReplace(TextAfter(Value, '">'), '
', ', '); HTMLRemoveTags(Value); HTMLDecode(Value); SetField(fieldDirector, Value); end; // Actors if CanSetField(fieldActors) then begin Value := TextBetween(PageText, 'ast overview', ''); if Value = '' then Value := TextBetween(PageText, 'redited cast', ''); if Value = '' then Value := TextBetween(PageText, 'Cast:', ''); if Value = '' then Value := TextBetween(PageText, 'ast Summary:', ''); if Value <> '' then begin Value := Trim(TextAfter(Value, '')); FullValue := ''; case GetOption('ActorsLayout') of 0, 1: while Pos('', Value) > 0 do begin Value2 := TextBetween(Value, ''); Value := RemainingText; if Pos('rest of cast', Value2) > 0 then Continue; if Pos('(more)', Value2) > 0 then Break; if FullValue <> '' then FullValue := FullValue + #13#10; TextBefore(Value2, '', ''); Value2 := TextBetween(RemainingText, '/">', ''); if Value2 <> '' then FullValue := FullValue + Value2; end; (* 0, 1: while Pos('', Value) > 0 do begin Value2 := TextBetween(Value, '', ''); Value := RemainingText; if Pos('rest of cast', Value2) > 0 then Continue; if Pos('(more)', Value2) > 0 then Break; if FullValue <> '' then FullValue := FullValue + #13#10; FullValue := FullValue + TextBefore(Value2, '', ''); end; *) 2, 3: while Pos('', Value) > 0 do begin Value2 := TextBetween(Value, ''); Value := RemainingText; if Pos('rest of cast', Value2) > 0 then Continue; if Pos('(more)', Value2) > 0 then Break; if FullValue <> '' then FullValue := FullValue + #13#10; TextBefore(Value2, '', ''); Value2 := TextBetween(RemainingText, '/">', ''); if Value2 <> '' then begin FullValue := FullValue + Value2; Value2 := TextBetween(RemainingText, 'e">', ''); if Value2 <> '' then FullValue := FullValue + ' (as ' + Value2 + ')'; end; end; (* 2, 3: while Pos('', Value) > 0 do begin Value2 := TextBetween(Value, '', ''); Value := RemainingText; if Pos('rest of cast', Value2) > 0 then Continue; if Pos('(more)', Value2) > 0 then Break; if FullValue <> '' then FullValue := FullValue + #13#10; FullValue := FullValue + TextBefore(Value2, '', ''); Value2 := TextBetween(RemainingText, '', ''); if Value2 <> '' then FullValue := FullValue + ' (as ' + Value2 + ')'; end; *) 4: begin FullValue := TextBefore(Value, '', ''); if FullValue = '' then FullValue := Value; FullValue := StringReplace(FullValue, ' rest of cast listed alphabetically: ', ''); FullValue := StringReplace(FullValue, '', #13#10); end; end; HTMLRemoveTags(FullValue); HTMLDecode(FullValue); case GetOption('ActorsLayout') of 0, 2: FullValue := StringReplace(FullValue, #13#10, ', '); end; // SetField(fieldActors, FullValue); SetField(fieldActors, FixActors(FullValue)); //xxx Run through FixActors to leave just comma sep'd actors end; end; //Country if CanSetField(fieldCountry) then begin SetField(fieldCountry, ImportList(PageText, GetOption('MultipleValuesCountry'), '/Countries/')); end; //Category only set for _M.ovies if CanSetField(fieldCategory) then begin //value := GetField(fieldCategory); //xxx If blank or _M.ovie ensure _Movie is appended, else leave alone //if (value = '') or (pos('_M.ovie',value) > 0) then SetField(fieldCategory, ImportList(PageText, GetOption('MultipleValuesCategory'), '/Genres/')); // + ',_M.ovie'); end; // Language if CanSetField(fieldLanguages) then begin SetField(fieldLanguages, ImportList(PageText, GetOption('MultipleValuesLanguages'), '/Languages/')); end; // Description if CanSetField(fieldDescription) then begin Value := TextBetween(PageText, 'Plot Outline:', '

'); if Value = '' then Value := TextBetween(PageText, 'Plot Summary:', '

'); if Value <> '' then SetField(fieldDescription, ImportSummary(Value)); // Amazon.com Description if (GetOption('AmazonReview') > 0) then begin Value := TextAfter(PageText, ''); if Value <> '' then begin Value := GetField(fieldURL); PageText := GetPage(Value+'/amazon'); Value := TextBetween(PageText, 'Amazon.com video review:', '