Page 1 of 2

MovieMeter (NL) : Script adaptation to get the poster

Posted: 2011-11-17 13:14:47
by umac6
Hello, i could not find the way to upload scripts so i'll pass it onto the forum :

MovieMeter has change their image tag so you need to change the search for the poster to : img itemprop="image"

Full working script :

Code: Select all

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

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

[Infos]
Authors=Antoine Potten
Title=MovieMeter.nl
Description=MovieMeter.nl import script
Site=www.moviemeter.nl
Language=NL
Version=2.7.7
Requires=3.5.0
Comments=Fixed by tsjarlie / Miss_Kitty (v 2.7.3)|Fixed by Kaas (v 2.7.1)|Updated/Fixed by bad4u (v 2.7)|Previous version made by JanC and corrections by <link>rolandb5@hotmail.com</link>, rewritten by Antoine Potten after a site change (v 2.0)
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]
AllCountries=0|0|0=Take only first country|1=Take all countries (separated by "/")
ImportComments=0|0|0=Do not import users' comments|1=Import users' comments

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

program MovieMeter;

uses
  StringUtils1;

var
  MovieName: string;

procedure AnalyzeMoviePage(Address: string);
var
  PageText, Line, Value: string;
begin
  PageText := GetPage(Address);

  // URL
  SetField(fieldURL, Address);

  // title & year
  Line := TextBetween(PageText, '<h1>', '</h1>');
  Value := TextBetween(Line, '(', ')');
  SetField(fieldYear, Value);
  Value := Trim(TextBefore(Line, '(', ''));
  HTMLDecode(Value);
  SetField(fieldOriginalTitle, Value);

  // translated title
  Line := TextBetween(PageText, 'Alternatieve titel', ' </p>');
  if Line <> '' then
  begin
    Line := TextAfter(Line, ': ');
    if Line <> '' then
    begin
      HTMLDecode(Line);
      SetField(fieldTranslatedTitle, Line);
    end;
  end;

  Value := TextBetween(PageText, '<div id="film_info"', '<br />');
  Line := RemainingText;
  Value := TextAfter(Value, '</div>');
  HTMLRemoveTags(Value);
  Value := Trim(Value);

  // Country
  if (GetOption('AllCountries') = 0) and (Pos(' / ', Value) > 0)  then
    Value := TextBefore(Value, ' / ', '');
  HTMLDecode(Value);
  SetField(fieldCountry, Value);

  // Category
  Value := TextBefore(Line, '<br />', '');
  Line := RemainingText;
  HTMLDecode(Value);
  SetField(fieldCategory, Value);

  // Length
  Value := TextBefore(Line, ' minuten', '');
  Line := RemainingText;
  HTMLDecode(Value);
  SetField(fieldLength, Value);

  // Director
  Value := TextBetween(Line, 'geregisseerd door ', '<br />');
  Line := RemainingText;
  HTMLRemoveTags(Value);
  HTMLDecode(Value);
  SetField(fieldDirector, Value);

  // Actors
  Value := TextBetween(Line, 'met ', '<br />');
  Line := RemainingText;
  HTMLDecode(Value);
  SetField(fieldActors, Value);

  // Description
  Value := TextBetween(Line, '<br />', '</div>');
  HTMLRemoveTags(Value);
  HTMLDecode(Value);
  SetField(fieldDescription, Value);

  // Picture
  Value := TextBetween(PageText, '<img itemprop="image" id="poster" class="poster" src="', '" ');
  if Value <> '' then
  begin
    GetPicture(Value);
  end;

  // Rating
  Value := TextBetween(PageText, '</span>gemiddelde <b>', '<');
  Value := StringReplace(FloatToStr(StrToFloat(StringReplace(Value, ',', '.')) * 2), ',', '.');
  SetField(fieldRating, Value);

  // Comments
  if GetOption('ImportComments') = 1 then
  begin
    Value := TextBetween(PageText, '<div class="forum_message_user">', '<div class="to_page entitypages" id="pages_bottom"></div>');
    Value := StringReplace(Value, ' uur', ' uur :  ' + #13#10);
//    Value := StringReplace(Value, '<div class="forum_message_message">', #13#10);
    Value := StringReplace(Value, '</div><div class="form_horizontal_divider" ', '-------------------------------------------------------------' + #13#10 + #13#10 + '<');
    HTMLRemoveTags(Value);
    HTMLDecode(Value);
    SetField(fieldComments, Value);
  end;

end;


procedure AnalyzeResultsPage(Address: string);
var
  Page: TStringList;
  Line: string;
  MovieAddress: string;
  MovieTitle: string;
  aantal : integer;
begin
  // get results page
  aantal := 0;
  Page := TStringList.Create;
  Page.Text := GetPage(Address);

  // get redirect javascript
  Line := Page.GetString(Page.Count-2);

  // more than 1 movie found
  if Pos('location.replace("http://www.moviemeter.nl/film/searchresults#results");', Line) <> 0 then
  begin
    PickTreeClear;
    PickTreeAdd('Zoekresultaten voor ' + MovieName, '');

    // get results page
    Page.Text := GetPage('http://www.moviemeter.nl/film/searchresults#results');
    if Pos('Populaire zoekresultaten in films:', Page.Text) > 0 then
      Line := TextBetween(Page.Text, 'Populaire zoekresultaten in films:</p>', '<form action="http://www.moviemeter.nl/film/search/"');
    if Pos('Alle zoekresultaten in films:', Page.Text) > 0 then
      Line := TextBetween(Page.Text, 'Alle zoekresultaten in films:</p>', '<form action="http://www.moviemeter.nl/film/search/"');
    if Pos('Zoekresultaten in films:', Page.Text) > 0 then
      Line := TextBetween(Page.Text, 'Zoekresultaten in films:</p>', '<form action="http://www.moviemeter.nl/film/search/"');
    Line := TextBetween(Line, '</p></div>', '<p><br /></p>');
    while Pos('filmresults_row', Line) > 0 do
    begin
      MovieAddress := TextBetween(Line, 'href="', '" >');
      MovieTitle := TextBefore(Line, '</p></div>', '');
      Line := RemainingText;
      HTMLRemoveTags(MovieTitle);
      HTMLDecode(MovieTitle);
      PickTreeAdd(Trim(MovieTitle), MovieAddress);
      aantal := aantal + 1;
    end;
    if aantal = 0 then
     begin
      ShowMessage('Geen resultaten gevonden...');
      Page.Free;
      exit;
     end;
    // if user picks a movie from the results list, import movie details
    if PickTreeExec(Address) then
      AnalyzeMoviePage(Address);
  end
  else
  begin
    MovieAddress := TextBetween(Line, '("', '");');
    if MovieAddress <> 'http://www.moviemeter.nl/film/' then
      // if only 1 movie found --> redirect to movie page
      AnalyzeMoviePage(MovieAddress)
    else
      // no movies found
      ShowMessage('Geen zoekresultaat voor "'+MovieName+'".');
  end;
  Page.Free;

end;


begin
  if CheckVersion(3,5,0) then
  begin
    if StringUtils1_Version >= 2 then
    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://www.moviemeter.nl/film/search/'+UrlEncode(MovieName));
      end;
    end
    else
      ShowMessage('The file "StringUtils1.pas" is outdated, please find a new version of it (at least version 2)');
  end
  else
    ShowMessage('Dit script vereist een nieuwere versie van Ant Movie Catalog (minstens versie 3.5.0)');
    exit;
end.

Posted: 2011-11-17 15:12:01
by antp
Hi,
This script is identical to the one currently on the server :??:

Posted: 2011-11-17 18:27:33
by wvd
Hello, there is more wrong: Titel, Rating, Category, Actors

I've tried to change the script and by my surprice it works nearly good,
I don't know if I did it the right way.
But there is one thing I can't get good and that's the "actors"

Can somebody correct the changed script please.

Thanks a lot :grinking: :grinking:
Greetings Wim


Here is the script how I changed it:

Code: Select all

program MovieMeter;

uses
  StringUtils1;

var
  MovieName: string;

procedure AnalyzeMoviePage(Address: string);
var
  PageText, Line, Value: string;
begin
  PageText := GetPage(Address);

  // URL
  SetField(fieldURL, Address);

  // title & year
  Line := TextBetween(PageText, '<h1 itemprop="name">', '</h1>');
  Value := TextBetween(Line, '(', ')');
  SetField(fieldYear, Value);
  Value := Trim(TextBefore(Line, '(', ''));
  HTMLDecode(Value);
  SetField(fieldOriginalTitle, Value);

  // translated title
  Line := TextBetween(PageText, 'Alternatieve titel', ' </p>');
  if Line <> '' then
  begin
    Line := TextAfter(Line, ': ');
    if Line <> '' then
    begin
      HTMLDecode(Line);
      SetField(fieldTranslatedTitle, Line);
    end;
  end;

  Value := TextBetween(PageText, '<div id="film_info"', '<br />');
  Line := RemainingText;
  Value := TextAfter(Value, '</div>');

  HTMLRemoveTags(Value);
Value := Trim(Value);

  // Country
  if (GetOption('AllCountries') = 0) and (Pos(' / ', Value) > 0)  then
    Value := TextBefore(Value, ' / ', '');
 HTMLDecode(Value);
  SetField(fieldCountry, Value);

  // Category
  Value := TextBetween(Line, '<span itemprop="genre">', '</span><br />');
  Line := RemainingText;
  HTMLRemoveTags(Value);
  HTMLDecode(Value);
  SetField(fieldCategory, Value);
  
  // Length
  Value := TextBefore(Line, ' minuten', '');
  Line := RemainingText;
  HTMLDecode(Value);
  SetField(fieldLength, Value);

  // Director
  Value := TextBetween(Line, 'geregisseerd door ', '<br />');
  Line := RemainingText;
  HTMLRemoveTags(Value);
  HTMLDecode(Value);
  SetField(fieldDirector, Value);

  // Actors
  Value := TextBetween(Line, 'met <span itemprop="actors">', '<br />');
  Line := RemainingText;
  HTMLDecode(Value);
  SetField(fieldActors, Value);

  // Description
  Value := TextBetween(Line, '<br />', '</div>');
  HTMLRemoveTags(Value);
  HTMLDecode(Value);
  SetField(fieldDescription, Value);

  // Picture
  Value := TextBetween(PageText, '<img itemprop="image" id="poster" class="poster" src=', '" ');
  if Value <> '' then
  begin
    GetPicture(Value);
  end;

  // Rating
  Value := TextBetween(PageText, '<span itemprop="ratingValue">', '<');
  Value := StringReplace(FloatToStr(StrToFloat(StringReplace(Value, ',', '.')) * 2), ',', '.');
  SetField(fieldRating, Value);

   // Comments
  if GetOption('ImportComments') = 1 then
  begin
    Value := TextBetween(PageText, '<div class="forum_message_user">', '<div class="to_page entitypages" id="pages_bottom"></div>');
    Value := StringReplace(Value, ' uur', ' uur :  ' + #13#10);
//    Value := StringReplace(Value, '<div class="forum_message_message">', #13#10);
    Value := StringReplace(Value, '</div><div class="form_horizontal_divider" ', '-------------------------------------------------------------' + #13#10 + #13#10 + '<');
    HTMLRemoveTags(Value);
    HTMLDecode(Value);
    SetField(fieldComments, Value);
  end;

end;


procedure AnalyzeResultsPage(Address: string);
var
  Page: TStringList;
  Line: string;
  MovieAddress: string;
  MovieTitle: string;
  aantal : integer;
begin
  // get results page
  aantal := 0;
  Page := TStringList.Create;
  Page.Text := GetPage(Address);

  // get redirect javascript
  Line := Page.GetString(Page.Count-2);

  // more than 1 movie found
  if Pos('location.replace("http://www.moviemeter.nl/film/searchresults#results");', Line) <> 0 then
  begin
    PickTreeClear;
    PickTreeAdd('Zoekresultaten voor ' + MovieName, '');

    // get results page
    Page.Text := GetPage('http://www.moviemeter.nl/film/searchresults#results');
    if Pos('Populaire zoekresultaten in films:', Page.Text) > 0 then
      Line := TextBetween(Page.Text, 'Populaire zoekresultaten in films:</p>', '<form action="http://www.moviemeter.nl/film/search/"');
    if Pos('Alle zoekresultaten in films:', Page.Text) > 0 then
      Line := TextBetween(Page.Text, 'Alle zoekresultaten in films:</p>', '<form action="http://www.moviemeter.nl/film/search/"');
    if Pos('Zoekresultaten in films:', Page.Text) > 0 then
      Line := TextBetween(Page.Text, 'Zoekresultaten in films:</p>', '<form action="http://www.moviemeter.nl/film/search/"');
    Line := TextBetween(Line, '</p></div>', '<p><br /></p>');
    while Pos('filmresults_row', Line) > 0 do
    begin
      MovieAddress := TextBetween(Line, 'href="', '" >');
      MovieTitle := TextBefore(Line, '</p></div>', '');
      Line := RemainingText;
      HTMLRemoveTags(MovieTitle);
      HTMLDecode(MovieTitle);
      PickTreeAdd(Trim(MovieTitle), MovieAddress);
      aantal := aantal + 1;
    end;
    if aantal = 0 then
     begin
      ShowMessage('Geen resultaten gevonden...');
      Page.Free;
      exit;
     end;
    // if user picks a movie from the results list, import movie details
    if PickTreeExec(Address) then
      AnalyzeMoviePage(Address);
  end
  else
  begin
    MovieAddress := TextBetween(Line, '("', '");');
    if MovieAddress <> 'http://www.moviemeter.nl/film/' then
      // if only 1 movie found --> redirect to movie page
      AnalyzeMoviePage(MovieAddress)
    else
      // no movies found
      ShowMessage('Geen zoekresultaat voor "'+MovieName+'".');
  end;
  Page.Free;

end;


begin
  if CheckVersion(3,5,0) then
  begin
    if StringUtils1_Version >= 2 then
    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://www.moviemeter.nl/film/search/'+UrlEncode(MovieName));
      end;
    end
    else
      ShowMessage('The file "StringUtils1.pas" is outdated, please find a new version of it (at least version 2)');
  end
  else
    ShowMessage('Dit script vereist een nieuwere versie van Ant Movie Catalog (minstens versie 3.5.0)');
    exit;
end.

Posted: 2011-11-18 22:45:11
by StefMir
With the IMDB script you only have to import the urls to fill all fields.

Is it possible to change the moviemeter.nl script this way?

I have over 2000 movies and the url's from moviemeter are in my .csv file, but I have to manually point almost all the movies when I run this script.

I don't know how to change the moviemeter.nl script to work the same way and I hope someone can ....

Posted: 2011-11-18 23:16:46
by antp
@wvd > thanks, I took your code and just added a "HTMLRemoveTags" call in the actors processing block to fix that last bug, and uploaded the script as version 2.7.8 on http://update.antp.be/amc/scripts/

@StefMir >I added a "batchmode" option (at the right of the script list, double click on the option name to change it) that allows to skip the title selection if a moviemeter address if found in the URL field.
I hope it will help ;)

Posted: 2011-11-19 00:24:41
by StefMir
Works great !!!!!!

Thank you both!!!

Now I got my 2000+ movies within' a few minutes updated with latest scores etc!!!!

Posted: 2011-11-20 01:26:13
by wvd
Thanx for fixing the problem Antoine :grinking: :grinking:

Posted: 2011-11-20 18:08:03
by xandertje
Thanks both for fixing the problems

It works great :grinking: :grinking:

Posted: 2011-12-28 23:51:05
by wvd
Unfortunaly there's something wrong again.
I have tried but I can't fix it.

The "rating" and the "length" of the movies does not work anymore.

I hope someone can fix it.

Many thanks

Greetings, Wim

Posted: 2011-12-29 00:10:34
by antp
I fixed the rating recently, I'll check for the length

edit: fixed, uploaded on the server as version 2.8.01

Posted: 2011-12-29 12:50:11
by wvd
Antoine,

Thanks for fixing the problem so fast :grinking: :grinking:

Greetings
Wim

Posted: 2012-01-02 20:06:24
by pele
Hi,

New script moviemeter is doing nothing. I does't find any film at all.

Kr. Bianca

Posted: 2012-01-02 21:45:46
by antp
Hi,
They changed the search page it seems.
I updated the script (version 2.8.02)

Posted: 2012-01-03 00:04:49
by pele
thanks for the update script but movies beginning with the...are not be found. Perhaps you can look into it.

Kr. Bianca

Posted: 2012-01-03 09:05:25
by DnDuffe
Same problem.
I updated the script (version of 2-1-2012) but it does not find anything on moviemeter. IMDB works fine.
Does anyone know they answer to this problem?

OR does anyone know another good alternative for moviemeter

Posted: 2012-01-03 12:04:52
by antp
It works with the few movies that I test... What movie do you try? Do you have the version 2.8.02? (version number is shown in the bottom panel when the script is selected)

Posted: 2012-01-03 14:35:59
by DnDuffe
aha now it works for caged but
Return to the Hiding Place he can't find

Posted: 2012-01-03 15:57:15
by Teebee
One more he can't seem to find, and is present on moviemeter:

The Big Red one (1980) http://www.moviemeter.nl/film/2284

tried to search for:
Big Red one
Big Red one, The
The Big Red one
The Big Red one (1980)

Posted: 2012-01-03 21:52:24
by antp
It failed when only one movie is found (because I did a search on the sentence "films gevonden die aan je zoekopdracht voldoen." which is of course different when there is only one :D )
Script fixed as version 2.8.03

Posted: 2012-01-03 23:46:16
by pele
Hi,

The new version works, thanks.

Kr, Bianca