Page 1 of 1

modified AMC version and full rating imdb update script

Posted: 2004-06-02 08:13:04
by kolia
Some days ago I asked Antoine to re-compile AMC so that the Rating field goes from 0-100 instead of 0-10.
well, he was kind enough to do it! However, before reading any further you have to note that
there are no guaranties that it will work for you, since I am the only one that has tested it so far (worked fine for me)
Consider this to be a temporary solution, until the next version comes out.
(I quote antp:)"in next version (if I continue on 3.x, see here) I will add an option to specify if it is 10 or 100, and the script should not be modified : depending if it is 10 or 100 the program should know if it has to divide or not the rating
Same for importation."

So, for those of you who want to have the full 2 digit IMDB rating, you can find the modified exe here
so that you can:
-keep the x.y imdb rating format as xy (i.e. 73/100 for 7.3/10)
-sort by (full) rating
-keep the small size of amc catalogs (rating is still an integer)


all that you have to do then is
1) in the imdb script you're using
  • find the "// Rating" block and
    replace "Value := IntToStr(Round(StrToInt(StrGet(Line, BeginPos), 0) + (StrToInt(StrGet(Line, BeginPos + 2), 0) / 10)));"
    with "Value := StrGet(Line, BeginPos) + StrGet(Line, BeginPos + 2);"
2) run the script below to 'fix' your current catalog

Code: Select all

// GETINFO SCRIPTING
// to replace rating with 2digit rating (uses imdb URL if found) - kolia

program IMDb_replace_rating;

var
  MovieName: string;
  MovieURL: string;

function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
var
  i: Integer;
begin
  Result := -1;
  if StartAt < 0 then
    StartAt := 0;
  for i := StartAt to List.Count-1 do
    if Pos(Pattern, List.GetString(i)) <> 0 then
    begin
      Result := i;
      Break;
    end;
end;

procedure AnalyzePage(Address: string);
var
  Page: TStringList;
begin
  Page := TStringList.Create;
  Page.Text := GetPage(Address);
  if pos('<title>IMDb', Page.Text) = 0 then
  begin
    AnalyzeMoviePage(Page)
  end else
  begin
    PickTreeClear;
    AddMoviesTitles(Page, '<b>Exact Matches</b>');
    AddMoviesTitles(Page, '<b>Partial Matches</b>');
    AddMoviesTitles(Page, '<b>Approximate Matches</b>');
    if PickTreeExec(Address) then
      AnalyzePage(Address);
  end;
  Page.Free;
end;

function FindValue(BeginTag, EndTag: string; Page: TStringList; var LineNr: Integer; var Line: string): string;
var
  BeginPos, EndPos: Integer;
  Value: string;
begin
  Result := '';
  Value := '';
  BeginPos := Pos(BeginTag, Line);
  if BeginPos > 0 then
  begin
    BeginPos := BeginPos + Length(BeginTag);
    if BeginTag = EndTag then
    begin
      Delete(Line,1,BeginPos-1);
      BeginPos := 1;
    end;
    EndPos := pos(EndTag, Line);
    while ((EndPos = 0) and (LineNr < Page.Count-1 )) do
    begin
      Value := Value + copy(Line, BeginPos, Length(Line) - BeginPos);
      // Next Line
      BeginPos := 1;
      LineNr := LineNr + 1;
      Line := Page.GetString(LineNr);
      if Value = '' then
        Exit;
      EndPos := Pos(EndTag, Line);
    end;
    Value := Value + copy(Line, BeginPos, EndPos - BeginPos);
   end;
  Result := Value;
end;

procedure AnalyzeMoviePage(Page: TStringList);
var
  Line, Value, Value2, FullValue: string;
  LineNr, BeginPos, EndPos, DescrImport: Integer;
  AllTitles: TStringList;
begin
  MovieURL := 'http://imdb.com/title/tt' + copy(Page.Text, pos('<a href="/title/tt',Page.Text)+19, 7);

  // Rating
  LineNr := FindLine('User Rating:', Page, 0);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr + 4);
    if Pos('/10', Line) > 0 then
    begin
      BeginPos := pos('<b>', Line) + 3;
      Value := StrGet(Line, BeginPos) + StrGet(Line, BeginPos + 2);
      SetField(fieldRating, Value);
    end;
  end;

  DisplayResults;
end;



procedure AddMoviesTitles(Page: TStringList; Tag: string);
var
  Line: string;
  LineNr: Integer;
  MovieTitle, MovieAddress: string;
  StartPos: Integer;
begin
  LineNr := FindLine(tag, Page, 0);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr);
    HTMLRemoveTags(Line);
    PickTreeAdd(Trim(Line), '');
    LineNr := LineNr + 5;
    Line := Page.GetString(LineNr);
    repeat
      StartPos := pos('href="', Line) + 5;
      Delete(Line, 1, StartPos);
      MovieAddress := Copy(Line, 1, pos('">', Line) - 1);
      StartPos := Pos('">', Line) + 2;
      MovieTitle := Copy(Line, StartPos, Pos('</a>', Line) - StartPos);
      HTMLDecode(Movietitle);
      PickTreeAdd(MovieTitle, 'http://us.imdb.com' + MovieAddress);
      LineNr := LineNr + 2;
      Line := Page.GetString(LineNr);
    until Pos('</table>', Line) > 0;
  end;
end;

begin
if CheckVersion(3,4,0) then
begin
  if Pos('imdb',GetField(fieldURL)) = 0 then
  begin
    MovieName := GetField(fieldOriginalTitle);
    if MovieName = '' then
     MovieName := GetField(fieldTranslatedTitle);
    if MovieName = '' then
     MovieName := Input('IMDb Import', 'Enter the title of the movie:', MovieName);
    if MovieName <> '' then
    begin
     AnalyzePage('http://us.imdb.com/Tsearch?title='+UrlEncode(MovieName));
    end;
  end
  else
  begin
    AnalyzePage(GetField(fieldURL));
  end;
end else
  ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.0)');
end.