Couple Scripts.

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
NoFiX

Couple Scripts.

Post by NoFiX »

With the lacking IMDB cover-art section, here is a couple picture grabbing scripts.

Here's the Yahoo-Movies picture/plot grabber, easily modified if you want it to do more:

Code: Select all


// GETINFO SCRIPTING
// Yahoo Movies (Quick Picture Grab) - NoFiX

program YahooPictureGrab;
const
  YMGrabPlot = FALSE;
var
  MovieName: string;

procedure AnalyzePage(Address: string);
var
  debugPage: TStringList;
  strPage, MovieAddr, MovieTitle, MoviePlot, MovieID: string;
  BeginPos, EndPos: Integer;
begin
//  debugPage:= TStringList.Create;
//  debugPage.Text := GetPage(Address);
//  debugPage.SaveToFile('C:\Yahoo1.txt');
  strPage:= GetPage(Address);
  BeginPos:= Pos('Titles Found</b>', strPage);
  Delete(strPage, 1, BeginPos);
  if(BeginPos > 0) then
    begin
      PickTreeClear;
      PickTreeAdd('Results for ' + MovieName + ':', '');
      BeginPos:= Pos('<a HRef="', strPage);
      while BeginPos > 0 do
        begin
         // Movie Address
          EndPos:= Pos('">', Copy(strPage, BeginPos, Length(strPage) - BeginPos)) + BeginPos - 1;
          MovieAddr:= Copy(strPage, BeginPos + 9, EndPos - BeginPos - 9);
         // Movie Title
          BeginPos:= EndPos + 2;
          EndPos:= Pos('</a>', strPage);
          MovieTitle:= Copy(strPage, BeginPos, EndPos - BeginPos);
         // Add to listbox
          PickTreeAdd(MovieTitle, MovieAddr);
         // Restart the process
          Delete(strPage, 1, EndPos);
          BeginPos:= Pos('<a HRef="', strPage);
        end;
        if(PickTreeExec(Address)) then
          begin
            strPage:= GetPage(Address);
            BeginPos:= Pos('<img src="http://shopping.yahoo.com/video/images/', strPage);
            if(BeginPos > 0) then
              begin
                EndPos:= Pos('"', Copy(strPage, BeginPos + 10, Length(strPage) - BeginPos)) + BeginPos;
                Address:= Copy(strPage, BeginPos + 10, EndPos - BeginPos - 1);
                GetPicture(Address, FALSE);
              end
            else
              ShowMessage('No cover-art was found for :' + MovieName);
            // Check if we need plot
            if(GetField(fieldDescription) = '') or (YMGrabPlot = TRUE) then
              begin
                BeginPos:= Pos('<font face=arial size=-1><b>' + #13, strPage) + 35;
                Delete(strPage, 1, BeginPos);
                EndPos:= Pos('<p>', strPage);
                MoviePlot:= Copy(strPage, 1, EndPos - 3);
                HTMLDecode(MoviePlot);
                SetField(fieldDescription, MoviePlot);
              end;
          end;
    end;
end;

begin
  if CheckVersion(3,4,0) then
  begin
    MovieName := GetField(fieldOriginalTitle);
    if MovieName = '' then
      MovieName := GetField(fieldTranslatedTitle);
    begin
      AnalyzePage('http://search.movies.yahoo.com/search/movies/title?p=%5B' + UrlEncode(MovieName) + '%5D+type%3Afeature&intl=us&search=title&s=wt,-$s');
    end;
  end else
    ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.0)');
end.

Here's one for CDUniverse:

Code: Select all


// GETINFO SCRIPTING
// CDUniverse (Quick Picture Grab) - NoFiX

program CUPictureGrab;
var
  MovieName: string;

procedure AnalyzePage(Address: string);
var
  strPage, MovieAddr, MovieTitle, MovieDate, MovieID: string;
  BeginPos, EndPos: Integer;
begin
  strPage := GetPage(Address);
  BeginPos := Pos('<b>Click price', strPage);
  if(BeginPos > -1)then
    begin
      PickTreeClear;
      PickTreeAdd('Search Results for: ' + MovieName, '');
      Delete(strPage, 1, BeginPos);
      BeginPos := Pos('<a href="/productinfo.asp?', strPage);
      EndPos := 1;
      while ((BeginPos > 0) and (EndPos > 0)) do
        begin
          Delete(strPage, 1, BeginPos + 29);
          EndPos := Pos('cart=', strPage) - 1;
          MovieId := Copy(strPage, 1, EndPos - 1);
          MovieAddr := 'http://www.cduniverse.com/productinfo.asp?pid=' + MovieId + '&cart=0&style=movie';
          BeginPos := Pos('<b>', strPage) + 3;
          EndPos := Pos('</b>', strPage);
          MovieTitle := Copy(strPage, BeginPos, EndPos - BeginPos);
          PickTreeAdd(MovieTitle, MovieAddr);
          BeginPos := Pos('<a href="/productinfo.asp?', strPage);
          if(Pos('</table>', strPage) < BeginPos) then
           BeginPos := -1;
        end;
      if(PickTreeExec(Address)) then
        begin
          strPage := GetPage(Address);
          if(Pos('default_coverart.gif', strPage) < 0) then
            begin
              BeginPos := Pos('<img src="http://cover', strPage) + 9;
              Delete(strPage, 1, BeginPos);
              EndPos := Pos('" border=', strPage) - 1;
              //ShowMessage(Copy(strPage, 1, EndPos));
              Address := Copy(strPage, 1, EndPos);
              GetPicture(Address, false);
            end
          else
            ShowMessage('Sorry, no cover-art was found for ' + MovieName);
        end;
    end;
end;

begin
  if CheckVersion(3,4,0) then
  begin
    MovieName := GetField(fieldOriginalTitle);
    if MovieName = '' then
      MovieName := GetField(fieldTranslatedTitle);
    begin
      AnalyzePage('http://www.cduniverse.com/sresult.asp?cart=123456789&style=movie&HT_Search_Info=' + UrlEncode(MovieName));
    end;
  end else
    ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.0)');
end.

Any suggestions or anything are welcome. And as you can see, I went with the simplicity approach on these.
antp
Site Admin
Posts: 9651
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

Thanks ;)

For CDUniverse script, there is a strange thing on line 55 :
if(Pos('default_coverart.gif', strPage) < 0) then
Pos can't return less than 0, since not found = 0, otherwise it returns the position of the string (from 1 to length of the string)
When I replace the "<" by a "=", the script works much better :D
Guest

Post by Guest »

Oops, didn't notice that one :)

Thanks.
NoFiX

Post by NoFiX »

There's also a major error with the Yahoo script as well.

Here's a temp version of it, that works much better.


Code: Select all


// GETINFO SCRIPTING
// Yahoo Movies (Quick Picture Grab)

program YahooPictureGrab;
const
  YMGrabPlot = FALSE;
var
  MovieName: string;

procedure AnalyzePage(Address: string);
var
  debugPage: TStringList;
  strPage, MovieAddr, MovieTitle, MoviePlot, MovieID: string;
  BeginPos, EndPos: Integer;
begin
//  debugPage:= TStringList.Create;
//  debugPage.Text := GetPage(Address);
//  debugPage.SaveToFile('C:\Yahoo1.txt');
  strPage:= GetPage(Address);
  BeginPos:= Pos('Titles Found</b>', strPage);
  Delete(strPage, 1, BeginPos);
  if(BeginPos > 0) then
    begin
      PickTreeClear;
      PickTreeAdd('Results for ' + MovieName + ':', '');
      BeginPos:= Pos('<a HRef="', strPage);
      while BeginPos > 0 do
        begin
         // Movie Address
          EndPos:= Pos('">', Copy(strPage, BeginPos, Length(strPage) - BeginPos)) + BeginPos - 1;
          MovieAddr:= Copy(strPage, BeginPos + 9, EndPos - BeginPos - 9);
         // Movie Title
          BeginPos:= EndPos + 2;
          EndPos:= Pos('</a>', strPage);
          MovieTitle:= Copy(strPage, BeginPos, EndPos - BeginPos);
         // Add to listbox
          PickTreeAdd(MovieTitle, MovieAddr);
         // Restart the process
          Delete(strPage, 1, EndPos);
          BeginPos:= Pos('<a HRef="', strPage);
        end;
        if(PickTreeExec(Address)) then
          begin
            strPage:= GetPage(Address);
            BeginPos:= FindBefore('<img src="', strPage, Pos('"Movie Image"', strPage));
            if(BeginPos > 0) then
              begin
                Delete(strPage, 1, BeginPos + 9);
                EndPos:= Pos('"', strPage);
                Address:= Copy(strPage, 1, EndPos - 1);
                GetPicture(Address, FALSE);
              end
            else
              ShowMessage('No cover-art was found for :' + MovieName);
            // Check if we need plot
            if(GetField(fieldDescription) = '') or (YMGrabPlot = TRUE) then
              begin
                BeginPos:= Pos('<font face=arial size=-1><b>' + #13, strPage) + 35;
                ShowMessage(IntToStr(BeginPos));
                Delete(strPage, 1, BeginPos);
                EndPos:= Pos('<p>', strPage);
                MoviePlot:= Copy(strPage, 1, EndPos - 3);
                HTMLDecode(MoviePlot);
                SetField(fieldDescription, MoviePlot);
              end;
          end;
    end;
end;

Function FindBefore(wordToFind: string; text: string; sPos: Integer):Integer;
var
  iPos, iFound: Integer;
begin
  Text:= Copy(Text, 1, sPos);

  iPos:= Pos(wordToFind, Text);
  iFound:= iPos;
  while iPos > 0 do
    begin
      if(iPos > 0) then
          Delete(Text, 1, iPos);

      iPos:= Pos(wordToFind, Text);
      iFound:= iFound + iPos;
    end;
   result:= iFound;
end;

begin
  if CheckVersion(3,4,0) then
  begin
    MovieName := GetField(fieldOriginalTitle);
    if MovieName = '' then
      MovieName := GetField(fieldTranslatedTitle);
    begin
      AnalyzePage('http://search.movies.yahoo.com/search/movies/title?p=%5B' + UrlEncode(MovieName) + '%5D+type%3Afeature&intl=us&search=title&s=wt,-$s');
    end;
  end else
    ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.0)');
end.
Sorry for cause any problems.
antp
Site Admin
Posts: 9651
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

What do you mean by "temp version" ? Can I include this one with the program or is it not yet finished ?
NoFiX

Post by NoFiX »

Yes, you can include it. But I plan on cleaning them both up a bit, plus I have a few more I'm going to release, so I'll just zip them and host them somewhere so you can get all of them at the same time.

Anyways, thanks a lot for the software.
Post Reply