unit ImdbPas; { Main IMDb var, constants and functions } uses // Debug, // StringUtils1, StringUtils7552; ItalianSharedPas; const ID_UnitVersion = 5; PopularTitleSearchURL = 'https://www.imdb.com/find?s=tt&q='; FullTitleSearchURL = 'https://www.imdb.com/find?s=tt&exact=true&q='; EpisodeTitleSearchURL = 'https://www.imdb.com/find?s=ep&q='; var MovieName: string; MovieURL: string; MovieNumber: string; MovieYear: string; UpdateFile: TStringList; // ----------------------------------- // Main program (for MultiSite) // IN: properties values (serialized) // OUT: properties values (serialized) // ----------------------------------- function IMDbCoreMultiSite(serializedValues: string): string; var italianDescription, italianComments: string; begin italianDescription := getField(fieldDescription); italianComments := getField(fieldComments); SharedUnserializeMe(serializedValues); if (GetField(fieldYear) <> '') then SharedSetYearDate(GetField(fieldYear)); if (GetField(fieldDirector) <> '') then SharedSetDirectorName(GetField(fieldDirector)); if (GetField(fieldTranslatedTitle) <> '') then SharedSetTranslatedStr(GetField(fieldTranslatedTitle)); if (GetField(fieldOriginalTitle) <> '') then SharedSetOriginalStr(GetField(fieldOriginalTitle)); // Analyze search page and get movie url (user choice) if (SharedGetMoviesFound() = 0) then IMDbSearchResults(); if (SharedGetMoviesFound() > 0) then // Analyze movie page and set movie fields IMDbSetMovieFields(); if (italianDescription <> '') then SharedSecureSetField(fieldDescription, italianDescription); SharedSecureSetField(fieldComments, italianComments); result := SharedSerializeMe(); end; procedure IMDbSearchResults; var myUrl: string; pageNumberMovies: integer; begin pageNumberMovies := 0; if RegExprSetExec('tt[0-9]+', fulltrim(SharedGetMovieName())) then begin SharedSetMovieUrl('https://www.imdb.com/title/' + fulltrim(SharedGetMovieName()) + '/reference'); SharedSetMoviesFound(1); end else begin repeat SharedSetMovieUrl(''); SharedSetMoviesFound(0); myUrl := 'https://www.imdb.com/search/title/?title=' + SharedAdvancedUrlEncode(UTF8Encode(SharedGetMovieName()), false) + '&title_type=feature,tv_movie,tv_series,tv_episode,tv_special,tv_miniseries,documentary,short,video,tv_short&adult=include'; if (SharedGetYearDate() <> '') then myUrl := myUrl + '&release_date=' + SharedAdvancedUrlEncode((IntToStr(StrToInt(SharedGetYearDate(), 0) - 3) + '-01-01,' + IntToStr(StrToInt(SharedGetYearDate(), 0) + 3) + '-12-31'), false); if (pageNumberMovies > 0) then myUrl := myUrl + '&start=' + IntToStr(((pageNumberMovies * 50) + 1)) + '&ref_=adv_nxt'; SharedHTTPGetPage(myUrl); IMDbPopulatePickTree(); // se non ho trovato nessun titolo oppure non ho trovato una url certa e avevo impostato la ricerca IMDB a 1 allora esco if ((SharedGetMovieUrl() = '') AND (GetParam('IMDB Ricerca') = '1')) then SharedSetMoviesFound(0); if (SharedGetMoviesFound() = 0) then begin SharedSetForceExit(true); exit; end; SharedPickTreeExec(); pageNumberMovies := pageNumberMovies + 1; until (copy(SharedGetMovieUrl(), 1, 5) <> 'next:'); end; end; // ----------------------- // ANALYZE MOVIE DATA PAGE // IN: none // ----------------------- procedure IMDbSetMovieFields; var PageText: string; begin PageText := ConvertToASCII(GetPage(SharedGetMovieUrl())); if (PageText <> '') then AnalyzeMoviePage(PageText); IMDbFinalize(); end; procedure IMDbPopulatePickTree; var PageText, MText, MTitle, MYear, Mdirectors, MURL, MURLS: string; NextPageAvailable: boolean; begin NextPageAvailable := (pos('>Next »<', SharedGetLatestPageHtml()) > 0); SharedPickTreeCreate(); MURLS := ''; if ((pos('No results.', SharedGetLatestPageHtml()) = 0) AND (pos('
'' then Result := ImportFromAmazonRedirect('https://www.imdb.com' + Value); end; end; function ImportFromAmazonRedirect(Url: string): Boolean; var Value, PageText: string; begin Result := False; PageText := ConvertToASCII(GetPage(Url)); Value := TextBetween(PageText, ' | '' then
begin
GetPicture(Value);
Result := True;
end;
end;
// ***** Gets summaries for the movie, based on the plot outline given in parameter (that contains the URL to more summaries) *****
{
function ImportSummary(PlotText: string): string;
var
Address, Value, PageText, Longest: string;
begin
Address := TextBetween(PlotText, '', '');
Value := TextBetween(PageText, ' ', ' '); PageText := RemainingText; while Value <> '' do begin Value := FullTrim(StringReplace(Value, #13#10, ' ')); Value := StringReplace(Value, '', #13#10); HTMLRemoveTags(Value); HTMLDecode(Value); while Pos(' ', Value) > 0 do Value := StringReplace(Value, ' ', ' '); if Length(Value) > Length(Longest) then Longest := Value; PickListAdd(FullTrim(Value)); Value := TextBetween(PageText, ' ', ' '); PageText := RemainingText; end; if (GetOption('IMDB Interazioni') > 0) or (GetOption('IMDB Trama') = 2) then Result := Longest else begin if not PickListExec('Select a description for "' + GetField(fieldOriginalTitle) + '"', Result) then Result := ''; end; end; end; } // Import awards procedure ImportAwards; var IndexPage: TStringList; PageText, FullValue, Block, Value, Row, Outcome, Details, AwardShow, PageText1: string; Year, Result, Award, Category: string; begin sleep(50); Value := MovieUrl; PageText := ConvertToASCII(GetPage(Value+'/awards')); repeat AwardShow := TextBetween(PageText, '', ''); if Pos('User Lists', AwardShow) > 0 then break; HTMLRemoveTags(AwardShow); HTMLDecode(AwardShow); AwardShow := FullTrim(AwardShow); AwardShow := StringReplace(AwardShow, #13, ''); AwardShow := StringReplace(AwardShow, #10, ''); FullValue := FullValue + #32 + AwardShow + #13#10; PageText1 := TextBetween(PageText, '
|