I have updated the IMDB script (it is still a work in progress) to get it to work in most scenarios. When I get 404 or no data, I have tried re-running the script which often works fine but there are also times where I am just unable to fetch the data and ended up passing URL so that will need to be looked at. I am sure there is probably better way to fix the issue as I've only "hacked" my way thru the script.
Below script does contain some of the modifications I made for my personal use (certification or MPAA rating data and couple of minor tweaks) so if you do not want any of that then just
Code: Select all
program IMDB;
uses
// Debug,
StringUtils1, StringUtils7552;
const
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;
function ConvertToASCII(AText: string): string;
begin
Result := UTF8Decode(AText);
if Result = '' then
Result := AText; // in case of a UTF8 decoding error
if GetOption('ConvertToASCII') = 1 then
Result := Cp1252ToASCII(Result);
end;
function AKACountry: string;
var
UserCountry: string;
begin
UserCountry := GetParam('UserCountry');
if UserCountry = 'United States' then
Result := 'USA'
else if UserCountry = 'United Kingdom' then
Result := 'UK'
else
Result := UserCountry;
end;
// ***** analyzes IMDB's results page that asks to select a movie from a list *****
procedure AnalyzeResultsPage(Address: string);
var
PageText: string;
Value: string;
begin
PageText := ConvertToASCII(GetPage(Address));
if pos('<title>Find - 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;
Value := TextBetween(PageText, '>Titles</h3>', '</section>');
if Value <> '' then
begin
PickTreeAdd('Titles search results', '');
//ShowMessage('Val: ' + Value);
AddMovieTitles(Value);
end;
if PickTreeExec(Address) then
AnalyzeResultsPage(Address);
end
else
if (MovieYear <> '') then
begin
Value := GetUrlBefore(PageText, '(' + MovieYear + ')', '');
if Value = '' then
begin
Value := GetUrlBefore(PageText, '(' + IntToStr(StrToInt(MovieYear, 0) - 1) + ')', '');
if Value = '' then
Value := GetUrlBefore(PageText, '(' + IntToStr(StrToInt(MovieYear, 0) + 1) + ')', '');
end;
if Value <> '' then
AnalyzeResultsPage('https://www.imdb.com' + Value);
end
else
begin
Value := TextBetween(PageText, '<td class="primary_photo">', '<img src');
if Value <> '' then
AnalyzeResultsPage('https://www.imdb.com' + TextBetween(Value, '<a href="', '"'));
end;
end;
end;
// ***** adds the movie titles found on IMDB's results page *****
function AddMovieTitles(List: string): Boolean;
var
Value: string;
Year: string;
AdditionalValue: string;
Address: string;
SummaryValue: string;
begin
Result := False;
//ShowMessage('L1 :' + List);
//Value := TextBetween(List, '<td class="result_text">', '</td>');
Value := TextBetween(List, '<a class="ipc-metadata-list-summary-item__t" role="button" tabindex="0" aria-disabled="false" ', '</a>');
//ShowMessage('V1 :' + Value);
if GetOption('HideAkaTitles') = 1 then
Value := StringReplace(Value, TextAfter(Value, '<br/>aka'), '')
else
Value := StringReplace(Value, 'aka', ' | aka');
List := RemainingText;
//ShowMessage('L2 :' + List);
while Value <> '' do
begin
Address := TextBetween(Value, 'href="/title/tt', '/');
Address := Address + '/reference';
Value := TextAfter(Value, '">');
HTMLRemoveTags(Value);
HTMLDecode(Value);
//ShowMessage('Val: ' + Value);
//ShowMessage('Add: ' + Address);
SummaryValue := TextBetween(List, 'ipc-metadata-list-summary-item__li', '</div><div');
//ShowMessage('SV: ' + SummaryValue);
Year := TextBetween(SummaryValue, '">', '</span></li>');
HTMLRemoveTags(Year);
HTMLDecode(Year);
Value := Value + ' (' + Year + ')';
//ShowMessage('V + AV: ' + Value);
SummaryValue := RemainingText;
while SummaryValue <> '' do
begin
AdditionalValue := TextBetween(SummaryValue, 'ipc-metadata-list-summary-item__li">', '</span></li></ul>');
SummaryValue := RemainingText;
if AdditionalValue <> '' then
begin
//ShowMessage('SV Inside: ' + SummaryValue);
HTMLRemoveTags(AdditionalValue);
HTMLDecode(AdditionalValue);
Value := Value + ' | ' + AdditionalValue + ')';
//ShowMessage('V2 + AV: ' + Value);
end else
break;
end;
PickTreeAdd(Value, 'https://www.imdb.com/title/tt' + Address);
Result := True;
//Value := TextBetween(List, '<td class="result_text">', '</td>');
Value := TextBetween(List, '<a class="ipc-metadata-list-summary-item__t" role="button" tabindex="0" aria-disabled="false" ', '</a>');
if GetOption('HideAkaTitles') = 1 then
Value := StringReplace(Value, TextAfter(Value, '<br/>aka'), '')
else
Value := StringReplace(Value, 'aka', ' | aka');
List := RemainingText;
//ShowMessage('L3: ' + List);
end;
end;
// ***** analyzes the page containing movie information *****
procedure AnalyzeMoviePage(PageText: string);
var
Value, Value2, FullValue, LastValue, originalTitle, certificationValues, LastCertificationValue: string;
p, Count: Integer;
begin
MovieNumber := TextBetween(PageText, '<input type="hidden" name="auto" value="legacy/title/tt', '/');
if MovieNumber = '' then
MovieNumber := TextBetween(PageText, '<input type="hidden" name="auto" value="legacy/title/tt', '/reference"');
if MovieNumber = '' then
MovieNumber := TextBetween(PageText, '<link rel="canonical" href="https://www.imdb.com/title/tt', '/');
if Pos('/reference"', TextBetween(PageText, '<link rel="canonical"', '/>')) = 0 then
PageText := ConvertToASCII(GetPage('https://www.imdb.com/title/tt' + MovieNumber + '/reference'));
MovieURL := 'https://www.imdb.com/title/tt' + MovieNumber;
// URL
if CanSetField(fieldURL) then
SetField(fieldURL, MovieURL);
// OriginalTitle & Year
{
if CanSetField(fieldOriginalTitle) or CanSetField(fieldYear) then
begin
originalTitle := TextBefore(PageText, '(original title)', '</h1>');
HTMLRemoveTags(originalTitle);
HTMLDecode(originalTitle);
originalTitle := RemoveSpaces(originalTitle, true);
if (originalTitle <> '') and CanSetField(fieldOriginalTitle) then
begin
SetField(fieldOriginalTitle, FullTrim(originalTitle));
end;
Value := TextBetween(PageText, '<title>', '</title>');
p := Pos(' (1', Value);
if p = 0 then
p := Pos(' (2', Value);
if p = 0 then
p := Pos(' (TV', Value);
if p > 0 then
begin
Value2 := Copy(Value, 0, p-1);
Value := Copy(Value, p+2, Length(Value));
HTMLDecode(Value2);
if (originalTitle = '') and CanSetField(fieldOriginalTitle) then
SetField(fieldOriginalTitle, FullTrim(Value2));
if CanSetField(fieldYear) then
begin
if Pos('/', Value) > 0 then
begin
Value := TextBefore(Value, '/', '');
end
else
begin
Value := TextBefore(Value, ')', '');
end;
if Pos('–', Value2) > 0 then
begin
Value := TextBefore(Value, '–', '');
end;
SetField(fieldYear, Value);
end;
end;
end;
}
if CanSetField(fieldOriginalTitle) or CanSetField(fieldYear) then
begin
originalTitle := TextBefore(PageText, '(original title)', '</h3>');
if originalTitle ='' then originalTitle := TextBetween (PageText,'<h3 itemprop="name">','<span class="titlereference-title-year">');
Value:= TextBetween (Pagetext, '<span class="titlereference-title-year">', '<ul class="ipl-inline-list">');
Value:= TextBetween (Value, 'url', '</a>)');
Value:= TextAfter (Value, '>');
HTMLRemoveTags(originalTitle);
HTMLDecode(originalTitle);
originalTitle := RemoveSpaces(originalTitle, true);
if (originalTitle <> '') and CanSetField(fieldOriginalTitle) then
SetField(fieldOriginalTitle, FullTrim(originalTitle));
end;
if CanSetField(fieldYear) then SetField(fieldYear, Value);
// Picture
if CanSetPicture then
begin
case GetOption('ImageKind') of
2: if not ImportSmallPicture(PageText) then
ImportPictureNotAvailable(PageText);
3: ImportLargePicture(PageText);
4: if not ImportMerchandisingPicture then
if not ImportDvdDetailsPicture then
ImportSmallPicture(PageText);
5: if not ImportDvdDetailsPicture then
if not ImportMerchandisingPicture then
ImportSmallPicture(PageText);
3: if not ImportLargePicture(PageText) then
if not ImportSmallPicture(PageText) then
ImportPictureNotAvailable(PageText);
else
ImportSmallPicture(PageText);
end;
end;
// Director
if CanSetField(fieldDirector) then
begin
Value := TextBetween(PageText, '<h4 name="directors"', '</table>');
FullValue := '';
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
while Value2 <> '' do
begin
Value := RemainingText;
Value2 := TextAfter(Value2, '>');
if FullValue <> '' then
FullValue := FullValue + ', ';
FullValue := FullValue + Value2;
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
end;
HTMLDecode(FullValue);
FullValue := RemoveSpaces(FullValue, true);
SetField(fieldDirector, FullValue);
end;
// Actors
if CanSetField(fieldActors) then
begin
if GetOption('AllActors') = 0 then
begin
FullValue := TextBetween(PageText, ' Stars:', '</li>');
HTMLRemoveTags(FullValue);
HTMLDecode(FullValue);
FullValue := RemoveSpaces(FullValue, true);
end
else
begin
FullValue := '';
Value := FullTrim(TextBetween(PageText, '<h4 name="cast"', '</table>'));
if Value <> '' then
begin
Count := 0;
p := StrToInt(GetParam('MaxActors'), 10);
case GetOption('ActorsLayout') of
0, 1:
while Pos('<tr class', Value) > 0 do
begin
Value2 := TextBetween(Value, '<tr class', '</tr>');
Value := RemainingText;
if Pos('Rest of cast', Value2) > 0 then
Continue;
if FullValue <> '' then
FullValue := FullValue + #13#10;
TextBefore(Value2, '</td>', '');
Value2 := FullTrim(TextBetween(Value2, '<td class="itemprop" itemprop="actor" itemscope itemtype="http://schema.org/Person">', '</td>'));
HTMLRemoveTags(Value2);
Value2 := RemoveSpaces(Value2, true);
if Value2 <> '' then
begin
FullValue := FullValue + Value2;
Count := Count + 1;
end;
if (Count = p) and (GetOption('AllActors') = 2) then
begin
Break;
end;
end;
2, 3, 4:
while Pos('<tr', Value) > 0 do
begin
Value2 := TextBetween(Value, '<tr class', '</tr>');
Value := RemainingText;
if Pos('Rest of cast', Value2) > 0 then
Continue;
if FullValue <> '' then
FullValue := FullValue + #13#10;
TextBefore(Value2, '</td>', '');
Value2 := FullTrim(TextBetween(Value2, '<td class="itemprop" itemprop="actor" itemscope itemtype="http://schema.org/Person">', '</td>'));
HTMLRemoveTags(Value2);
Value2 := RemoveSpaces(Value2, true);
if Value2 <> '' then
begin
FullValue := FullValue + Value2;
Value2 := FullTrim(TextBetween(RemainingText, '<td class="character">', '</td>'));
HTMLRemoveTags(Value2);
Value2 := RemoveSpaces(Value2, true);
if Value2 <> '' then
begin
if GetOption('ActorsLayout') = 4 then
begin
FullValue := FullValue + ' ... ' + Value2;
end
else
begin
FullValue := FullValue + ' (as ' + Value2 + ')';
end;
end;
Count := Count + 1;
if (Count = p) and (GetOption('AllActors') = 2) then
begin
Break;
end;
end;
end;
end;
HTMLRemoveTags(FullValue);
HTMLDecode(FullValue);
case GetOption('ActorsLayout') of
0, 2:
begin
FullValue := StringReplace(FullValue, #13#10, ', ');
end;
end;
end;
end;
SetField(fieldActors, FullValue);
end;
// Composer
if CanSetField(fieldComposer) then
begin
Value := TextBetween(PageText, '<h4 name="composers"', '</table>');
FullValue := '';
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
while Value2 <> '' do
begin
Value := RemainingText;
Value2 := TextAfter(Value2, '>');
if FullValue <> '' then
FullValue := FullValue + ', ';
FullValue := FullValue + Value2;
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
end;
HTMLDecode(FullValue);
FullValue := RemoveSpaces(FullValue, true);
SetField(fieldComposer, FullValue);
end;
//Country
if CanSetField(fieldCountry) then
begin
SetField(fieldCountry, ImportList(PageText, GetOption('MultipleValuesCountry'), '<td class="ipl-zebra-list__label">Country</td>'));
end;
//Category
if CanSetField(fieldCategory) then
begin
SetField(fieldCategory, ImportList(PageText, GetOption('MultipleValuesCategory'), '<td class="ipl-zebra-list__label">Genres</td>'));
end;
// Language
if CanSetField(fieldLanguages) then
begin
SetField(fieldLanguages, ImportList(PageText, GetOption('MultipleValuesLanguages'), '<td class="ipl-zebra-list__label">Language</td>'));
end;
// Audio Format
if CanSetField(fieldAudioFormat) then
begin
SetField(fieldAudioFormat, ImportList(PageText, GetOption('MultipleValuesAudioFormat'), '<td class="ipl-zebra-list__label">Sound Mix</td>'));
end;
// Aspect Ratio
begin
Value := '';
Value := TextBetween(PageText, '<td class="ipl-zebra-list__label">Aspect Ratio</td>', '</li>');
HTMLRemoveTags(Value);
HTMLDecode(Value);
Value := RemoveSpaces(Value, true);
if (CanSetField(fieldVideoFormat)) and (GetOption('AspectRatio') = 1) then
SetField(fieldVideoFormat, Value);
if (CanSetField(fieldResolution)) and (GetOption('AspectRatio') = 2) then
SetField(fieldResolution, Value);
end;
// Description
if CanSetField(fieldDescription) then
begin
if (GetOption('DescriptionSelection') = 0) then
begin
Value := TextBetween(PageText, '<section class="titlereference-section-overview">', '<div class="titlereference-overview-section">');
//Value := TextAfter(Value, '<hr>');
end
else
begin
Value := TextBetween(PageText, '<td class="ipl-zebra-list__label">Plot Summary</td>', '</td>');
Value := TextBefore(Value, '</p>', '');
if Pos('<em', Value) > 0 then
begin
Value := TextBefore(Value, '<em', '');
end;
if Value = '' then // no long description on the page, taking the short one
begin
Value := TextBetween(PageText, '<section class="titlereference-section-overview">', '<div class="titlereference-overview-section">');
end;
end;
HTMLRemoveTags(Value);
HTMLDecode(Value);
Value := StringReplace(Value, ConvertToAscii('See more »'), '');
Value := RemoveSpaces(Value, true);
SetField(fieldDescription, Value);
end;
// Length
if CanSetField(fieldLength) then
begin
Value := TextBetween(PageText, '<td class="ipl-zebra-list__label">Runtime</td>', '</li>');
Value := TextBefore(Value, ' min', '');
HTMLRemoveTags(Value);
Value := RemoveSpaces(Value, true);
if Value <> '' then
begin
SetField(fieldLength, Value);
end;
end;
// Producer
if CanSetField(fieldProducer) then
begin
Value := TextBetween(PageText, '<h4 name="producers"', '</table>');
FullValue := '';
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
while Value2 <> '' do
begin
Value := RemainingText;
Value2 := TextAfter(Value2, '>');
if FullValue <> '' then
FullValue := FullValue + ', ';
HTMLRemoveTags(Value2);
FullValue := FullValue + RemoveSpaces(Value2, true);
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
end;
HTMLDecode(FullValue);
SetField(fieldProducer, FullValue);
end;
// Writer
if CanSetField(fieldWriter) then
begin
Value := TextBetween(PageText, '<h4 name="writers"', '</table>');
FullValue := '';
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
while Value2 <> '' do
begin
Value := RemainingText;
Value2 := TextAfter(Value2, '>');
if FullValue <> '' then
FullValue := FullValue + ', ';
HTMLRemoveTags(Value2);
FullValue := FullValue + RemoveSpaces(Value2, true);
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
end;
HTMLDecode(FullValue);
SetField(fieldWriter, FullValue);
end;
// AKA Name
if CanSetField(fieldTranslatedTitle) then
begin
Count := 0;
LastValue := '';
FullValue := ConvertToASCII(GetPage(MovieURL+'/releaseinfo#akas'));
FullValue := TextBetween(FullValue, 'id="akas"', '</table>');
PickTreeClear;
PickTreeAdd('Select the translated title', '');
while Fullvalue <> '' do
begin
Value2 := TextBetween(FullValue, ' <td class="aka-item__name">', '</td>'); //country
Value := TextBetween(FullValue, '<td class="aka-item__title">', '</td>'); //title
HTMLDecode(Value2);
HTMLDecode(Value);
if (Pos(AKACountry(), Value2) > 0) and (Value <> originalTitle) then
begin
LastValue := Value;
Count := Count + 1;
if (Count = 1) and (GetOption('BatchMode') > 0) then
begin
Break;
end
PickTreeAdd(Value, Value);
end;
FullValue := TextAfter(FullValue, '</tr>');
end;
if Count = 1 then
begin
SetField(fieldTranslatedTitle, LastValue);
end else
if Count > 1 then
begin
if PickTreeExec(Value) then
begin
SetField(fieldTranslatedTitle, Value);
end;
end;
end;
// Comments
if CanSetField(fieldComments) then
begin
case GetOption('CommentType') of
0, 1:
begin
Value2 := '';
p := 0;
FullValue := ConvertToASCII(GetPage(MovieURL+'/reviews'));
FullValue := TextAfter(FullValue, '<div class="lister-item mode-detail imdb-user-review');
while FullValue <> '' do
begin
Value := TextBetween(FullValue, '<div class="review-container">','<div class="actions text-muted">');
if GetOption('CommentType') = 1 then
begin
p := p + 1;
Value2 := Value2 + inttostr(p) + '. ';
end;
Value2 := Value2 + TextBetween(Value, '<div class="title">','</div>');
Value2 := Value2 + ' (by ' + TextAfter (TextBetween(Value, '<span class="display-name-link">','</a>'),'>');
Value2 := Value2 + #32 + 'on ' + TextBetween(Value, '<span class="review-date">', '</span>') + ')' ;
Value := RemainingText;
Value := TextBetween(Value, '<div class="text show-more__control">','</div>');
Value := StringReplace(Value, #13#10, ' ');
Value := StringReplace(Value, '<br/><br/>', #13#10);
Value := StringReplace(Value, '<br/>', #13#10);
HtmlRemoveTags(Value);
Value2 := Value2 + #13#10 + #13#10 + FullTrim(Value);
if GetOption('CommentType') = 0 then
begin
break;
end;
FullValue := TextAfter(FullValue, '<div class="lister-item mode-detail imdb-user-review');
if FullValue <> '' then
begin
Value2 := Value2 + #13#10 + #13#10;
end;
end;
HTMLRemoveTags(Value2);
HTMLDecode(Value2);
SetField(fieldComments, Value2);
end;
2:
begin
SetField(fieldComments, '');
end;
end;
end;
// TagLine
if GetOption('GetTagline') > 0 then
begin
Value := TextBetween(PageText, '<td class="ipl-zebra-list__label">Taglines</td>', '</td>');
HTMLRemoveTags(Value);
HTMLDecode(Value);
Value := StringReplace(Value, ConvertToAscii('See more »'), '');
Value := RemoveSpaces(Value, true);
if Value <> '' then
begin
if StrGet(Value, 1) <> '"' then
Value := '"' + Value + '"';
case GetOption('GetTagline') of
1:
begin
if GetField(fieldDescription) <> '' then
Value := Value + #13#10 + #13#10 + GetField(fieldDescription);
SetField(fieldDescription, Value);
end;
2:
begin
if GetField(fieldComments) <> '' then
Value := Value + #13#10 + #13#10 + GetField(fieldComments);
SetField(fieldComments, Value);
end;
end;
end;
end;
// Trivia
if GetOption('Trivia') > 0 then
begin
sleep(50);
Value := MovieUrl;
FullValue := ConvertToASCII(GetPage(Value+'/trivia'));
case GetOption('Trivia') of
1,2:
Value := TextBetween(FullValue, '<div class="sodatext">', '</div>');
3,4:
Value := TextBetween(FullValue, '<div class="list">', '<div id="sidebar">');
end;
if Value <> '' then
begin
Value := StringReplace(Value, #13#10, '');
while Pos(' ', Value) > 0 do
Value := StringReplace(Value, ' ', '');
while Pos('<span class="linksoda">', Value) > 0 do
begin
Value := StringReplace(Value, TextBetween(Value, '<span class="linksoda">', '</div>'), '');
Value := StringReplace(Value, '<span class="linksoda"></div>', '');
end;
Value := StringReplace(Value, 'Link this trivia', '');
Value := StringReplace(Value, '<div class="sodatext">', #13#10 + '- ');
Value := StringReplace(Value, TextBetween(Value, '<script type="text/javascript">', '</script>'), '');
HTMLRemoveTags(Value);
HTMLDecode(Value);
Value := RegExprSetReplace('\s[\d,]+\s+of\s+[\d,]+\sfound\sthis\sinterestingInteresting\?YesNo\|', Value, '', false);
Value := RegExprSetReplace('\s*Is\sthis\sinteresting\?Interesting\?YesNo\|', Value, '', false);
Value := RegExprSetReplace('Spoilers\sThe\strivia\sitems?\sbelow\smay\sgive\saway\simportant\splot\spoints\.\s*', Value, #13#10 + 'Spoilers:' + #13#10, false);
Value := RegExprSetReplace('\s*See\salsoGoofs.*', Value, '', false);
if (GetOption('Trivia') = 1) or (GetOption('Trivia') = 2) then
Value := ' ' + Value;
case GetOption('Trivia') of
1,3:
begin
if GetField(fieldDescription) <> '' then
Value := GetField(fieldDescription) + #13#10 + #13#10 + 'IMDB TRIVIA:' + Trim(Value)
else
Value := 'IMDB TRIVIA: ' + Value;
SetField(fieldDescription, Value);
end;
2,4:
begin
if GetField(fieldComments) <> '' then
Value := GetField(fieldComments) + #13#10 + #13#10 + 'IMDB TRIVIA:' + Trim(Value)
else
Value := 'IMDB TRIVIA: ' + Value;
SetField(fieldComments, Value);
end;
end;
end;
end;
// Awards
if (GetOption('Awards') > 0) then
begin
ImportAwards();
end;
// Rating
if CanSetField(fieldRating) then
begin
// (Remove the "//" of the next two lines beginning with "Value" and add "//" to the following two lines beginning with Value
// if you would like to import arithmetic ratings instead of IMDB's user ratings)
// Value := ConvertToASCII(GetPage(MovieURL + '/ratings'));
// Value := TextBetween(Value, 'Arithmetic mean = ', '. ');
// *** not sure that changing that still works, to be confirmed
Value := TextBetween(PageText, '<span class="ipl-rating-star__rating">', '</span>');
if Value <> '' then
if (GetOption('RoundRating') = 1) then
SetField(fieldRating, IntToStr(Round(StrToFloat(Value))))
else
SetField(fieldRating, Value);
end;
if GetOption('UserRatings') > 0 then
begin
Value := TextBetween(PageText, '<a href="ratings" class="tn15more">', '</a>');
if Value <> '' then
Value := 'User Rating: ' + GetField(fieldRating) + ' out of 10 (with ' + Value + ')';
if (GetOption('UserRatings') = 1) and (Value <> '') and (CanSetField(fieldMediaType)) then
SetField(fieldMediaType, Value);
if (GetOption('UserRatings') = 2) and (Value <> '') then
SetField(fieldComments, GetField(fieldComments) + #13#10 + #13#10 + Value);
end;
// Classification - 10/11/22 replaced with below certification code
// if CanSetField(fieldCertification) then
// begin
// Value := TextBetween(PageText, '<a href="/search/title?certificates=', '</div>');
//ShowMessage('Value: '+Value);
// Value := TextBetween(Value, GetParam('UserCountry') + ':', '</a>');
// if Value <> '' then
// SetField(fieldCertification, Value);
// end;
// Classification - 10/11/22 replaced with below certification code
if CanSetField(fieldCertification) then
begin
Value := TextBetween(PageText, '<span class="titlereference-change-view-link">', '<div class=');
Value := TextBetween(Value, '<li class="ipl-inline-list__item">', '</li>');
Value := StringReplace(Value, #13#10, '');
//ShowMessage('Initial Value: [' + Value + ']');
//ShowMessage('Initial pos: [' + IntToStr(Pos(' ', Value)) + ']');
while Pos(' ', Value) = 1 do
begin
Value := StringReplace(Value, ' ', '');
//ShowMessage('Inter pos: [' + IntToStr(Pos(' ', Value)) + ']');
//ShowMessage('Inter Value: [' + Value + ']');
end;
//ShowMessage('final pos: [' + IntToStr(Pos(' ', Value)) + ']');
//ShowMessage('Final Value: [' + Value + ']');
if Value <> '' then
SetField(fieldCertification, Value);
end;
// Certification -- Use below code to get list of all US certifications for selection
// if CanSetField(fieldCertification) then
// begin
// CertificationValues := TextBetween(PageText, '<a href="/search/title?certificates=US', '</table>');
// PickTreeClear;
// PickTreeAdd('Select the certification value', '');
// while CertificationValues <> '' do
// begin
// Value := TextBetween(CertificationValues, GetParam('UserCountry') + ':', '</a>'); //for user's country
// HTMLDecode(Value);
// Count := Count + 1;
// if Value = '' then
// begin
// Break;
// end;
// PickTreeAdd(Value, Value);
// LastCertificationValue := GetParam('UserCountry') + ':' + Value + TextBetween(CertificationValues, GetParam('UserCountry') + ':' + Value, '<li class=');
// CertificationValues := TextBetween(PageText, LastCertificationValue, '</table>');
// end;
// if Count = 1 then
// begin
// SetField(fieldCertification, Value);
// end else
// if Count > 1 then
// begin
// if PickTreeExec(Value) then
// begin
// SetField(fieldCertification, Value);
// end;
// end;
// end;
// MPAA rating
if (GetOption('MPAA') > 0) then
begin
Value := TextBetween(PageText, '<a href="/search/title?certificates=US', '</a>');
Value := Trim(TextAfter(Value, ':'));
if Value <> '' then
begin
if GetOption('MPAA') = 1 then
SetField(fieldCertification, Value)
else
SetField(fieldComments, GetField(fieldComments) + #13#10 + #13#10 + 'Rated ' + Value);
end;
end;
end;
// ***** Imports lists like Genre, Country, etc. depending of the selected option *****
function ImportList(PageText: string; MultipleValues: Integer; StartTag: string): string;
var
Value, Value2: string;
begin
if MultipleValues = 0 then
begin
Value := TextBetween(PageText, StartTag, '</a>');
Value2 := TextAfter(Value, '<li class="ipl-inline-list__item">');
end
else if MultipleValues = 3 then
begin
Exit;
end
else
begin
Value := TextBetween(PageText, StartTag, '</ul>');
Value2 := TextBefore(Value, 'See more »</a>', '');
if Value2 = '' then
Value2 := Value;
Value2 := TextAfter(Value2, '">');
Value2 := StringReplace(Value2, '<li class="ipl-inline-list__item">', ' / ');
end;
HTMLRemoveTags(Value2);
HTMLDecode(Value2);
Value2 := RemoveSpaces(Value2, true);
if Pos('/ ', Value2) = 1 then
begin
Delete(Value2, 1, 2);
end;
if MultipleValues = 1 then
begin
Value2 := StringReplace(Value2, ' / ', ', ');
end;
Result := Value2;
end;
// ***** functions to import the different pictures kinds, depending of the option selected by user *****
//Import small picture from IMDB movie main page
function ImportSmallPicture(PageText: string): Boolean;
var
Value: string;
begin
Result := False;
Value := TextBetween(PageText, 'alt="Poster"', '/>');
if (Value <> '') then
begin
Value := TextBetween(Value, 'src="', '"');
if Value <> '' then
begin
//Value := StringReplace(Value, 'https://', 'http://');
GetPicture(Value);
Result := True;
end;
end;
end;
//Import large image, building link from the small image of the movie page
function ImportLargePicture(PageText: string): Boolean;
var
Value: string;
begin
Result := False;
Value := TextBetween(PageText, 'alt="Poster"', '/>');
if (Value <> '') then
begin
Value := TextBetween(Value, 'src="', '"');
if Value <> '' then
begin
//Value := StringReplace(Value, 'https://', 'http://');
Value := TextBefore(Value, '._', '') + '._V1_SY' + GetParam('LargePictureHeight') + '_AL_.jpg';
GetPicture(Value);
Result := True;
end;
end;
end;
//Image not available, import "No Poster Available" icon
function ImportPictureNotAvailable(PageText: string): Boolean;
var
Value: string;
begin
Result := False;
Value := TextBetween(PageText, '<div class="photo">', '</div>');
if (Value <> '') and (Pos('"Poster Not Submitted"', Value) > 0) then
begin
Value := TextBetween(Value, 'src="', '"');
if Value <> '' then
begin
GetPicture(Value);
Result := True;
end;
end;
end;
//Image from DVD Details Page
function ImportDvdDetailsPicture: Boolean;
var
Value, PageText: string;
begin
Result := False;
PageText := ConvertToASCII(GetPage(MovieUrl+'/dvd'));
Value := TextBefore(PageText, '.jpg alt="', '<table class="dvd_section" cellpadding="10"><tr>');
if Value <> '' then
begin
Value := TextBetween(Value, '<a href="', '">');
if Value <> '' then
Result := ImportFromAmazonRedirect('https://www.imdb.com' + Value);
end;
end;
//Image from Merchandising Links (/sales) Page
function ImportMerchandisingPicture: Boolean;
var
Value, PageText: string;
begin
Result := False;
PageText := ConvertToASCII(GetPage(MovieUrl+'/sales'));
Value := TextBefore(PageText, '.jpg" width=', '<td class=w_rowtable_colcover><a href="');
if Value <> '' then
begin
Value := TextBefore(Value, '"><img', '');
if Value <> '' 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, '<td id="prodImageCell"', '" id="prodImage"');
// Value := StringReplace(TextAfter(Value, ' src="'), '_AA240', '');
Value := StringReplace(Value, TextBetween(Value, '_AA', '_'), '');
Value := StringReplace(TextAfter(Value, ' src="'), '_AA', '');
if Value <> '' 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, '<a class="tn15more inline" href="', '" ');
if (Address = '') or (GetOption('DescriptionSelection') = 0) then
begin
Result := FullTrim(TextBefore(PlotText, '<a class="tn15more inline"', ''));
if Result = '' then
Result := FullTrim(PlotText);
HTMLRemoveTags(Result);
HTMLDecode(Result);
end else
begin
PageText := ConvertToASCII(GetPage('https://www.imdb.com' + Address));
PickListClear;
Longest := '';
PageText := TextBetween(PageText, '<ul class="ipl-zebra-list" id="plot-summaries-content">', '</ul>');
Value := TextBetween(PageText, '<p>', '</p>');
PageText := RemainingText;
while Value <> '' do
begin
Value := FullTrim(StringReplace(Value, #13#10, ' '));
Value := StringReplace(Value, '<br>', #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, '<p>', '</p>');
PageText := RemainingText;
end;
if (GetOption('BatchMode') > 0) or (GetOption('DescriptionSelection') = 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, '<h3>', '</h3>');
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, '<table class="awards"', '</table>');
PageText := RemainingText;
Block := PageText1;
repeat
Row := TextBetween(Block, '<tr>', '</tr>');
Block := RemainingText;
Outcome := TextBetween(Row, '<b>', '</b>');
Category := TextBetween(Row, '<span class="award_category">', '</span>');
Award := TextBetween(Row, '<td class="award_description">', '</td>');
Details := TextBetween(Row, '<div class="award_detail_notes">', '</div>');
If Outcome <> '' then
FullValue := FullValue + #32 + Outcome + #13#10;
If Category <> '' then
FullValue := FullValue + #32 + Category;
If Award <> '' then
Award := StringReplace(Award, '<br />', #32);
HTMLRemoveTags(Award);
HTMLDecode(Award);
Award := StringReplace(Award, #13, '');
Award := StringReplace(Award, #10, '');
Award := FullTrim(Award);
Award := StringReplace(Award, ' ', '');
FullValue := FullValue + #32 + Award;
If Details <> '' then
HTMLRemoveTags(Details);
HTMLDecode(Details);
Award := StringReplace(Details, #13, '');
Award := StringReplace(Details, #10, '');
Award := FullTrim(Details);
FullValue := FullValue + #32 + Details + #13#10;
until (Row = '');
until (PageText1 = '');
// ShowInformation(FullValue);
if FullValue <> '' then
case GetOption('Awards') of
1:
begin
if GetField(fieldDescription) <> '' then
Value := GetField(fieldDescription) + #13#10 + #13#10 + 'AWARDS: ' + #13#10 + FullValue
else
Value := 'AWARDS: ' + FullValue;
SetField(fieldDescription, Value);
end;
2:
begin
if GetField(fieldComments) <> '' then
Value := GetField(fieldComments) + #13#10 + #13#10 + 'AWARDS: ' + #13#10 + FullValue
else
Value := 'AWARDS: ' + FullValue;
SetField(fieldComments, Value);
end;
end;
end;
// ***** beginning of the program *****
begin
// Check StringUtils1 version and update if < version 7
if StringUtils1_Version < 7 then
begin
if ShowWarning('Old version of file "Stringutils1.pas" detected: v'+IntToStr(StringUtils1_Version)+#13#10+'The script requires at least version 7.'+#13#10+'Download and install latest version now ?') = True then
begin
UpdateFile := TStringList.Create;
UpdateFile.Text := GetPage('http://update.antp.be/amc/scripts/StringUtils1.pas');
UpdateFile.SaveToFile(dirScripts + 'StringUtils1.pas');
UpdateFile.Free;
ShowInformation('StringUtils1 has been updated. Please restart IMDB script now. Thank you.');
Exit;
end
else
begin
ShowInformation('You can download latest version of "StringUtils1.pas" using script "update scripts" or via http://update.antp.be/amc/scripts');
Exit;
end;
end;
// Check for current AMC version
if CheckVersion(4,2,2) then
begin
// bug with default values it seems ?
if GetParam('MaxActors') = '' then
begin
SetParam('MaxActors', '10');
end;
if GetParam('UserCountry') = '' then
begin
SetParam('UserCountry', 'United States');
end;
if GetParam('LargePictureHeight') = '' then
begin
SetParam('LargePictureHeight', '720');
end;
MovieYear := GetField(fieldYear);
MovieName := '';
if GetOption('BatchMode') = 2 then
begin
MovieName := GetField(fieldURL);
if Pos('imdb.com', MovieName) = 0 then
MovieName := '';
end;
if MovieName = '' then
MovieName := GetField(fieldOriginalTitle);
if MovieName = '' then
MovieName := GetField(fieldTranslatedTitle);
if GetOption('BatchMode') = 0 then
begin
if not Input('IMDB Import', 'Enter the title or the IMDB URL of the movie:', MovieName) then
Exit;
end
else
Sleep(500);
if MovieName <> '' then
begin
if Pos('imdb.com', MovieName) > 0 then
begin
MovieName := StringReplace(MovieName, '//imdb.com', '//www.imdb.com');
MovieName := StringReplace(MovieName, 'http://', 'https://');
AnalyzeResultsPage(MovieName)
end else
if RegExprSetExec('tt[0-9]+', moviename) then
AnalyzeResultsPage('https://www.imdb.com/title/' + MovieName + '/reference')
else
begin
if CheckVersion(4,2,2) then
MovieName := StringReplace(MovieName, '&', 'and')
else
MovieName := UTF8Encode(StringReplace(MovieName, '&', 'and'));
if (GetOption('BatchMode') > 0) or (GetOption('PopularSearches') = 1) then
AnalyzeResultsPage(PopularTitleSearchURL + UrlEncode(MovieName))
else
AnalyzeResultsPage(FullTitleSearchURL + UrlEncode(MovieName));
end;
end;
end
else if ShowWarning('This script requires a newer version of Ant Movie Catalog, at least the version 4.2.2, currently available as beta - do you wish to open the link to download it?)') = true then
begin
Launch('https://forum.antp.be/phpbb3/viewtopic.php?f=6&t=6862', '');
end;
end.