[REL][EN] DVD Empire updated script

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
deadeye
Posts: 33
Joined: 2009-02-17 17:33:43

[REL][EN] DVD Empire updated script

Post by deadeye »

Updated the script to deal with the site changes plus a couple of small bug fixes.

Please let me know if you have any problems.

Code: Select all

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

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

[Infos]
Authors=dmitry501,Pavel Uher,Chetan Rao,Deadeye
Title=DVDEmpire.com
Description=Import script for DVD Empire
Site=http://www.dvdempire.com
Language=EN
Version=2.2.0
Requires=4.1.0
Comments=
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
RequiresMovies=1

[Options]
MediaType=0|0|0=DVD|1=Blu-ray
PictureType=0|0|0=Large Picture|1=Small Picture
ClearCheckMark=1|0|0=No|1=Yes

[Parameters]

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

program DVDEmpire;

uses
  StringUtils1;
const
  LF = #13#10;
var
  MovieName: string;
  MediaType: string;
  UpdateFile: TStringList;

//
// ********** Get multiple values from a string **********
// ********** Returns string with comma or linefeed between each item **********
//
function GetMultiValues(Line : String; StartTag : String; EndTag : String; UseCommaDelimiter : Boolean): String;
var
    Value     : String;
    Delimiter : String;
begin
  Result := '';

  if (UseCommaDelimiter) then
    Delimiter := ', '
  else
    Delimiter := LF;

  while(true) do
  begin
    Value := TextBetween(Line, StartTag, EndTag);
    if Value = '' then
      break
    else
    begin
      HTMLDecode(Value);
      HTMLRemoveTags(Value);
      if Pos(Value, Result) = 0 then     // if not a duplicate
      begin
        if (Length(Result) > 0) then
          Result := Result + Delimiter;
      
        Result := Result + Value;
      end;
      Line := RemainingText;
    end;
  end;
end;

//
// ********** Gets the specific movie info **********
//
procedure GetMovieInfo(Address: String);
var PageText, Value, TempValue : String;
    hours, mins : Integer;
begin
  PageText := GetPage(Address);

  // URL
  SetField(fieldURL, Address);

  // Picture
  Value := TextBetween(PageText, '<div id="Boxcover"><a href="', '" class="fancy"');
  if GetOption('PictureType') = 1 then 
    Value := StringReplace(Value, 'h.jpg', 'm.jpg');
  GetPicture(Value);

  // Original Title
  Value := TextBetween(PageText, '<span itemprop="name">', '</span>');
  HTMLDecode(Value);
  SetField(fieldOriginalTitle, Value);

  // Media Type
  Value := TextBetween(PageText, 'class="active">', '</a>');
  SetField(fieldMediaType, Value);

  // Description
  Value := TextBetween(PageText, '<p class="Tagline">', '</div>');
  Value := StringReplace(Value, '</p><p>', LF);
  Value := StringReplace(Value, '®', '®');
  HTMLDecode(Value);
  HTMLRemoveTags(Value);
  Value := FullTrim(Value);
  SetField(fieldDescription, Value);

  // Length
  Value := Trim(TextBetween(PageText, '<strong>Length</strong>', '<br/>'));
  if Value <> '' then
  begin
    hours := StrToInt(Trim(TextBefore(Value, ' hrs', '')),1);
    mins := StrToInt(Trim(TextBetween(Value, 'hrs. ', ' mins')),1);
    Value := IntToStr(hours*60+mins);
    SetField(fieldLength, Value);
  end;

  // Rating
  Value := 'Rating: ' + Trim(TextBetween(PageText, '<strong>Rating</strong>', '<br/>'));
  SetField(fieldComments, Value);

  // Year
  Value := Trim(TextBetween(PageText, '<strong>Production Year</strong>', '<br/>'));
  SetField(fieldYear, Value);

  // Number of Discs
  Value := Trim(TextBetween(PageText, '<strong>Number of Discs</strong>', '<br/>'));
  SetField(fieldDisks, Value);

  // Subtitles
  Value := Trim(TextBetween(PageText, '<strong>Subtitles</strong>', '<br/>'));
  SetField(fieldSubtitles, Value);

  // Video format
  Value := Trim(TextBetween(PageText, '<strong>Video</strong>', '<strong>'));
  HTMLRemoveTags(Value);
  Value := FullTrim(Value);
  SetField(fieldVideoFormat, Value);

  // Audio
  TempValue := FullTrim(TextBetween(PageText, '<strong>Audio</strong><br />', '</div>'));
  if TempValue <> '' then
  begin
    TempValue := RemoveSpaces(TempValue, true);
    Value := TextBetween(TempValue, ' ', '<br />');
    SetField(fieldAudioFormat, Value);

    // Languages
    Value := '<br />' + TempValue;
    Value := GetMultiValues(Value, '<br />', ' ', true);
    SetField(fieldLanguages, Value);
  end;

  // Actors
  Value := FullTrim(TextBetween(PageText, '<h3>Cast</h3>', '</div>'));
  Value := GetMultiValues(Value, '">', '</a>', false);
  SetField(fieldActors, Value);

  // Producer(s)
  Value := FullTrim(TextBetween(PageText, '<h3>Production</h3>', '</div>'));
  Value := GetMultiValues(Value, '<li>', '</li>', true);
  SetField(fieldProducer, Value);

  // Director(s)
  Value := FullTrim(TextBetween(PageText, '<h3>Director</h3>', '</div>'));
  Value := GetMultiValues(Value, '">', '</a>', true);
  SetField(fieldDirector, Value);

  // Clear Check Mark
  if GetOption('ClearCheckMark') = 1 then
    SetField(fieldChecked, 'false');
end;

//
// ********** Gets the movie titles/addresses from the search results page **********
//
procedure AnalyzePage(Address: string);
var
  Page: TStringList;
  LineNr, L: Integer;
  Line: string;
  MovieAddress, MovieTitle: string;
begin
  PickTreeClear;
  Page := TStringList.Create;
  Page.Text := GetPage(Address);
  LineNr := FindLine('</strong> Matches Found', Page, 0);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr);
    L := StrToInt(StringReplace(Trim(TextBetween(Line, '<strong>', '</strong>')), ',', ''),1);
    If L > 50 then
      begin
        PickTreeAdd('First 50 results of ' + IntToStr(L), '');
        L := 50;
      end
    else
      begin
        PickTreeAdd(IntToStr(L)+' Matches found', '');
      end;

    while L > 0 do
    begin
      // Find the line with the film info
      LineNr := FindLine('<p class="title"><a href="', Page, LineNr + 1);
      Line := Trim(Page.GetString(LineNr));

      // find the movie name
      MovieTitle := TextBetween(Line, 'itemprop="name">', '</a>');

      // find the link
      MovieAddress := 'http://www.dvdempire.com' + TextBetween(Line, '<p class="title"><a href="', '" title=');

      // add it to the tree
      HTMLDecode(MovieTitle);
      HTMLRemoveTags(MovieTitle);
      PickTreeAdd(MovieTitle, MovieAddress);

      // decrement counter
      L := L - 1;
    end;
  end;
  Page.Free;
  if PickTreeExec(Address) then
    GetMovieInfo(Address);
end;


//
// ********** Begin program **********
//
begin
  // Check StringUtils1 version and update if < version 7
  if StringUtils1_Version < 7 then
  begin
    if ShowWarning('Old version of file "Stringutils1.pas" detected: v' + IntToStr(StringUtils1_Version) + LF + 'The script requires at least version 7.' + LF + 'Download and install latest version now ?') = True then
    begin
      UpdateFile := TStringList.Create;
      UpdateFile.Text := GetPage('http://update.antp.be/amc/scripts/StringUtils1.pas');
      UpdateFile.SaveToFile(dirScripts + 'StringUtils1.pas');
      UpdateFile.Free;
      ShowInformation('StringUtils1 has been updated. Please restart the DVD Empire script now. Thank you.');
      Exit;
    end
    else
    begin
      ShowInformation('You can download latest version of "StringUtils1.pas" using script "update scripts" or via http://update.antp.be/amc/scripts');
      Exit;
    end;
  end;

  // Check for current AMC version
  if CheckVersion(4,1,0) then
  begin
    PickListClear;
    MovieName := GetField(fieldOriginalTitle);
    if MovieName = '' then
      MovieName := GetField(fieldTranslatedTitle);
    if not Input('Import from DVD Empire', 'Enter the title or the URL of the movie:', MovieName) then
      Exit;
    if Pos('dvdempire.com', MovieName) > 0 then
      AnalyzePage(MovieName)
    else
      MovieName := AnsiLowerCase(MovieName);
      MovieName := StringReplace(MovieName, '’', '');
      MovieName := StringReplace(MovieName, Chr(39), '');
      MovieName := StringReplace(MovieName, ' ', '+');
      MovieName := StringReplace(MovieName, '&', '%26');
      MediaType := 'dvd';
      // Blu-ray
      if GetOption('MediaType')=1 then MediaType := 'blu-ray';
      AnalyzePage('http://www.dvdempire.com/' + MediaType + '/search?exactMatch=' + MovieName + '&q=' + MovieName + '&sort=score&pageSize=50');
  end
  else
    ShowMessage('This script requires a newer version of Ant Movie Catalog (at least version 4.1.0)');
end.
Last edited by deadeye on 2013-04-08 01:42:02, edited 1 time in total.
oneacer
Posts: 16
Joined: 2009-02-13 18:32:26

Post by oneacer »

This new script you worked on for DVDEmpire.com works like a charm. Thank you again for all your time and effort. If I can assist you with anything, just message me.
antp
Site Admin
Posts: 9636
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

Thanks for the update
Sabertooth
Posts: 2
Joined: 2013-04-07 14:41:42

Re: [REL][EN] DVD Empire updated script

Post by Sabertooth »

Greetings!
deadeye wrote:Please let me know if you have any problems.
When I attempted to use your script, there is an extra (empty) line at the top of the script that prevented recognition until it was removed. IOW, as posted, the script failed to show up in my scripts list.

Code: Select all

(*************************************************** 
oneacer
Posts: 16
Joined: 2009-02-13 18:32:26

Post by oneacer »

Only copy from:

program DVDEmpire; .......to........ end.


Then past over existing script, works like a charm. Been using it for years.
deadeye
Posts: 33
Joined: 2009-02-17 17:33:43

Re: [REL][EN] DVD Empire updated script

Post by deadeye »

Sabertooth wrote:there is an extra (empty) line at the top of the script that prevented recognition until it was removed
Sorry about that, it was my misuse of the code tags. Should be fixed now.
antp
Site Admin
Posts: 9636
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

I updated it on the server too, as I didn't notice that when I copied the file there.
antp
Site Admin
Posts: 9636
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

oneacer wrote:Only copy from:

program DVDEmpire; .......to........ end.


Then past over existing script, works like a charm. Been using it for years.
By doing that you do not have the correct script version indicated (can be useful if you notice problems to be sure that you have the latest one)
And if the script has new options, these would not be added either.
deadeye
Posts: 33
Joined: 2009-02-17 17:33:43

latest script version

Post by deadeye »

Update the script to deal with site changes.
Also added the option to show the year of film release or dvd release in the search results.

Code: Select all

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

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

[Infos]
Authors=dmitry501,Pavel Uher,Chetan Rao,Deadeye
Title=DVDEmpire.com
Description=Import script for DVD Empire
Site=http://www.dvdempire.com
Language=EN
Version=2.2.2
Requires=4.1.0
Comments=
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
RequiresMovies=1

[Options]
MediaType=0|0|0=DVD|1=Blu-ray
PictureType=1|0|0=Large Picture|1=Small Picture
ClearCheckMark=1|0|0=No|1=Yes
YearOption=0|0|0=Movie Release Year (if available)|1=DVD Release Year (if available)

[Parameters]

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

program DVDEmpire;

uses
  StringUtils1;
const
  LF = #13#10;
var
  MovieName: string;
  MediaType: string;
  UpdateFile: TStringList;

//
// ********** Get multiple values from a string **********
// ********** Returns string with comma or linefeed between each item **********
//
function GetMultiValues(Line : String; StartTag : String; EndTag : String; UseCommaDelimiter : Boolean): String;
var
    Value     : String;
    Delimiter : String;
begin
  Result := '';

  if (UseCommaDelimiter) then
    Delimiter := ', '
  else
    Delimiter := LF;

  while(true) do
  begin
    Value := TextBetween(Line, StartTag, EndTag);
    if Value = '' then
      break
    else
    begin
      HTMLDecode(Value);
      HTMLRemoveTags(Value);
      if Pos(Value, Result) = 0 then     // if not a duplicate
      begin
        if (Length(Result) > 0) then
          Result := Result + Delimiter;
      
        Result := Result + Value;
      end;
      Line := RemainingText;
    end;
  end;
end;

//
// ********** Gets the specific movie info **********
//
procedure GetMovieInfo(Address: String);
var PageText, Value, TempValue : String;
    hours, mins : Integer;
begin
  PageText := GetPage(Address);

  // URL
  SetField(fieldURL, Address);

  // Picture
  Value := TextBetween(PageText, '<div id="Boxcover"><a href="', '" class="fancy"');
  if GetOption('PictureType') = 1 then 
    Value := StringReplace(Value, 'h.jpg', 'm.jpg');
  GetPicture(Value);

  // Original Title
  Value := TextBetween(PageText, '<meta itemprop="name" content="', '"');
  HTMLDecode(Value);
  SetField(fieldOriginalTitle, Value);

  // Media Type
  Value := TextBetween(PageText, 'class="active">', '</a>');
  SetField(fieldMediaType, Value);

  // Description
  Value := TextBetween(PageText, '<p class="Tagline">', '</div>');
  Value := StringReplace(Value, '</p><p>', LF);
  Value := StringReplace(Value, '®', '®');
  HTMLDecode(Value);
  HTMLRemoveTags(Value);
  Value := FullTrim(Value);
  SetField(fieldDescription, Value);

  // Length
  Value := Trim(TextBetween(PageText, '<strong>Length</strong>', '<br/>'));
  HTMLRemoveTags(Value);
  if Value <> '' then
  begin
    hours := StrToInt(Trim(TextBefore(Value, ' hrs', '')),1);
    mins := StrToInt(Trim(TextBetween(Value, 'hrs. ', ' mins')),1);
    Value := IntToStr(hours*60+mins);
    SetField(fieldLength, Value);
  end;

  // Rating
  Value := 'Rating: ' + Trim(TextBetween(PageText, '<span itemprop="contentRating"> ', '</span>'));
  SetField(fieldComments, Value);

  // Year
  Value := Trim(TextBetween(PageText, '<strong>Production Year</strong>', '<br/>'));
  SetField(fieldYear, Value);

  // Number of Discs
  Value := Trim(TextBetween(PageText, '<strong>Number of Discs</strong>', '<br/>'));
  SetField(fieldDisks, Value);

  // Subtitles
  Value := Trim(TextBetween(PageText, '<strong>Subtitles</strong>', '<br/>'));
  SetField(fieldSubtitles, Value);

  // Video format
  Value := Trim(TextBetween(PageText, '<strong>Video</strong>', '<strong>'));
  HTMLRemoveTags(Value);
  Value := FullTrim(Value);
  SetField(fieldVideoFormat, Value);

  // Audio
  TempValue := FullTrim(TextBetween(PageText, '<strong>Audio</strong><br />', '</div>'));
  if TempValue <> '' then
  begin
    TempValue := RemoveSpaces(TempValue, true);
    Value := TextBetween(TempValue, ' ', '<br />');
    SetField(fieldAudioFormat, Value);

    // Languages
    Value := '<br />' + TempValue;
    Value := GetMultiValues(Value, '<br />', ' ', true);
    SetField(fieldLanguages, Value);
  end;

  // Actors
  Value := FullTrim(TextBetween(PageText, '<h3>Cast</h3>', '</div>'));
  Value := GetMultiValues(Value, '">', '</a>', false);
  SetField(fieldActors, Value);

  // Producer(s)
  Value := FullTrim(TextBetween(PageText, '<h3>Production</h3>', '</div>'));
  Value := GetMultiValues(Value, '<span itemprop="name">', '</span>', true);
  SetField(fieldProducer, Value);

  // Director(s)
  Value := FullTrim(TextBetween(PageText, '<h3>Director</h3>', '</div>'));
  Value := GetMultiValues(Value, '">', '</a>', true);
  SetField(fieldDirector, Value);

  // Clear Check Mark
  if GetOption('ClearCheckMark') = 1 then
    SetField(fieldChecked, 'false');
end;

//
// ********** Gets the movie titles/addresses from the search results page **********
//
procedure AnalyzePage(Address: string);
var
  LineNr, L: Integer;
  PageText, MovieText: string;
  MovieAddress, MovieTitle, MovieYear: string;
begin
  PickTreeClear;
  PageText := GetPage(Address);
  L := StrToInt(TextBetween(PageText, '<span class="sub"><strong>', '</strong> Matches Found'),1);
  PageText := RemainingText;
  if L > 0 then
  begin
    if L > 50 then
    begin
      PickTreeAdd('First 50 results of ' + IntToStr(L), '');
      L := 50;
    end
    else
    begin
      PickTreeAdd(IntToStr(L)+' Matches found', '');
    end;

    repeat
      // Get the info of one result
      MovieText := TextBetween(PageText, '<div class="container"><span class="rank">', '<p class="cast">');
      PageText := RemainingText;
      
      // find the link
      MovieAddress := 'http://www.dvdempire.com' + TextBetween(MovieText, '<p class="title"><a href="', '" title=');
      MovieText := RemainingText;

      // find the movie name
      MovieTitle := TextBetween(MovieText, '"List Page" Label="Title">', '</a>');
      MovieText := RemainingText;

      // find the year
      if GetOption('YearOption')=0 then
        MovieYear := FullTrim(TextBetween(MovieText, '- year: ', '</p>'))    // movie release year
      else
        MovieYear := FullTrim(TextBetween(MovieText, '- Released ', LF));    // dvd release year
      if MovieYear <> '' then
        MovieTitle := MovieTitle + ' [' + MovieYear + ']';

      // add it to the tree
      HTMLDecode(MovieTitle);
      HTMLRemoveTags(MovieTitle);
      PickTreeAdd(MovieTitle, MovieAddress);

      // decrement counter
      L := L - 1;
    until L = 0;
  end;
  if PickTreeExec(Address) then
    GetMovieInfo(Address);
end;


//
// ********** Begin program **********
//
begin
  // Check StringUtils1 version and update if < version 7
  if StringUtils1_Version < 7 then
  begin
    if ShowWarning('Old version of file "Stringutils1.pas" detected: v' + IntToStr(StringUtils1_Version) + LF + 'The script requires at least version 7.' + LF + 'Download and install latest version now ?') = True then
    begin
      UpdateFile := TStringList.Create;
      UpdateFile.Text := GetPage('http://update.antp.be/amc/scripts/StringUtils1.pas');
      UpdateFile.SaveToFile(dirScripts + 'StringUtils1.pas');
      UpdateFile.Free;
      ShowInformation('StringUtils1 has been updated. Please restart the DVD Empire script now. Thank you.');
      Exit;
    end
    else
    begin
      ShowInformation('You can download latest version of "StringUtils1.pas" using script "update scripts" or via http://update.antp.be/amc/scripts');
      Exit;
    end;
  end;

  // Check for current AMC version
  if CheckVersion(4,1,0) then
  begin
    PickListClear;
    MovieName := GetField(fieldOriginalTitle);
    if MovieName = '' then
      MovieName := GetField(fieldTranslatedTitle);
    if not Input('Import from DVD Empire', 'Enter the title or the URL of the movie:', MovieName) then
      Exit;
    if Pos('dvdempire.com', MovieName) > 0 then
      AnalyzePage(MovieName)
    else
      MovieName := AnsiLowerCase(MovieName);
      MovieName := StringReplace(MovieName, '’', '');
      MovieName := StringReplace(MovieName, Chr(39), '');
      MovieName := StringReplace(MovieName, ' ', '+');
      MovieName := StringReplace(MovieName, '&', '%26');
      MovieName := StringReplace(MovieName, ':', '%3A');

      MediaType := 'dvd';
      // Blu-ray
      if GetOption('MediaType')=1 then MediaType := 'blu-ray';
      AnalyzePage('http://www.dvdempire.com/' + MediaType + '/search?exactMatch=' + MovieName + '&q=' + MovieName + '&sort=score&pageSize=50');
  end
  else
    ShowMessage('This script requires a newer version of Ant Movie Catalog (at least version 4.1.0)');
end.
antp
Site Admin
Posts: 9636
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

Thanks
oneacer
Posts: 16
Joined: 2009-02-13 18:32:26

Post by oneacer »

Thank You very much.
Post Reply