[REQ][EN] How to modify IMDB script to import large pic url

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
Mguel
Posts: 39
Joined: 2003-01-28 10:48:14

[REQ][EN] How to modify IMDB script to import large pic url

Post by Mguel »

Hi, I want to import the large pic url to ie Media Field, besides from the "normal" import of the small pic. I use this because I export to html with a small pic but use a (online) link to the large pic (as to save space but to be able to see a big pic)

I previously used a modification of an old IMDB to import the url from amazon, but it's not working very well, and I wanted to take advantage of the IMDB scrip functions:

Code: Select all

ImportLargePicture
ImportMerchandisingPicture
ImportDvdDetailsPicture
I don't have programming knowledge and previously modified scripts "empirically". I know I have to start with:

Code: Select all

if CanSetField(fieldMedia) then
begin
And end with:

Code: Select all

SetField(fieldMedia, Value);
end;
But I haven't been able to put something in the middle that works ;)

Thanks in advance,
Mguel


PS: as a off-topic comment: I recently switched to linux... tried xamc, lmc (Moviefly), GCFilms, but didn't like them... so now I'm happily using AMC with wine ;)
antp
Site Admin
Posts: 9636
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

Check the line that contains "if CanSetPicture then"
Depending on the "ImageKind" option, it calls different function.
These functions call "GetPicture".
One of the way to do what you want may be to add an extra boolean parameter to all these functions to specify if they should do a GetPicture or a SetField, and then call them in "if CanSetField(fieldMedia)" with that parameter.
Mguel
Posts: 39
Joined: 2003-01-28 10:48:14

Post by Mguel »

Thanks!

Although it's a bit chinese to me... I'll try to figure it out ;)
Mguel
Posts: 39
Joined: 2003-01-28 10:48:14

Post by Mguel »

antp wrote:Check the line that contains "if CanSetPicture then"
Depending on the "ImageKind" option, it calls different function.
These functions call "GetPicture".
One of the way to do what you want may be to add an extra boolean parameter to all these functions to specify if they should do a GetPicture or a SetField, and then call them in "if CanSetField(fieldMedia)" with that parameter.
OK, I made great progress (works for most popular movies... I believe those with amazon big pic).

As I don't know how to add the extra boolean parameter you mention, I simply changed the GetPicture with SetField on the functions for big pics (as I have always imported the small pic since I started using AMC).

Then I used the following to call (I believe) the functions:

Code: Select all

    // URL of big picture
if CanSetField(fieldMedia) then
begin
ImportLargePicture('http://us.imdb.com/gallery/ss/' + MovieNumber);
if not ImportMerchandisingPicture(PageText) then
if not ImportDvdDetailsPicture(PageText) then
ImportSmallPictureURL(PageText) then
SetField(fieldMedia,PageText);
end;
As ideally if no big pic url is fetched the small pic url would do fine, I used the "ImportSmallPicture", but as I use that by default (import small pic), I created a new function "ImportSmallPictureURL, using the same code for the normal one but replacing the GetPicture with SetField

Code: Select all

function ImportSmallPictureURL(PageText: string): Boolean; 
var
  Value: string;
begin
  Result := False;
  Value := TextBetween(PageText, '<img border="0" alt="cover" src="', '"');
  if Value <> '' then
  begin
    SetField(Value);
    Result := True;
  end;
end;
It worked for most popular/old movies, but for more "rare" movies, it game me errors (Script error in "IMDB": type mismatch at line 547 - that's the SetField of ImportSmallPictureURL function), and "Script error in "IMDB": error in statement at line 154 (ImportSmallPictureURL(PageText) then), so I simply deleted that line (after trying to fix it).

Now I stop receiving those error for the rare movies, but on the media label field it seems that I started having as a result a hole imdb webpage "<html> <head> <meta-http.... etc" what I haven't been able to fix neither.

At least it's working fine for most know movies (tried Matrix, Gladiator, LOR, Harry Potter and worked great... I get the <html> stuff for others like Oldboy, Four Brothers, etc)

I believe I'm making lot's of very basic mistakes in my programming technique, but as I told before I don't know programming so sorry if I produce nausea to someone :hihi:

Cheers,
Mguel
antp
Site Admin
Posts: 9636
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

your code should rather look like this:

Code: Select all

if CanSetField(fieldMedia) then
begin
  if not ImportLargePicture('http://us.imdb.com/gallery/ss/' + MovieNumber) then
    if not ImportMerchandisingPicture(PageText) then
      if not ImportDvdDetailsPicture(PageText) then
        ImportSmallPictureURL(PageText);
end;
you get the whole IMDB page when none of the large pictures could be found because you have put a SetField in the end. But it is not useful since the ImportPicture function already do that SetField.
Mguel
Posts: 39
Joined: 2003-01-28 10:48:14

Post by Mguel »

Thanks!

Now I not receive the complete page ;)

With some movies I still get the error:
Script error in "IMDB": type mismatch at line 547 (on the red quoted code)
Code wrote:function ImportSmallPictureURL(PageText: string): Boolean;
var
Value: string;
begin
Result := False;
Value := TextBetween(PageText, '<img border="0" alt="cover" src="', '"');
if Value <> '' then
begin

SetField(Value);
Result := True;
end;
end;
Note: I added this function just after the ImportSmallPicture function.

Thanks,
Mguel
antp
Site Admin
Posts: 9636
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

SetField(fieldMedia, Value);
Mguel
Posts: 39
Joined: 2003-01-28 10:48:14

Post by Mguel »

antp wrote:SetField(fieldMedia, Value);
GREAT!

Thanks a lot, for the help and your time... besides from making AMC you waste time helping noobs like me
Post Reply