[NL] Moviemeter update

If you made a script you can offer it to the others here, or ask help to improve it. You can also report here bugs & problems with existing scripts.
Post Reply
rolandb5

[NL] Moviemeter update

Post by rolandb5 »

The original title stopped working as well as the alternative titel.
Fixed that and also corrected the rating procedure.
rolandb5

Post by rolandb5 »

left a testing variable in the code, this is the correct code


edit: new version bellow
antp
Site Admin
Posts: 9651
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

Hi,

Thanks ;)
I added the [code] ... [/code] tags so the script keeps its formatting (spaces in front of the lines)
Guest

Post by Guest »

Roland, bedankt man... (JoopBraakhekke)
CyMo

Post by CyMo »

One more other thing besides the title ...... it doesn't show the duration (duur) of the movie any longer :??:
rolandb5

Post by rolandb5 »

Code: Select all

// GETINFO SCRIPTING
// MovieMeter.nl import script

(***************************************************
 *  Movie importation script for:                  *
 *      MovieMeter (NL), http://MovieMeter.nl/     *
 *                                                 *
 *  Now works with the new site !!                 *
 *                                                 *
 *  Written by JanC <amc-script@janc.cjb.net>      *
 *  (partially based on other import scripts)      *
 *   corrections by rolandb5@hotmail.com           *                                  *
 *  For use with Ant Movie Catalog                 *
 *  http://antp.be/software/moviecatalog           *
 *                                                 *
 ***************************************************)


program MovieMeter;

var
  MovieName: string;


procedure AnalyzeMoviePage(Address: string);
var
  Page: TStringList;
  Line, Value: string;
  LineNr: Integer;
  I: Integer;
  BeginPos, EndPos: Integer;
begin
  // get movie page
  Page := TStringList.Create;
  Page.Text := GetPage(Address);

  // get URL
  SetField(fieldURL, Address);

  // find line with titles & year
  LineNr := 0;
  repeat
    LineNr := LineNr + 1;
    Line := Page.GetString(LineNr);
  until Pos('<p class="kop">', Line) > 0;
  // get original(?) title
  BeginPos := Pos('<p class="kop">', Line);
  Delete(Line, 1, BeginPos-1);
  BeginPos := Pos('<p class="kop">', Line) + Length('<p class="kop">');
   EndPos := Pos('(', Line) - Length(' ');
  Value := Copy(Line, BeginPos, EndPos - BeginPos);
  HTMLDecode(Value);
  SetField(fieldOriginalTitle, Value);
  Delete(Line, 1, EndPos);

  // get year
  BeginPos := Pos('(', Line) + Length('(');
  EndPos := pos(')', Line);
  Value := Copy(Line, BeginPos, EndPos - BeginPos);
  HTMLDecode(Value);
  SetField(fieldYear, Value);

  // get first alternative title???
  LineNr := LineNr + 1;
  Line := Page.GetString(LineNr);
  BeginPos := Pos('Alternatieve titel:', Line) + Length('    Alternatieve titel:');
    if BeginPos > 0 then begin
    EndPos := pos('</b>', Line);
    Value := Copy(Line, BeginPos, EndPos - BeginPos);
    HTMLDecode(Value);
    SetField(fieldTranslatedTitle, Value);
  end;

  // find line with country, cat & length
  repeat
    LineNr := LineNr + 1;
    Line := Page.GetString(LineNr);
  until Pos('geregisseerd door', Line) > 0;
  // get country
  BeginPos := 1;
  EndPos := Pos('<br>', Line);
  Value := StringReplace(Copy(Line, BeginPos, EndPos - BeginPos), #9, '');
  HTMLDecode(Value);
  SetField(fieldCountry, Value);
  Delete(Line, 1, EndPos + Length('<br>') - 1);
  // get category
  BeginPos := 1;
  EndPos := Pos('<br>', Line);
  Value := Copy(Line, BeginPos, EndPos - BeginPos);
  HTMLDecode(Value);
  SetField(fieldCategory, Value);
  Delete(Line, 1, EndPos + Length('<br>') - 1);
  // get length
  BeginPos := 1;
  EndPos := Pos(' minuten <br>', Line);
  Value := Copy(Line, BeginPos, EndPos - BeginPos);
  HTMLDecode(Value);
  SetField(fieldLength, Value);

  // find line with director & actors
  repeat
    LineNr := LineNr + 1;
    Line := Page.GetString(LineNr);
  until Pos('<a href="?regisseur=', Line) > 0;
  // get director
  BeginPos := Pos('">', Line) + Length('">');
  EndPos := Pos('</a>', Line);
  Value := Copy(Line, BeginPos, EndPos - BeginPos);
  HTMLDecode(Value);
  SetField(fieldDirector, Value);
  Delete(Line, 1, EndPos-1);
  // get actors
  BeginPos := Pos('<br>met ', Line) + Length('<br>met ');
  EndPos := Pos('</p><p>', Line);
  Value := StringReplace(Copy(Line, BeginPos, EndPos - BeginPos), #9, '');
  HTMLDecode(Value);
  SetField(fieldActors, Trim(Value));

  Value := '';
  repeat
    // get line with description

    LineNr := LineNr + 1;
    Line := Page.GetString(LineNr);
    if Pos('</p>', Line) = 0 then begin
    Value := Value + Line;
    end;
    // get description

    if Pos('</p>', Line) > 0 then begin
      BeginPos := 1;
      EndPos := Pos('</p>', Line);
      Value := Value + Copy(Line, BeginPos, EndPos - BeginPos);

    end;
    HTMLDecode(Value);

  until Pos('</p>', Line) > 0;
  Value := StringReplace(Value, #9, '');
  SetField(fieldDescription, Value);
  // find line with cover picture
  repeat
    LineNr := LineNr + 1;
    Line := Page.GetString(LineNr);
  until Pos('<img src="images/covers/', Line) > 0;
  // get cover picture
  BeginPos := Pos('<img src="', Line) + Length('<img src="');
  EndPos := Pos('" ', Line);
  Value := Copy(Line, BeginPos, EndPos - BeginPos);
  GetPicture('http://www.moviemeter.nl/' + Value, False);

  // find line with rating
  repeat
    LineNr := LineNr + 1;
    Line := Page.GetString(LineNr);
  until Pos('<td class="stembody">', Line) > 0;
  LineNr := LineNr + 1;
  Line := Page.GetString(LineNr);
  // get average rating (range 0.00-5.00 on the site, range 0-10 in AMC)
  BeginPos := Pos('<br>', Line) + Length('<br>');
  EndPos := Pos(' gemiddeld', Line);
  Value := Copy(Line, BeginPos, EndPos - BeginPos);
  I := StrToInt(Copy(Value, 1, 1), 0) * 100 + StrToInt(Copy(Value, 3, 2), 0);
  Value := IntToStr(Round(I/50));
  SetField(fieldRating, Value);

  DisplayResults;
  Page.Free;
end;


procedure AnalyzeResultsPage(Address: string);
var
  Page: TStringList;
  Line: string;
  MovieAddress: string;
  LineNr: Integer;
  MovieTitle: string;
  StartPos, EndPos: Integer;
begin
  // get results page
  Page := TStringList.Create;
  Page.Text := GetPage(Address);

  // get redirect javascript
  Line := Page.GetString(Page.Count-1);
  
  // if only 1 movie found --> redirect to movie page
  if Pos('location.replace("?film=', Line) <> 0 then begin
    StartPos := Pos('?film=', Line);
    EndPos := Pos('");</script>', Line);
    MovieAddress := 'http://moviemeter.nl/' + Copy(Line, StartPos, EndPos - StartPos);
    AnalyzeMoviePage(MovieAddress);
  end
  // more than 1 movie found
  else if Pos('location.href = "?searchresults"', Line) <> 0 then begin
    PickTreeClear;

    // get results page
    Page.Text := GetPage('?searchresults');

    // find line with results
    LineNr := 0;
    repeat
      LineNr := LineNr + 1;
      Line := Page.GetString(LineNr);
    until Pos('<!--m-->', Line) > 0;
  
    // find individual results delimited by <!--m--> & <!--n-->'
    StartPos := Pos('<!--m-->', Line);
    while StartPos > 0 do begin
      Delete(Line, 1, StartPos-1);
      StartPos := Pos('<!--m-->', Line) + Length('<!--m--><a href="');
      EndPos := Pos('">', Line);
      MovieAddress := Copy(Line, StartPos, EndPos - StartPos);
      
      StartPos := Pos('">', Line) + Length('"><b>');
      EndPos := Pos('<br>', Line);
      MovieTitle := Copy(Line, StartPos, EndPos - StartPos);
      HTMLRemoveTags(MovieTitle);
      HTMLDecode(Movietitle);
      
      PickTreeAdd(MovieTitle, 'http://www.moviemeter.nl/' + MovieAddress);
      
      Delete(Line, 1, EndPos-1);
      StartPos := Pos('<!--m-->', Line);
    end;

    // if user picks a movie from the results list, import movie details
    if PickTreeExec(Address) then
      AnalyzeMoviePage(Address);
  end
  // no movies found
  else begin
    ShowMessage('Geen zoekresultaat voor "'+MovieName+'".');
  end;

  Page.Free;
end;


begin
  if CheckVersion(3,4,0) then     // is this really the minimum version?
  begin
    MovieName := GetField(fieldOriginalTitle);
    if MovieName = '' then
      MovieName := GetField(fieldTranslatedTitle);
    if Input('MovieMeter.nl Import', 'Geef de titel van de film:', MovieName) then
    begin
      AnalyzeResultsPage('http://moviemeter.nl/?search&q='+UrlEncode(MovieName));
    end;
  end else
    ShowMessage('Dit script vereist een nieuwere versie van Ant Movie Catalog (minstens versie 3.4.0)');
end.
rolandb5

Post by rolandb5 »

Sorry, Antp, ruined your layout again. Forget a ].

This must solve all problems.
antp
Site Admin
Posts: 9651
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

no problem, I edited your message to add the missing "]" ;)
Thanks for the script update
CyMo

Post by CyMo »

Works like a charm again :grinking:

Thanks for the quick update and for the beautiful script
It safes so much time
Guest

Post by Guest »

It doesn't work for me. Whatever title I try to add, it keeps saying 'no search results'. What am I doing wrong?
rolandb5

Post by rolandb5 »

Don;t know, still works here as a charm. Maybe you didn;t copy-paste the script correct?
Guest

Post by Guest »

Hmmm, I switched off my firewall, and now it's working like a charm indeed! That's very strange, because other scripts like IMDB and Amazon are working OK with the firewall on!
Post Reply