Moviemeter import doesn't work anymore

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
wvd
Posts: 96
Joined: 2006-08-02 22:21:20
Location: Nederland

Moviemeter import doesn't work anymore

Post by wvd »

Hello,

Can someone fix the script for the moviemeter import? ;)
Thank you very much. :grinking: :grinking:
tsjarlie
Posts: 8
Joined: 2007-08-28 20:11:54

Post by tsjarlie »

The moviemeter.nl site has changed something ...
Here's a preliminary script, the explanation of what has changed is in dutch.

Ik heb een voorlopige oplossing, ik heb de code om bij slechts 1 keuze direct de film te laden uitgeschakeld. Nu krijg je sowieso steeds een tussenscherm.
In de code heb ik onderaan (analyzeresultspage) enkele dingen in commentaar geplaatst.

Ik gebruik dit script samen met mijn XBMC script om de info uit amc naar mijn xbox xbmc over te brengen. Daarom zou het kunnen zijn dat er nog bepaalde zaken gewijzigd zijn. URL van cover staat ook ergens in een veld en ook het aantal stemmen op moviemeter.nl denk ik.

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 apart
  Line := TextBetween(PageText, '<h1>', '</h1>');
  Value := TextBetween(Line, '(', ')');
  SetField(fieldYear, Value);
  //Value := Trim(TextBefore(Line, '(', ''));
  //HTMLDecode(Value);
  //SetField(fieldOriginalTitle, Value);
  
  // title & year tesamen
  Value := TextBetween(PageText, '<h1>', '</h1>');
  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, '>');

  // 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 class="poster" src="', '" ');
  if Value <> '' then
  begin
    GetPicture(Value);
    SetField(fieldBorrower, Value);
  end;
  
  // Aantal Stemmen
  Value := TextBetween(PageText, '<div id="film_votes"><b>', '<');
  HTMLDecode(Value);
  SetField(fieldMediaType, Value);

  // 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;
begin
  // get results page
  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[/color]/film/searchresults', Line) <> 0 then
  begin
    PickTreeClear;
    PickTreeAdd('Zoekresultaten voor ' + MovieName, '');

    // get results page
    Page.Text := GetPage('http://www.moviemeter.nl/film/searchresults');
    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/"');
    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/"');
    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);
    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);
        SetField(fieldTranslatedTitle, MovieName);
      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)');
end.
[/code]
wvd
Posts: 96
Joined: 2006-08-02 22:21:20
Location: Nederland

Post by wvd »

Hartelijk bedankt :grinking: :)

Ga ik vanavond uitproberen.

Groeten,
Wim
antp
Site Admin
Posts: 9629
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

You did not include the block at the beginning of the script, with script infos and options (for that you have to open the script file with a text editor instead of using AMC's build-in editor).
But maybe you did not add options? There is still maybe the comments & versions that you updated.
tsjarlie
Posts: 8
Joined: 2007-08-28 20:11:54

Post by tsjarlie »

Wim,

Als het niet werkt, laat iets weten.

antp,

J'ai rien changé au debut de la script, meme pas les commentaires et la version.

I'haven't changed anything in te beginning of the script, I will test it in a few days, then I will change the comments & credits and upload a new version.

grtz tsJarlie
xandertje
Posts: 2
Joined: 2008-09-12 14:26:02

Post by xandertje »

Tsjarlie, hartelijk dank voor jouw script van moviemeter. Voor mijn doel werkt het uitstekend
antp
Site Admin
Posts: 9629
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

tsjarlie wrote: J'ai rien changé au debut de la script, meme pas les commentaires et la version.

I'haven't changed anything in te beginning of the script, I will test it in a few days, then I will change the comments & credits and upload a new version.
I updated the version and added your nickname in comments, for the version that I uploaded on my server ;)
wvd
Posts: 96
Joined: 2006-08-02 22:21:20
Location: Nederland

Post by wvd »

Tsjarlie,

Bedankt voor je moeite :grinking:

De import werkt weer, maar hetvolgende:

In het veld 'drager' komt een nummer te staan,
bij 'Uitgeleend aan' komt de url van het plaatje te staan,
En bij 'Vertaalde titel' komt niet de vertaalde titel te staan maar de originele titel nog een keer.

Als je dit nog kunt oplossen ben ik weer helemaal blij :lol: :lol:

groeten
Wim
Miss_Kitty
Posts: 14
Joined: 2007-04-14 18:25:03

Post by Miss_Kitty »

Ik heb het script als volgt aangepast:

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>', '</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, '>');

  // 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 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.
wvd
Posts: 96
Joined: 2006-08-02 22:21:20
Location: Nederland

Post by wvd »

Miss Kitty,

Heel erg bedankt, het werkt weer als vanouds :grinking: :grinking: :wink:

Groeten,
Wim
tsjarlie
Posts: 8
Joined: 2007-08-28 20:11:54

Post by tsjarlie »

sorry Wim

Ik had het script al aangepast voor eigen gebruik met die velden, heb de verkeerde versie doorgestuurd, gelukkig dat miss kitty intussen een correct script doorgestuurd heeft. :grinking:
wvd
Posts: 96
Joined: 2006-08-02 22:21:20
Location: Nederland

Post by wvd »

Tsjarlie,

Je hoeft je echt niet te verontschuldigen, ik vind het geweldig dat jij en Miss Kitty de moeite nemen om me helpen.

Allebei heel erg bedankt :grinking: :grinking:

Wim
Post Reply