[NL] Custom script from several sites

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
Guest

[NL] Custom script from several sites

Post by Guest »

This script does the following:

-Looks for the movie on moviemeter.nl and downloads all data
-Looks for the movie on IMDB and, fills in the website in the source field and downloads the rating ( I find IMDB more reliable)
-Downloads summary of Cinebel (NL) in the Commentary field
-Downloads a big HQ cover from DVDempire

This is my custom made script, just sharing for those who like it. It is compiled, tweaked and corrected from several other scripts. Credit for the original authors.
rolandb5

Post by rolandb5 »

DOh.. must not post being tired :(
This is the correct script

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;

const
  DescriptionToImport = 2;
var
  MovieName: string;
  MovieName2: string;// variable voor de coverpage
  MovieURL: string;




//
//
//algemeen stuk
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;



function GetDescriptions(Address: string): string;
var
  Line, Value: string;
  LineNr: Integer;
  BeginPos, EndPos,Longest: Integer;
  Page: TStringList;
begin
  Result := '';
  Longest := 0;
  Page := TStringList.Create;
  Page.Text := GetPage(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);
    HTMLDecode(Value);
    HTMLRemoveTags(Value);
    PickListAdd(Value);

    if Length(Value) > Longest then
    begin
      Result := Value;
      Longest := Length(Value);
    end;

    LineNr := FindLine('<p class="plotpar">', Page, LineNr);
  end;
  Page.Free;
end;

procedure AnalyzePageIMDB(Address: string);
var
  Page: TStringList;
begin
  Page := TStringList.Create;
  Page.Text := GetPage(Address);
  if pos('<title>IMDb', Page.Text) = 0 then
  begin
    AnalyzeMoviePageIMDB(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
      AnalyzePageIMDB(Address);
  end;
  Page.Free;
end;


//
//
//cinebel
procedure AnalyzePageCinema(Address: string);
var
  PageText: string;
  Block: string;
  ResultBlock: Integer;
  BeginPos, EndPos: Integer;
  ValueTitle, ValueAddress: string;
begin
  PageText := GetPage(Address);
  if pos('<a href=/fr/film.asp', PageText) > 0 then
  begin
    //SetField(fieldURL, Address);
    AnalyzeMoviePageCinema(PageText)
  end
  else
  begin
    PickTreeClear;
    ResultBlock := Pos('<td class="cadre" height="16">', PageText);
    while ResultBlock > 0 do
    begin
      Delete(PageText, 1, ResultBlock + 35);
      EndPos := Pos('</td>', PageText);
      PickTreeAdd(StringReplace(Copy(PageText, 1, EndPos - 1), #13#10 + '                   ', ''), '');
      BeginPos := EndPos;
      EndPos := Pos('<td height="10"> </td>', PageText);
      Block := Copy(PageText, BeginPos, EndPos - BeginPos);
      Delete(PageText, 1, EndPos);
      BeginPos := Pos('<a href="/nl/film.asp', Block);
      while BeginPos > 0 do
      begin
        Delete(Block, 1, BeginPos - 1);
        EndPos := Pos('</a>', Block);
        ValueTitle := Copy(Block, 1, EndPos - 1);
        HTMLRemoveTags(ValueTitle);
        BeginPos := Pos('"', Block);
        EndPos := Pos('" class', Block);
        ValueAddress := 'http://www.cinebel.be' + Copy(Block, BeginPos + 1, EndPos - BeginPos - 1);
        PickTreeAdd(ValueTitle, ValueAddress);
        EndPos := Pos('</td>', Block);
        Delete(Block, 1, EndPos);
        BeginPos := Pos('<a href="/nl/film.asp', Block);
      end;
      ResultBlock := Pos('<td class="cadre" height="16">', PageText);
    end;
    if PickTreeExec(Address) then
      AnalyzePageCinema(Address);
  end;
end;

procedure AnalyzeMoviePageCinema(PageText: string);
var
  Line, Value: string;
  BeginPos, EndPos: Integer;
begin
  BeginPos := Pos('<table border="0" width="95%" cellpadding="0" cellspacing="0">', PageText);
  Delete(PageText, 1, BeginPos);

  // Description
  BeginPos := Pos('<hr noshade width="100%" size="1" color="#000000">', PageText);
  Delete(PageText, 1, BeginPos);
  EndPos := Pos('<hr noshade width="100%" size="1" color="#000000">', PageText);
  Line := Copy(PageText, 1, EndPos - 1);
  Delete(PageText, 1, EndPos);
  BeginPos := Pos('>', Line);
  Delete(Line, 1, BeginPos);
  Line := StringReplace(Trim(StringReplace(Line, #13#10, '')), '<br>', #13#10#13#10);
  SetField(fieldComments, Line);
  DisplayResults;
end;





//
//
//moviemeter
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;




// COVERSTUK
//
//
 function GetLines(Page: TStringList; LineNr: Integer): String;
var Value, Line: String;
    StartPos : Integer;
begin
  Value := '';
  Line := Page.GetString(LineNr);
  If Pos(' ',Line) > 0 Then Begin
    Value := StringReplace(Line, '•', '');
    HTMLDecode(Value);
    HTMLRemoveTags(Value);
    repeat
      LineNr := LineNr + 1;
      Line := Page.GetString(LineNr);
      If Pos(' ',Line) > 0 Then Begin
        Value := Value + ',' + StringReplace(Line, '•', '');
        HTMLDecode(Value);
        HTMLRemoveTags(Value);
      end;
    until Pos(' ',Line) < 1
  end;
  result := Trim(Value);
end;
// -------------------------------------------------------------------------------------------------------
procedure GetInfo(Page: TStringList; ItemID: String);
var Line, Value : String;
    LineNR, StartPos : Integer;
begin
  // URL
 // SetField(fieldURL,'http://www.dvdempire.com/Exec/v4_item.asp?item_id=' + ItemID);
  //Rating
  LineNr := FindLine('<b>Rating:</b>', Page, 0);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr+3);
    StartPos := Pos('(<b>',Line)+4;
    Value := copy(Line, StartPos, pos('</b>', Line) - StartPos);
  //  SetField(fieldRating,Value);
  end;
  // Year
  LineNr := FindLine('<b>Production Year:</b>', Page, 0);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr);
    StartPos := Pos('</b>',Line)+5;
    Value := Copy(Line, StartPos,4);
 //   SetField(fieldYear, Value);
  end;
  // Director
  LineNr := FindLine('<b>Directors:</b>', Page, 0);
  if LineNr > -1 then
  begin
    Value := GetLines(Page, LineNr+1);
  //  SetField(fieldDirector, Value);
  end;
  // Producer
  LineNr := FindLine('<b>Producers:</b>', Page, 0);
  if LineNr > -1 then
  begin
    Value := GetLines(Page, LineNr+1);
  //  SetField(fieldProducer, Value);
  end;
  // Actors
  LineNr := FindLine('<b>Actors:</b>', Page, 0);
  if LineNr > -1 then
  begin
    Value := GetLines(Page, LineNr+1);
  //  SetField(fieldActors, Value);
  end;
   // Description
  LineNr := FindLine('<b> Synopsis</b>', Page, 0);
  if LineNr > -1 then
  begin
    Value := Page.GetString(LineNr + 16)+Page.GetString(LineNr + 17)+Page.GetString(LineNr + 18);
    Value:=StringReplace(Value, '>i<', '> <');
    HTMLDecode(Value);
    HTMLRemoveTags(Value);
    //SetField(fieldDescription,Value);
  end;
  // Picture
  Line := 'http://images.dvdempire.com/gen/movies/' + ItemID + 'h.jpg';
  GetPicture(Line, False);
end;
// -------------------------------------------------------------------------------------------------------
procedure AnalyzePageCOVER(Address: string);
var
  Page: TStringList;
  LineNr, StartPos, EndPos, L: Integer;
  Line: string;
  ItemID, MovieAddress, MovieTitle : string;
begin
  PickTreeClear;
  Page := TStringList.Create;
  Page.Text := GetPage(Address);
  LineNr := FindLine('<title>DVD Empire - Item -', Page, 0);
  if LineNr >-1 then begin
    LineNr := FindLine('item_id', Page, 0);
    Line := Trim(Page.GetString(LineNr));
    StartPos := pos('item_id=', Line) + 8;
    ItemID := copy(Line, StartPos, pos('&tab=', Line) - StartPos);
    GetInfo(Page,ItemID);
  end else begin
    LineNr := FindLine('Matches Found<br>', Page, 0);
    if LineNr >-1 then begin
      Line := Page.GetString(LineNr);
      StartPos := pos('<b>', Line) + 3;
      L := StrToInt('0'+ Copy(Line, StartPos, pos('</b>', Line) - StartPos),1);
      PickTreeAdd(IntToStr(L)+' Matches found', '');
      If L>0 Then begin
        // Find Films
          LineNr := FindLine('searchID=', Page, LineNr);
          LineNr := LineNr + 1;
        repeat
          LineNr := FindLine('searchID=', Page, LineNr);
          if LineNr >-1 then begin
            Line := Trim(Page.GetString(LineNr));
            LineNr := LineNr + 1;
            If pos('<img src="', Line) <1 Then Begin
              StartPos := pos('item_id=', Line) + 8;
              ItemID := copy(Line, StartPos, pos('">', Line) - StartPos);
              MovieAddress := 'http://www.dvdempire.com/Exec/v4_item.asp?item_id=' + ItemID;
              StartPos := pos('">', Line) + 2;
              MovieTitle := copy(Line, StartPos, 500);
              HTMLDecode(Movietitle);
              HTMLRemoveTags(MovieTitle);
              PickTreeAdd(MovieTitle, MovieAddress);
            end;
          end;
        until (LineNr <1 );
      end;
    end;
    Page.Free;
    if PickTreeExec(Address) then
     begin
      Page := TStringList.Create;
      Page.Text := GetPage(Address);
      ItemID :=copy(Address, 51, 8);
      GetInfo(Page,ItemID);
    end;
  end;
  DisplayResults;
end;




//IMDB Onderdeel
//
//
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;

procedure AnalyzeMoviePageIMDB(Page: TStringList);
var
  Line, Value, Value2, FullValue: string;
  LineNr: Integer;
  BeginPos, EndPos, DescrImport: Integer;
begin
  DescrImport := DescriptionToImport;
  if (DescrImport <> 1) and (Pos('<a href="plotsummary">', Page.Text) = 0) then
    DescrImport := 1;

  MovieURL := 'http://imdb.com/title/tt' + Copy(Page.Text, Pos('?pending&add=', Page.Text) + 17, 7);

  // URL
  SetField(fieldSource, MovieURL);

  // 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 := IntToStr(Round(StrToInt(StrGet(Line, BeginPos), 0) + (StrToInt(StrGet(Line, BeginPos + 2), 0) / 10)));
      SetField(fieldRating, Value);
    end;
  end;
  DisplayResults;
end;




//  Programma Aanroep deel
//
//
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
      if pos('  ', MovieName)>0 then MovieName:=StringReplace(MovieName, '  ', '');// voor eigen gebruik
      AnalyzeResultsPage('http://moviemeter.nl/?search&q='+UrlEncode(MovieName));
      MovieName := GetField(fieldOriginalTitle);
      AnalyzePageIMDB('http://us.imdb.com/Tsearch?title='+UrlEncode(MovieName));
      if pos(', The', MovieName)>0 then MovieName:=StringReplace(MovieName, ', The', '');
      if pos(',The', MovieName)>0 then MovieName:=StringReplace(MovieName, ',The', '');
      AnalyzePageCinema('http://www.cinebel.be/nl/srch.asp?mot='+UrlEncode(MovieName));
      // code voor de coverpage
      MovieName2:=MovieName;
      MovieName:=StringReplace(MovieName, '’', Chr(39));
      MovieName:=AnsiLowerCase(MovieName);
      MovieName:=AnsiUpFirstLetter(MovieName);
      if pos('The ', MovieName)=1 then MovieName:=StringReplace(MovieName, 'The ', '');
      AnalyzePageCOVER('http://www.dvdempire.com/Exec/v5_search_item.asp?string='+UrlEncode(MovieName));
    end;
  end else
    ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.0)');
end.
antp
Site Admin
Posts: 9629
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

I remove the "incorrect" one from the first post.
So this one is different than the one you posted on the other topic ? There is something strange at the end ; I guess that the few lines after the "end." should be deleted...
rolandb5

Post by rolandb5 »

this is indeed another script. though based on the other one.

You were correct on the code, should be removed, but it works when it is included.
antp
Site Admin
Posts: 9629
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

It's because in Pascal & Delphi all what's after the "end." is simply ignored
Bonus
Posts: 10
Joined: 2005-06-15 12:22:25

Post by Bonus »

Can anyone make this one working?

Thx in advance!
Post Reply