(*************************************************** Ant Movie Catalog importation script www.antp.be/software/moviecatalog/ [Infos] Authors=Shay Hen (minishay@gmail.com) Title=Lionetwork.net and IMDB.com Description=Lionetwork Hebrew Import Script and Addon's from IMDB Site=http://www.lionetwork.net Language=HE Version=06/06/2005 Requires=3.5.0 Comments=Modified version of IMDB import 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] ***************************************************) program Lionetwork; // uses - same as c #include - uses extrenal class of functions uses StringUtils1; // declare general program vars var MovieNameEng, MovieNameHeb: string; MovieURL: string; MovieNumber: string; MoviePageAddress: string; MovieNameHebArray: Array of string; MovieNameEngArray: Array of string; // added from imdb script MovieNameIMDB: string; MovieURLIMDB: string; MovieNumberIMDB: string; // Integers to fill results if Lionetwork returend no data for the field IMDbImage : Integer; IMDbDesc : Integer; IMDbLength : Integer; IMDbYear : Integer; IMDbRating : Integer; IMDbActors : Integer; IMDbCategory : Integer; IMDbComments : Integer; // Strings below are defined here to compare lionetwork data MovieLength, MovieOutYear, MovieRatings : String; CompareI : integer; NoMore : integer; IndexSearch : integer; //imdb functions procedure AnalyzeResultsPageIMDB(Address: string); var PageText: string; Value: string; begin PageText := GetPage(Address); if pos('IMDb', PageText) = 0 then begin AnalyzeMoviePageIMDB(PageText) end else begin if Pos('<b>No Matches.</b>', PageText) > 0 then begin if 1 = 1 then begin ShowMessage('שם הסרט לא מתאים לאי.אמ.די.בי הכנס שם חדש'); Input('IMDB Import', 'Enter the title or the IMDB URL of the movie:', MovieNameIMDB); AnalyzeResultsPageIMDB('http://us.imdb.com/find?more=tt;q=' + UrlEncode(MovieNameIMDB)); end; end; if NoMore = 0 Then Begin if 1 = 1 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 AddMovieTitlesIMDB(Value); Value := TextBefore(PageText, '"><b>more titles</b></a>', '<a href="'); if Value <> '' then PickTreeMoreLink('http://us.imdb.com' + Value); if PickTreeExec(Address) then AnalyzeResultsPageIMDB(Address); NoMore := 1; end else begin Value := TextBetween(TextBetween(PageText, '<ol>', '</ol>'), '<li>', '</li>'); if Value <> '' then AnalyzeResultsPageIMDB(TextBetween(Value, '<a href="', '">')); end; end; end; end; // ***** adds the titles contained in <ol>'s items ***** function AddMovieTitlesIMDB(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, 'http://us.imdb.com' + Address); Result := True; Value := TextBetween(List, '<li>', '</li>'); List := RemainingText; end; end; // ***** analyzes the page containing movie information ***** procedure AnalyzeMoviePageIMDB(PageText: string); var Value, Value2, Value3, FullValue: string; p: Integer; begin MovieNumberIMDB := TextBetween(PageText, '<input type="hidden" name="auto" value="legacy/title/tt', '/"><input'); MovieURLIMDB := 'http://imdb.com/title/tt' + MovieNumberIMDB; { URL Is Set by lionetwork or no URL at all // URL if CanSetField(fieldURL) then SetField(fieldURL, MovieURLIMDB); } // Original Title & Year // Here We may get results we don't want, but I prefer IMDB's spelling for the Movie Name Rather than Lionetwork's if CanSetField(fieldOriginalTitle) or CanSetField(fieldYear) then begin Value := TextBetween(PageText, '<title>', ''); Value2 := TextBefore(Value, ' (', ''); Value := RemainingText; HTMLDecode(Value2); if CanSetField(fieldOriginalTitle) then SetField(fieldOriginalTitle, Value2); if Pos('/', Value) > 0 then Value2 := TextBefore(Value, '/', '') else Value2 := TextBefore(Value, ')', ''); // Again prefer IMDB year rather than Lionetwork if IMDbYear = 1 then begin If StrToInt(Value2, CompareI) <> StrToInt(MovieOutYear, CompareI) Then begin if CanSetField(fieldYear) then SetField(fieldYear, Value2); end; end else if CanSetField(fieldYear) then SetField(fieldYear, Value2); end; // Rating if CanSetField(fieldRating) then begin Value := TextBetween(PageText, '/rating-stars/', '/rating-vote/'); SetField(fieldRating, TextBetween(Value, '', '/')); end; // Picture If IMDbImage = 0 Then begin if CanSetPicture then begin case GetOption('ImageKind') of 1: ImportSmallPictureIMDB(PageText); 2: if not ImportLargePictureIMDB('http://us.imdb.com/gallery/ss/' + MovieNumberIMDB) then ImportSmallPictureIMDB(PageText); 3: if not ImportLargePictureIMDB('http://us.imdb.com/gallery/ss/' + MovieNumberIMDB) then if not ImportMerchandisingPicture(PageText) then if not ImportDvdDetailsPicture(PageText) then ImportSmallPictureIMDB(PageText); 4: if not ImportMerchandisingPicture(PageText) then if not ImportDvdDetailsPicture(PageText) then ImportSmallPictureIMDB(PageText); 5: if not ImportDvdDetailsPicture(PageText) then if not ImportMerchandisingPicture(PageText) then ImportSmallPictureIMDB(PageText); 6: if not ImportAmazonPicture(PageText) then ImportSmallPictureIMDB(PageText); end; 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 IMDbActors = 0 Then begin if CanSetField(fieldActors) then begin Value := TextBetween(PageText, 'ast overview', ''); if Value = '' then Value := TextBetween(PageText, 'redited cast', ''); if Value <> '' then begin Value := 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; 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; 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); end; end; end; //Country if CanSetField(fieldCountry) then begin SetField(fieldCountry, ImportListIMDB(PageText, GetOption('MultipleValuesCountry'), '/Countries/')); end; //Category if IMDbCategory = 0 Then begin if CanSetField(fieldCategory) then begin SetField(fieldCategory, ImportListIMDB(PageText, GetOption('MultipleValuesCategory'), '/Genres/')); end; end; // Language if CanSetField(fieldLanguages) then begin SetField(fieldLanguages, ImportListIMDB(PageText, GetOption('MultipleValuesLanguages'), '/Languages/')); end; // Description if IMDbDesc = 0 Then begin 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:', '