Page 1 of 3

[MOD] IMDB Script: imports more info

Posted: 2005-03-22 09:25:43
by KaraGarga
Edited by antp:

Last version of the script:
http://www.antp.be/temp/scripts/IMDB.ifs


See last posts of the topic for more info about last changes.

---------------------

This is the IMDB script that i created (based on ant's default script) for myself and have some extras upon standart IMDB script of AMC. (awards, more comments, more accurate picture grabbing, trivia, writer name, etc.)

I don't test it much it seems to work well. Maybe someone want to use :)

Code: Select all

(***************************************************

Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/

[Infos]
Authors=Antoine Potten (modifications by KaraGarga)
Title=IMDB (Experimental)
Description=Import data & picture from IMDB (optional image from Amazon)
Site=us.imdb.com
Language=EN
Version=1.0
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
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=6|1|0=No image|1=IMDB small image, from the main movie page|2=IMDB large image if found easily, else small image|3=First search for Amazon large image, then IMDB large one, then IMDB small image if other failed|4=First search for Amazon large image, then directly take IMDB small image if the first one failed|5=IMDB large image if found easily, else search for Amazon large image, then take IMDB small image if others failed|6=KG Addition 1: Get Large cover from "DVD details" page.|7=KG Addition 2: Get Large cover from "Merchandising Link" page. (Recommended)
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
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
ActorsLayout=4|0|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=2|0|0=Only take first value for Country|1=Take full list, separated by commas|2=Take full list, separated by slashes
MultipleValuesCategory=2|0|0=Only take first value for Category|1=Take full list, separated by commas|2=Take full list, separated by slashes
MultipleValuesLanguages=2|0|0=Only take first value for Languages|1=Take full list, separated by commas|2=Take full list, separated by slashes
DescriptionSelection=1|1|0=Take the short summary, from main page (faster)|1=Show a list of available summaries|2=Take the longest summary
GetTagline=1|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=1|1|0=Not import trivia|1=Import trivia
AmazonReview=1|1|0=Don't get Amazon Review|1=Get Amazon Review
CommentType=1|1|0=Standart Type (Only one comment from main page)|1=Detailed Type (10 Most useful comments from /comments page)
Awards=1|1|0=NOT import awards|1=Get awards from IMDB

***************************************************)

program IMDB;

uses
  StringUtils1;

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('<title>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('http://us.imdb.com' + 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, 'http://us.imdb.com' + 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: string;
begin
  MovieNumber := TextBetween(PageText, '<input type="hidden" name="arg" value="', '"><input');
  MovieURL := 'http://imdb.com/title/tt' + MovieNumber;
  // URL
  if CanSetField(fieldURL) then
    SetField(fieldURL, MovieURL);
  // Original Title & Year
  if CanSetField(fieldOriginalTitle) or CanSetField(fieldYear) then
  begin
    Value := TextBetween(PageText, '<title>', '</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, ')', '');
    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, '<b>', '/'));
  end;
  // Picture
  if CanSetPicture then
  begin
    case GetOption('ImageKind') of
      1:  ImportSmallPicture(PageText);
      2:  if not ImportLargePicture('http://us.imdb.com/gallery/ss/' + MovieNumber) then
            ImportSmallPicture(PageText);
      3:  if not ImportAmazonPicture(PageText) then
            if not ImportLargePicture('http://us.imdb.com/gallery/ss/' + MovieNumber) then
              ImportSmallPicture(PageText);
      4:  if not ImportAmazonPicture(PageText) then
            ImportSmallPicture(PageText);
      5:  if not ImportLargePicture('http://us.imdb.com/gallery/ss/' + MovieNumber) then
            if not ImportAmazonPicture(PageText) then
              ImportSmallPicture(PageText);
    end;
  end;
  // Director
  if CanSetField(fieldDirector) then
  begin
    Value := TextBetween(PageText, '<b class="blackcatheader">Directed by</b><br>', '<br>' + #13);
    Value := StringReplace(TextAfter(Value, '">'), '<br>', ', ');
    HTMLRemoveTags(Value);
    HTMLDecode(Value);
    SetField(fieldDirector, Value);
  end;
  // Actors
  if CanSetField(fieldActors) then
  begin
    Value := TextBetween(PageText, 'ast overview', '</div>');
    if Value = '' then
      Value := TextBetween(PageText, 'redited cast', '</div>');
    if Value <> '' then
    begin
      Value := TextAfter(Value, '</tr> ');
      FullValue := '';
      case GetOption('ActorsLayout') of
        0, 1:
          while Pos('<tr>', Value) > 0 do
          begin
            Value2 := TextBetween(Value, '<tr>', '</tr>');
            Value := RemainingText;
            if Pos('<a href="fullcredits">(more)</a>', Value2) > 0 then
              Break;
            if FullValue <> '' then
              FullValue := FullValue + #13#10;
            FullValue := FullValue + TextBefore(Value2, '</td>', '');
          end;
        2, 3:
          while Pos('<tr>', Value) > 0 do
          begin
            Value2 := TextBetween(Value, '<tr>', '</tr>');
            Value := RemainingText;
            if Pos('<a href="fullcredits">(more)</a>', Value2) > 0 then
              Break;
            if FullValue <> '' then
              FullValue := FullValue + #13#10;
            FullValue := FullValue + TextBefore(Value2, '</td>', '');
            Value2 := TextBetween(RemainingText, '<td valign="top">', '</td>');
            if Value2 <> '' then
              FullValue := FullValue + ' (as ' + Value2 + ')';
          end;
        4:
          begin
            FullValue := TextBefore(Value, '</tr><tr><td colspan="2">', '');
            if FullValue = '' then
              FullValue := Value;
            FullValue := StringReplace(FullValue, '</tr>', #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;
  //Country
  if CanSetField(fieldCountry) then
  begin
    SetField(fieldCountry, ImportList(PageText, GetOption('MultipleValuesCountry'), '/Countries/'));
  end;
  //Category
  if CanSetField(fieldCategory) then
  begin
    SetField(fieldCategory, ImportList(PageText, GetOption('MultipleValuesCategory'), '/Genres/'));
  end;
  // Language
  if CanSetField(fieldLanguages) then
  begin
    SetField(fieldLanguages, ImportList(PageText, GetOption('MultipleValuesLanguages'), '/Languages/'));
  end;
  //Description
  if CanSetField(fieldDescription) then
  begin
    Value := TextBetween(PageText, '<b class="ch">Plot Outline:</b>', '<br><br>');
    if Value = '' then
      Value := TextBetween(PageText, '<b class="ch">Plot Summary:</b>', '<br><br>');
    if Value <> '' then
      SetField(fieldDescription, ImportSummary(Value));
  end;
  // Comments (Type 0)
  if CanSetField(fieldComments) then
  begin
    Value := TextAfter(PageText, '/comments">');
    if Value <> '' then
    begin
      Value := TextBetween(Value, '<p>', '</p>');
      Value := StringReplace(Value, #13#10, ' ');
      Value := StringReplace(Value, '<br>', #13#10);
      HTMLRemoveTags(Value);
      HTMLDecode(Value);
      Value := Trim(Value);
      while Pos('  ', Value) > 0 do
        Value := StringReplace(Value, '  ', ' ');
      while Pos(#13#10, Value) = 1 do
        Delete(Value, 1, 2);
      SetField(fieldComments, Value);
    end;
  end;
  // Length
  if CanSetField(fieldLength) then
  begin
    Value := TextBetween(PageText, '<b class="ch">Runtime:</b>' + #13#10, ' ');
    if Value <> '' then
    begin
      if Pos(':', Value) > 0 then
        SetField(fieldLength, TextAfter(Value, ':'))
      else
        SetField(fieldLength, Value);
    end;
  end;
// KG Edit
// Writer (Producer Field)
  begin
    Value := TextBetween(PageText, '<b class="blackcatheader">Writing credits</b>', '<br>' + #13#10 + '<br>');
    if Value <> '' then
    begin
      Value := StringReplace(Value, '(<a href="/wga">WGA</a>)', '');
      Value := StringReplace(TextAfter(Value, '">'), '<br>', ', ');
      HTMLRemoveTags(Value);
      HTMLDecode(Value);
      SetField(fieldProducer, Value)
   end;
  end;
// KG Edit
// AKA Name
  begin
    Value := TextBetween(PageText, '<b class="ch">Also Known As:</b><br>', '<br>' + #13#10 + '<b');
    if Value <> '' then
    begin
      Value := StringReplace(Value, ' ', '');
      Value := StringReplace(Value, ' <br>', '/ ');
      HTMLRemoveTags(Value);
      HTMLDecode(Value);
      SetField(fieldTranslatedTitle, Value)
   end;
  end;
//KG Edit
//Trivia
    if GetOption('Trivia') > 0 then
    begin
    Value := TextAfter(PageText, '<a href="trivia">');
    if Value <> '' then
    begin
    sleep(50);
    Value := GetField(fieldURL);
    PageText := GetPage(Value+'/trivia');
    Value := TextBetween(PageText, '<ul class="trivia">', '<div align="center"> <!--');
    Value2 := TextBetween(PageText, '<title>', '</title>');
    Value := StringReplace(Value, #13#10, '');
    Value := StringReplace(Value, '"', '"');
    Value := StringReplace(Value, '  ', '');
    Value := StringReplace(Value, '<li>', #13#10+'- ');
    HTMLRemoveTags(Value);
    HTMLRemoveTags(Value2);
    Value2 := AnsiUpperCase(Value2);
    SetField(fieldDescription, GetField(fieldDescription)+#13#10+#13#10+'IMDB '+Value2+': '+Value);
  end;
end;
//KG Edit
//Image from DVD Details Page
  if (GetOption('ImageKind') = 6) then
  begin
  Value := TextAfter(PageText, '<a href="dvd">DVD details</a>');
  if Value <> '' then
  begin
    Value := GetField(fieldURL);
    PageText := GetPage(Value+'/dvd');
    //Value := TextBetween(PageText, '<td width=80 align="center" valign="center" rowspan="2">', '</a>');
    Value := TextBetween(TextBetween(PageText, 'internetmoviedat">', '></a>'), 'src="', '"');
    //Value2 := TextBetween(Value, '<img src="', '"');
    Value := StringReplace(Value, 'MZZZZZZZ', 'LZZZZZZZ');
    Value := StringReplace(Value, 'TZZZZZZZ', 'LZZZZZZZ');
    Value := StringReplace(Value, '.gif', '.jpg');
    //SetField(fieldTranslatedTitle, Value)
    GetPicture(Value);
  end;
end;
//KG Edit
//Image from Merchandising Links (/sales) Page
  if (GetOption('ImageKind') = 7) then
  begin
  Value := TextAfter(PageText, '<a href="sales">');
  if Value <> '' then
  begin
    Value := GetField(fieldURL);
    PageText := GetPage(Value+'/sales');
    Value := TextBetween(PageText, '<img src="http://images.', '"');
    Value := StringReplace(Value, 'MZZZZZZZ', 'LZZZZZZZ');
    Value := StringReplace(Value, 'TZZZZZZZ', 'LZZZZZZZ');
    Value := StringReplace(Value, '.gif', '.jpg');
    GetPicture('http://images.'+Value);
  end;
end;
//KG Edit
//Amazon.com Description
  if (GetOption('AmazonReview') > 0) then
  begin
  Value := TextAfter(PageText, '<a href="amazon">');
  if Value <> '' then
  begin
    Value := GetField(fieldURL);
    PageText := GetPage(Value+'/amazon');
    Value := TextBetween(PageText, 'Amazon.com video review:', '<div align="center"> <!--');
    Value2 := TextBetween(PageText, '<title>', '</title>');
    Value := StringReplace(Value, #13#10, '');
    Value := StringReplace(Value, '  ', '');
    Value := StringReplace(Value, '<p>', #13#10+'');
    HTMLRemoveTags(Value);
    HTMLRemoveTags(Value2);
    Value2 := AnsiUpperCase(Value2);
    SetField(fieldDescription, GetField(fieldDescription)+#13#10+#13#10+Value2+': '+Value);
  end;
end;
//KG Edit
//Comments (Type 1)
 if (GetOption('CommentType') > 0) then
  begin
  Value := TextAfter(PageText,'<a href="usercomments">');
  if Value <> '' then
  begin
    Value := GetField(fieldURL);
    PageText := GetPage(Value+'/usercomments');
    Value := TextBetween(PageText, '<hr size="1" noshade="1">', '<hr size="1" noshade="1">');
    Value2 := TextBetween(PageText, '<title>', '</title>');
    Value := StringReplace(Value, #13#10, ' ');
    Value := StringReplace(Value, '"', '"');
    Value := StringReplace(Value, '</b>, <small>', #13#10+'Date: ');
    Value := StringReplace(Value, '</small><br>', #13#10);
    Value := StringReplace(Value, '</b>', #13#10);
    Value := StringReplace(Value, '<br><br>', #13#10);
    Value := StringReplace(Value, '<br>', #13#10);
    Value := StringReplace(Value, '<p>', #13#10);
    Value := StringReplace(Value, 'Add another comment', '');
    Value := StringReplace(Value, '  ', '');
    Value := StringReplace(Value, 'Was the above comment useful to you?', #13#10+'___________'+#13#10);
    HTMLRemoveTags(Value);
    HTMLRemoveTags(Value2);
    Value2 := AnsiUpperCase(Value2);
    Value := StringReplace(Value, ' Author:', 'Author:');
    SetField(fieldComments, Value2+':'+#13#10+Value);
  end;
end;
//
//IMDb Awards
  if (GetOption('Awards') = 1) then
  begin
  Value := TextAfter(PageText, '<a href="awards">');
  if Value <> '' then
  begin
    Value := GetField(fieldURL);
    PageText := GetPage(Value+'/awards');
    Value2 := TextBetween(PageText, ' <h1>', '</h1>');
    Value := TextBetween(PageText, '<table cellspacing="2" cellpadding="2" border="1" width="95%">', '<!--');
    Value := StringReplace(Value, '<big>', '- ');
    Value := StringReplace(Value, '<tr><th>Year</th><th>Result</th><th>Award</th><th>Category/Recipient(s)</th></tr>', '');
    HTMLDecode(Value);
    HTMLRemoveTags(Value);
    HTMLRemoveTags(Value2);
    Value2 := AnsiUpperCase(Value2);
    Value := StringReplace(Value, ' '+#13#10, #13#10);
    Value := StringReplace(Value, #13#10+#13#10+#13#10+#13#10, #13#10);
    Value := StringReplace(Value, #13#10+#13#10+#13#10, #13#10);
    Value := StringReplace(Value, #13#10+#13#10, #13#10);
    //Value := StringReplace(Value, #13#10, ' / ');
    FullValue:= Value2+': '+Value;
    SetField(fieldDescription, GetField(fieldDescription)+#13#10+#13#10+Value2+': '+Value);
  end;
  end;
//
// TagLine
  if GetOption('GetTagline') > 0 then
  begin
    Value := TextBetween(PageText, 'Tagline:</b>', #13);
    if Pos('<a', Value) > 0 then
      Value := TextBefore(Value, '<a', '');
    HTMLRemoveTags(Value);
    HTMLDecode(Value);
    Value := Trim(Value);
    if Value <> '' then
    begin
      Value := '"' + Value + '"';
      case GetOption('GetTagline') of
        1:
          if CanSetField(fieldDescription) then
            SetField(fieldDescription, Value + #13#10 + GetField(fieldDescription));
        2:
          if CanSetField(fieldComments) then
            SetField(fieldComments, Value + #13#10 + GetField(fieldComments));
      end;
    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, '">');
  end
  else
  begin
    Value := TextBetween(PageText, StartTag, #13#10);
    Value2 := TextBefore(Value, ' <a href="/rg', '');
    if Value2 <> '' then
      Value := Value2;
    Value2 := TextAfter(Value, '">');
    HTMLRemoveTags(Value2);
    if MultipleValues = 1 then
      Value2 := StringReplace(Value2, ' / ', ', ');
  end;
  HTMLDecode(Value2);
  Result := Value2;
end;

// ***** functions to import the different pictures kinds, depending of the option selected by user *****

function ImportSmallPicture(PageText: string): Boolean;
var
  Value: string;
begin
  Result := False;
  Value := TextBetween(PageText, '<img border="0" alt="cover" src="', '"');
  if Value <> '' then
  begin
    GetPicture(Value);
    Result := True;
  end;
end;

function ImportLargePicture(Address: string): Boolean;
var
  Value, Value2: string;
begin
  Result := True;
  Value := GetPage(Address);
  if SearchForLargePicture(Value, 'Onesheet_text', False) then
    Exit;
  if SearchForLargePicture(Value, 'keyart01', True) then
    Exit;
  if SearchForLargePicture(Value, 'keyart02', True) then
    Exit;
  if SearchForLargePicture(Value, 'oster', True) then // poster, usposter, Poster
    Exit;
  if SearchForLargePicture(Value, 'pos01', True) then
    Exit;
  if SearchForLargePicture(Value, 'KeyArt', True) then
    Exit;
  if SearchForLargePicture(Value, 'heet', True) then // Sheet & Onesheet
    Exit;
  if SearchForLargePicture(Value, 'OneSheetv2', True) then
    Exit;
  if SearchForLargePicture(Value, 'artwork', True) then
    Exit;
  if SearchForLargePicture(Value, 'text', True) then
    Exit;
  Address := TextBetween(Value, 'There are ' + #13#10 + '<a href="', '">');
  if Address <> '' then
    Result := ImportLargePicture('http://us.imdb.com' + Address)
  else
    Result := False;
end;

function SearchForLargePicture(PageText: string; Name: string; PartialName: Boolean): Boolean;
var
  Value: string;
begin
  Result := False;
  if PartialName then
  begin
    Value := TextBefore(PageText, Name + '.jpg', '/');
    if Value = '' then
      Exit
    else
      Name := Value + Name;
  end;
  Value := TextBefore(PageText, 'th-' + Name + '.jpg', 'src="');
  if Value <> '' then
  begin
    GetPicture(Value + Name + '.jpg');
    Result := True;
  end;
end;

function ImportAmazonPicture(PageText: string): Boolean;
var
  Value, Value2: string;
begin
  Result := False;
  Value := TextBefore(PageText, '" title="DVD available', '<a href="');
  if Value = '' then
    Exit;
  PageText := GetPage('http://us.imdb.com' + Value);
  if Pos('unable to find exact matches', PageText) > 0 then
    Exit;
  if Pos('You may also be interested in these items...', PageText) > 0 then
    PageText := TextBefore(PageText, 'You may also be interested in these items...', '');
  Value := TextBefore(PageText, 'TZZZZZZZ.jpg', '<img src="');
  if Value = '' then
    Value := TextBefore(PageText, 'THUMBZZZ.jpg', '<img src="');
  if Value <> '' then
  begin
    GetPicture(Value + 'LZZZZZZZ.jpg');
    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, Value2, PageText, Longest: string;
begin
  Address := TextBetween(PlotText, '<a href="/rg/title-tease/plotsummary', '">(more)</a>');
  if (Address = '') or (GetOption('DescriptionSelection') = 0) then
  begin
    Result := Trim(TextBefore(PlotText, '<a href="/rg', ''));
    if Result = '' then
      Result := Trim(PlotText);
    HTMLRemoveTags(Result);
    HTMLDecode(Result);
  end
  else
  begin
    PageText := GetPage('http://us.imdb.com/rg/title-tease/plotsummary' + Address);
    PickListClear;
    Longest := '';
    Value := TextBetween(PageText, '<p class="plotpar">', '</p>');
    PageText := RemainingText;
    while Value <> '' do
    begin
      Value := 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(Trim(Value));
      Value := TextBetween(PageText, '<p class="plotpar">', '</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;

// ***** beginning of the program *****

begin
  if CheckVersion(3,5,0) then
  begin
    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
        AnalyzeResultsPage(MovieName)
      else
      begin
        MovieName := StringReplace(MovieName, '&', 'and');
        if (GetOption('BatchMode') > 0) or (GetOption('PopularSearches') = 1) then
          AnalyzeResultsPage('http://us.imdb.com/find?tt=1;q=' + UrlEncode(MovieName))
        else
          AnalyzeResultsPage('http://us.imdb.com/find?more=tt;q=' + UrlEncode(MovieName));
      end;
    end;
  end
  else
    ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.0)');
end.

Posted: 2005-03-22 10:12:30
by antp
I'll check that and probably include that (or most of that) as official script after having cleaned a little the image options ;)

Posted: 2005-03-23 23:13:54
by zile
Nice script!
Just found something to correct.
ex: movie is 8 mile.
In translated field, there is no spaces between words. And if it is possible to remove "(working title) " phrase.
Thanks.

Posted: 2005-03-28 15:12:37
by KaraGarga
Hi,

It's not a bug actually. In 8 mile for example Transletd Title like this:
8 Mile (Germany)/ Fight Music (USA)(working title)/ Fight Song (USA)(working title)/ Untitled Detroit Project (USA)(working title)
It's enough for me to get this info like this way.

If you want a space after ")" you can do this:

Find:

Code: Select all

// AKA Name
  begin
    Value := TextBetween(PageText, '<b class="ch">Also Known As:</b><br>', '<br>' + #13#10 + '<b');
    if Value <> '' then
    begin
      Value := StringReplace(Value, ' ', '');
      Value := StringReplace(Value, ' <br>', '/ ');
      HTMLRemoveTags(Value);
      HTMLDecode(Value);
      SetField(fieldTranslatedTitle, Value)
   end;
  end; 
replace with

Code: Select all

// AKA Name
  begin
    Value := TextBetween(PageText, '<b class="ch">Also Known As:</b><br>', '<br>' + #13#10 + '<b');
    if Value <> '' then
    begin
      Value := StringReplace(Value, ' ', '');
      Value := StringReplace(Value, ' <br>', '/ ');
      Value := StringReplace(Value, ')', ') ');
      HTMLRemoveTags(Value);
      HTMLDecode(Value);
      SetField(fieldTranslatedTitle, Value)
   end;
  end; 

If you want to remove "(working title) " phrase you can add a code that removes it, like this.

Before

Code: Select all

HTMLRemoveTags(Value);
line
you can add

Code: Select all

Value := StringReplace(Value, '(working title)', '');
or any phrase you want to remove.

Posted: 2005-03-28 18:56:21
by Guest
I did what you tell, but i got the following result in translated title:

8Mile(Germany) FightMusic(USA) (workingtitle) FightSong(USA) (workingtitle) UntitledDetroitProject(USA) (workingtitle)

It would be nice if I can get the following:

8 Mile (Germany), Fight Music (USA), Fight Song (USA), Untitled Detroit Project (USA)

Tnx.

Posted: 2005-04-12 06:42:10
by KaraGarga
Well then. I just try this one and it give the result you desired for AKA Titles.

Find

Code: Select all

 Value := StringReplace(Value, ' <br>', '/ ');
      HTMLRemoveTags(Value);
      HTMLDecode(Value);
      SetField(fieldTranslatedTitle, Value)
   end;
  end;
in the above original script and replace with

Code: Select all

 Value := StringReplace(Value, ' <br>', ', ');
      Value := StringReplace(Value, '(working title)', '');
      HTMLRemoveTags(Value);
      HTMLDecode(Value);
      SetField(fieldTranslatedTitle, Value)
   end;
  end;
This line removes (Working title) phrase:

Code: Select all

Value := StringReplace(Value, '(working title)', '');
if you want to remove another phrase just add above this line like this:
Value := StringReplace(Value, 'Desired Omitted Phrase', '');

Hope this one helps :D

Posted: 2005-04-12 11:24:43
by Guest
// KG Edit
// AKA Name
begin
Value := TextBetween(PageText, '<b class="ch">Also Known As:</b><br>', '<br>' + #13#10 + '<b');
if Value <> '' then
begin
Value := StringReplace(Value, ' <br>', ', ');
Value := StringReplace(Value, '(working title)', '');
Value := StringReplace(Value, '(complete title)', '');
Value := StringReplace(Value, '(alternative spelling)', '');
HTMLRemoveTags(Value);
HTMLDecode(Value);
SetField(fieldTranslatedTitle, Value)
end;
end;

Well, thanks for replay. I modified by your instruction and I got the following result:

8 Mile (Germany) , Fight Music (USA) , Fight Song (USA) , Untitled Detroit Project (USA)

What Im looking know is how to get:
8 Mile (Germany), Fight Music (USA), Fight Song (USA), Untitled Detroit Project (USA) (you see where comma is) :)

I found that importing Tagline is not working.

Also, another possible options would be cool. To be able to select where Trivia, awards, amazon review could be imported. (Im aiming to comments field, since default is description field). Just like value for option "GetTagline".

Thanks again KaraGarga.

Posted: 2005-04-12 11:48:59
by Guest

Code: Select all

// KG Edit 
// AKA Name
  begin
    Value := TextBetween(PageText, '<b class="ch">Also Known As:</b><br>', '<br>' + #13#10 + '<b');
    if Value <> '' then
    begin
      Value := StringReplace(Value, ' <br>', ', ');
      Value := StringReplace(Value, '(working title)', '');
      Value := StringReplace(Value, '(complete title)', '');
      Value := StringReplace(Value, '(alternative title)', '');
      Value := StringReplace(Value, '(alternative spelling)', '');
      HTMLRemoveTags(Value);
      HTMLDecode(Value);
      SetField(fieldTranslatedTitle, Value)
   end;
  end;
Well, thanks for replay. I modified by your instruction and I got the following result:

8 Mile (Germany) , Fight Music (USA) , Fight Song (USA) , Untitled Detroit Project (USA)

What Im looking know is how to get:
8 Mile (Germany), Fight Music (USA), Fight Song (USA), Untitled Detroit Project (USA) (you see where comma is)

I found that importing Tagline is not working.

Also, another possible options would be cool. To be able to select where Trivia, awards, amazon review could be imported. (Im aiming to comments field, since default is description field). Just like value for option "GetTagline".

Thanks again KaraGarga.

PS: Forgot to login. Moderator plz delete previous post.

Posted: 2005-04-14 10:20:22
by kolia
Thanks KaraGarga, I'll try it out myself and make the appropriate adjustments :)

P.S.
come on zile, it's not so difficult, try to change something yourself and see how it works :/

like, maybe if you added a

Code: Select all

Value := StringReplace(Value, ' , ', ', ');
after the

Code: Select all

Value := StringReplace(Value, ' <br>', ', ');
line...

experiment a little yourself and you'll be able to do a lot more, a lot quicker ;)

Posted: 2005-04-14 12:54:18
by Guest
P.S.
come on zile, it's not so difficult, try to change something yourself and see how it works

like, maybe if you added a
Code:
Value := StringReplace(Value, ' , ', ', ');

after the
Code:
Value := StringReplace(Value, ' <br>', ', ');

line...

experiment a little yourself and you'll be able to do a lot more, a lot quicker
Thanks for replay. But did you actually try before you post the "solution" ;)

I was trying to experiment but since it doesnt work out, I posted here. Im curious about that comma...
PS: Your suggestion doesnt work either. :cry:

Posted: 2005-04-17 18:18:57
by Peter
Hello

your seems doesn't seem to work right, i did a copy-paste and when i try to extract info from imdb i've got this error message :

"synthor error a the line 14" , that means this line

Code: Select all

ImageKind=6|1|0=No image|1=IMDB small image, from the main movie page|2=IMDB large image if found easily, else small image|3=First search for Amazon large image, then IMDB large one, then IMDB small image if other failed|4=First search for Amazon large image, then directly take IMDB small image if the first one failed|5=IMDB large image if found easily, else search for Amazon large image, then take IMDB small image if others failed|6=KG Addition 1: Get Large cover from "DVD details" page.|7=KG Addition 2: Get Large cover from "Merchandising Link" page. (Recommended)
did i do something wrong? thanx by advance

Posted: 2005-04-17 21:29:10
by antp
You have to paste it using notepad (or any text editor) to a .ifs file in AMC's script folder.
If you do it within AMC's script editor the settings part of the script will be duplicated with the current script's settings (it not clear what I try to say :D)

Posted: 2005-04-18 17:58:45
by Peter
thanx, it works perfectly now :cool:

Posted: 2005-04-20 08:25:17
by Sanaa
uses
StringUtils1;
"unknown identyfier"

Posted: 2005-04-20 11:33:59
by scorpion7552
never delete stuffs in the script directory, especially these xxx.pas (as StingUtils1.pas): they contain functions and procedures common to lot of scripts...

CU

Posted: 2005-04-20 11:35:49
by antp
This may also happen if you still have version 3.4.x of AMC :D

Missing Images

Posted: 2005-04-28 00:45:46
by Mong0
Just curious why certain films do not have an image url when using ImageKind 7. Example would be Van Helsing.

Thanks for the excellent script and program.

Posted: 2005-05-05 12:11:05
by antp
I modified a little the above script to make KaraGarga's changes more "integrated" in IMDB "official" script.
It would be nice if people could test it and report bugs, since it will be included with next update of AMC:
www.antp.be/temp/scripts/IMDB.ifs

Posted: 2005-05-08 03:01:06
by TiaoMacaleh
I found two problems.... it list the actors with character name which wont work very well on templated that you can browse by actor dont it?

And where the awards go?

Posted: 2005-05-08 10:57:19
by antp
What's the problem with the actors? If you only want actors name there is an option that you can change (double-click on ActorsLayout item in options list)

Awards go to the Description field.