Page 1 of 1

Script fot imdb Certification?

Posted: 2003-02-05 18:16:45
by Mguel
Hi has anyone done a script to get the certification of a movie? I've tried but can't make it work. It would be an easy and fast way to know if a certain movie is apropiate or not for a kid.

I think it could be added to an unoccupied field such as Media Label or Producer, and it could fetch the USA Certification on imdb, since its more global.

Thanks in advance,
Mguel

Posted: 2003-02-05 19:35:18
by Guest
Finally I managed to make it :D

Code: Select all

    //Certificates
  LineNr := FindLine('Certification:', Page, 0);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr + 1);
    BeginPos := pos(';USA:', Line) + 5;
    EndPos := pos('">USA:', Line);
    Value := copy(Line, BeginPos, EndPos - BeginPos);
    HTMLDecode(Value);
    SetField(fieldBorrower, Value);
  end;
Add it on you imdb script. I added the Certification on Borrowers file.

Mguel

Posted: 2003-02-05 19:36:40
by Mguel
Anonymous wrote:Finally I managed to make it :D

Code: Select all

    //Certificates
  LineNr := FindLine('Certification:', Page, 0);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr + 1);
    BeginPos := pos(';USA:', Line) + 5;
    EndPos := pos('">USA:', Line);
    Value := copy(Line, BeginPos, EndPos - BeginPos);
    HTMLDecode(Value);
    SetField(fieldBorrower, Value);
  end;
Add it on you imdb script. I added the Certification on Borrowers file.

Mguel
Ups, forgot to sign in.
Mguel

Posted: 2003-02-05 19:49:36
by antp
I think that I'll add that to the comments field ;)

Posted: 2003-02-05 20:56:18
by Mguel
antp wrote:I think that I'll add that to the comments field ;)
Yep that would be the best, but I didn't add it there because of two reasons:

1.- I don't know programing nor scripting... I made this one based on other fields without much real knowledge of what I was doing :??: so I don't figure how to add it to comments without actually replacing the comments, and

2.- I wanted to be able to export it (html) on a single field next to title/director/actors...

Any way, here is the complete script for adding only the certification to the movies on a catalog (on the borrowers field), in case is usefull for someone ;)

Code: Select all

// GETINFO SCRIPTING
// IMDB (US) import USA Certification (on borrowers field)

(***************************************************
 *  Movie importation script for:                  *
 *      IMDB (US), http://us.imdb.com              *
 *                                                 *
 *  (c) 2002 Antoine Potten    antoine@buypin.com  *
 *  Improvements made by Danny Falkov              *
 *  Improvements made by Kai Blankenhorn           *
 *                                                 *
 *  For use with Ant Movie Catalog 3.4.0           *
 *  www.ant.be.tf/moviecatalog ยทยทยท www.buypin.com  *
 *                                                 *
 *  The source code of the script can be used in   *
 *  another program only if full credits to        *
 *  script author and a link to Ant Movie Catalog  *
 *  website are given in the About box or in       *
 *  the documentation of the program               *
 ***************************************************)

program IMDb;
var
  MovieName: 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;
  LineNr: Integer;
begin
  Page := TStringList.Create;
  Page.Text := GetPage(Address);
  if pos('<TITLE>IMDb', Page.Text) = 0 then
  begin
    SetField(fieldURL, Address);
    AnalyzeMoviePage(Page)
  end else
  begin
    PickTreeClear;
    LineNr := 0;
    LineNr := FindLine('<H2><A NAME="top">Most popular searches</A></H2>', Page, LineNr);
    if LineNr > -1 then
    begin
      PickTreeAdd('Most popular searches', '');
      AddMoviesTitles(Page, LineNr);
    end;
    LineNr := FindLine('<H2><A NAME="mov">Movies</A></H2>', Page, LineNr);
    if LineNr > -1 then
    begin
      PickTreeAdd('Movies', '');
      AddMoviesTitles(Page, LineNr);
    end;
    LineNr := FindLine('<H2><A NAME="tvm">TV-Movies</A></H2>', Page, LineNr);
    if LineNr > -1 then
    begin
      PickTreeAdd('TV-Movies', '');
      AddMoviesTitles(Page, LineNr);
    end;
    LineNr := FindLine('<H2><A NAME="tvs">TV series</A></H2>', Page, LineNr);
    if LineNr > -1 then
    begin
      PickTreeAdd('TV Series', '');
      AddMoviesTitles(Page, LineNr);
    end;
    LineNr := FindLine('<H2><A NAME="vid">Made for video</A></H2>', Page, LineNr);
    if LineNr > -1 then
    begin
      PickTreeAdd('Made for video', '');
      AddMoviesTitles(Page, LineNr);
    end;
    if PickTreeExec(Address) then
      AnalyzePage(Address);
  end;
  Page.Free;
end;

procedure AnalyzeMoviePage(Page: TStringList);
var
  Line, Value, Value2, FullValue: string;
  LineNr: Integer;
  BeginPos, EndPos: Integer;
begin

    //Certification
  LineNr := FindLine('Certification:', Page, 0);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr + 1);
    BeginPos := pos(';USA:', Line) + 5;
    EndPos := pos('">USA:', Line);
    Value := copy(Line, BeginPos, EndPos - BeginPos);
    HTMLDecode(Value);
    SetField(fieldBorrower, Value);
  end;


  DisplayResults;
end;

procedure GetDescriptions(Address: string);
var
  Line, Value: string;
  LineNr: Integer;
  BeginPos, EndPos: Integer;
  Page: TStringList;
begin
  Page := TStringList.Create;
  Page.Text := GetPage('http://us.imdb.com' + Address);
  LineNr := FindLine('<p class="plotpar">', Page, 0);
  while LineNr > -1 do
  begin
    Value := '';
    repeat
      Line := Page.GetString(LineNr);
      BeginPos := pos('"plotpar">', Line);
      if BeginPos > 0 then
        BeginPos := BeginPos + 10
      else
        BeginPos := 1;
      EndPos := pos('</p>', Line);
      if EndPos < 1 then
        EndPos := Length(Line) + 1;
      if Value <> '' then
        Value := Value + ' ';
      Value := Value + copy(Line, BeginPos, EndPos - BeginPos);
      LineNr := LineNr + 1;
    until (pos('</p>', Line) > 0) or (LineNr = Page.Count);
    PickListAdd(Value);
    LineNr := FindLine('<p class="plotpar">', Page, LineNr);
  end;
  Page.Free;
end;

procedure AddMoviesTitles(Page: TStringList; var LineNr: Integer);
var
  Line: string;
  MovieTitle, MovieAddress: string;
  StartPos: Integer;
begin
  repeat
    LineNr := LineNr + 1;
    Line := Page.GetString(LineNr);
    StartPos := pos('="', Line);
    if StartPos > 0 then
    begin
      Startpos := Startpos + 2;
      MovieAddress := copy(Line, StartPos, pos('">', Line) - StartPos);
      StartPos := pos('">', Line) + 2;
      MovieTitle := copy(Line, StartPos, pos('</A>', Line) - StartPos);
      HTMLDecode(Movietitle);
      PickTreeAdd(MovieTitle, 'http://us.imdb.com' + MovieAddress);
    end;
  until pos('</OL>', Line) > 0;
end;

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

Posted: 2003-02-06 22:49:34
by Guest
...me again, here is the script for adding the MPAA description/explanation of the rating of certain movie i.e.:

Rated PG-13 for intense sci-fi action.
or:
Rated R for strong violence/gore, language and some drug content.

Code: Select all

    //MPAA Rating
  LineNr := FindLine('href="/mpaa"', Page, 0);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr);
    BeginPos := pos('MPAA</a>:', Line) + 14;
    EndPos := pos('<br>', Line);
    Value := copy(Line, BeginPos, EndPos - BeginPos);
    HTMLDecode(Value);
    SetField(fieldProducer, Value);
  end;
Note: This is added on the Producers field :/

Mguel

Posted: 2003-02-06 22:52:40
by Mguel
Logged out again :hum:

Posted: 2003-02-07 08:25:13
by antp
Yes phpbb forum seems to forget the login quite often, even if it seems well configured :/

If you want to add info to a field, e.g. comments field, you can do this :

SetField(fieldComments, Value + #13#10 + GetField(fieldComments));

here it adds the contents of Value, followed by a linebreak, then the old contents of the Comments field.

Posted: 2003-02-07 12:08:15
by Mguel
ok, thanks ;)