amazon.sco

Use this forum for everything concerning script usage
Skunky
Newbie
Newbie
Posts: 14
Joined: Sat Apr 06, 2019 3:57 pm

amazon.sco

Post by Skunky »

has anybody ever tried to make an amazon.sco similar to the amg.sco? there are just some things that allmusic doesn't have... that amazon does...

User avatar
jtclipper
Administrator
Administrator
Posts: 768
Joined: Tue Aug 10, 2010 12:04 pm

Re: amazon.sco

Post by jtclipper »

There was no need for that until recently when Amazon decided to drop support for 3rd party application using their API for free.
I might do something about it, just point me to a few links so i can investigate a bit more

Skunky
Newbie
Newbie
Posts: 14
Joined: Sat Apr 06, 2019 3:57 pm

Re: amazon.sco

Post by Skunky »

Ok... here's one that amg that doesn't have, but amazon does....

https://www.amazon.com/Glow-Deluxe-Bret ... 065&sr=8-4

you can see they have it in different formats, streaming, mp3, and audio cd. each one gives a slightly different page, but they all have the important info... artist, album, track, title, duration...

not everything on amazon has all the info, or is in all formats though....

https://www.amazon.com/Hotel-Bible-Aaro ... way&sr=8-2

for example, only comes in "streaming" flavor

there are other things that only come as "audio cd", but I can't find anything right now like that. I seem to recall that they're mostly older stuff.

thanks for a great program! it can do so many things I didn't even know I wanted. :)

User avatar
jtclipper
Administrator
Administrator
Posts: 768
Joined: Tue Aug 10, 2010 12:04 pm

Re: amazon.sco

Post by jtclipper »

It seems that Amazon does not follow a simple pattern on their product pages but something can be worked out, not for all albums but at least for most, hopefully.
Will have a look at it in the next couple of weeks

Skunky
Newbie
Newbie
Posts: 14
Joined: Sat Apr 06, 2019 3:57 pm

Re: amazon.sco

Post by Skunky »

"most" is better than "none" :) ;) ;D

and every little bit helps.

User avatar
jtclipper
Administrator
Administrator
Posts: 768
Joined: Tue Aug 10, 2010 12:04 pm

Re: amazon.sco

Post by jtclipper »

Here is a script that will work on digital album formats (e.g mp3)

Code: Select all

{https://www.amazon.com}

{?
 TITLE=FORM;field-keywords=%:str
 ALBUM=FORM;field-keywords=%:str
 ARTIST=FORM;field-keywords=%:str
/?}


Program Allmusic;
const LIST_SEP = ',';
var
  slMain: TStringList;
  iPos,iRow: integer;
  sTmp: String;

  //---
  procedure GetImage;
  var
    iPos: integer;
    sLine: string;
  begin
    if on_FindRow( iRow, 0, '"digitalMusicProductImage_feature_div"', slMain ) or
       on_FindRow( iRow, 0, '<div class="imgTagWrapper"', slMain ) then begin
       if on_FindRow( iRow, 0, 'alt="', slMain ) then begin
          sLine := slMain.Strings[ iRow ];
          iPos := Pos( 'src="', sLine );
          if iPos > 0 then begin
             sTmp := Copy( sLine, iPos + 5, 99999 );
             iPos := Pos( '"', sTmp );
             if iPos > 0 then begin
                sTmp := Copy( sTmp, 1, iPos -1 );
                on_setPicture( sTmp );
             end;
          end;
       end;
    end;
    iRow := 0;
  end;

  //---
  function GetListing: string;
  begin
    result := Trim( on_cleanHTMLLine( AnsiReplaceText( slMain[ iRow ], '</a>', '</a>' + LIST_SEP ) ) );
    while Pos( '  ', result ) > 0 do result :=  AnsiReplaceText( result, '  ', ' ' );
    result := AnsiReplaceText( result, LIST_SEP + ' ', LIST_SEP );
    if Copy( result, Length( result ), 1 ) = LIST_SEP then result := Copy( result, 1, Length( result ) - 1 );
  end;

  //---
  procedure GetTracks;
  var
    sID, sTrack, sComposer, sPerformer, sTitle, sTime: string;
    iTrack: integer;
  begin

    iTrack := 0;
    while on_FindRow( iRow, 0, '/ref=dm_ws_tlw_trk', slMain ) do begin

       //same track ?
       if Pos( '/ref=dm_ws_tlw_trk' + IntToStr( iTrack ), slMain[ iRow ] ) = 0 then begin

          sID := Copy( slMain[ iRow ], Pos( 'href="/dp/', slMain[ iRow ] ) + 10, 999 );
          sID := Copy( sID, 1,  Pos( '/ref=dm_ws_tlw_trk', sID ) - 1 ) ;

          Inc( iTrack );
          sTrack := IntToStr( iTrack );
          sTitle := on_cleanHTMLLine( slMain[ iRow ] );

          //Track artist?
          if on_FindRow( iRow, 0, '/ref=dm_ws_tlw_art' + sTrack + '"', slMain ) then begin
             sPerformer := on_cleanHTMLLine( slMain[ iRow ] );
          end;
          //Duration
          if on_FindRow( iRow, 0, '"dmusic_tracklist_duration_' + sID + '"', slMain ) then begin
             sTime := slMain[ iRow + 3 ];
          end;

          if on_getIsVarious and (sPerformer <> '') then  sTitle := sPerformer + ' / ' + sTitle;

          on_addTrack( sTrack, sTitle, sComposer, sTime );

       end;

       Inc(iRow);

    end;
  end;

  //---
//  procedure GetReview;
//  begin
//    on_setComment( on_cleanHTMLMultiLine( slMain[ iRow + 2 ] ) );
//  end;

begin

  on_Init(1); // comment this out if you wish to retain current values
  slMain := TStringList.Create;

  try

    iRow := 0;
    on_loadHTML( slMain ); // load the actual page to a stringlist
    //slMain.SaveToFile( 'c:\1.htm' ); //uncomment if you want to see the HTML code

    // image if any
    GetImage;

    // album
    if on_FindRow( iRow, 0, '"dmusicProductTitle_feature_div"', slMain) then begin
       if on_FindRow( iRow, 0, '<h1 class="', slMain) then begin
          on_setAlbum( on_cleanHTMLLine( slMain[ iRow ] ) );
       end;
       iRow := 0;
    end;
    //artist
    if on_FindRow( iRow, 0, '"ProductInfoArtistLink"', slMain) then begin
       sTmp := on_cleanHTMLLine( slMain[ iRow ] );
       //if Copy( sTmp, 0, 4) = 'The ' then sTmp := Copy( sTmp, 5, 9999 ); // uncomment to get rid of THE <artist name>
       on_setArtist ( sTmp );
       if on_getIsVarious then on_setAlbumArtist ( sTmp );
       iRow := 0;
    end;
    //year
    if on_FindRow( iRow, 0, '"ProductInfoReleaseDate"', slMain) then begin
       on_setYear( on_cleanHTMLLine( slMain[ iRow+1 ] ) );
       iRow := 0;
    end;
    //label
    if on_FindRow( iRow, 0, '<strong>Label:</strong>', slMain) then begin
       sTmp := on_cleanHTMLLine( slMain[ iRow ] );
       on_setLabel( Copy( sTmp, 8, 9999 ) );
       iRow := 0;
    end;
    //genre
    if on_FindRow( iRow, 0, '<strong>Genres:</strong>', slMain) then begin
       if on_FindRow( iRow, 0, '<li><a href="', slMain) then begin
          sTmp := GetListing;
          iPos := Pos( ',', sTmp );
          if iPos > 0 then begin
             on_setGenre( Copy( sTmp, 1, iPos -1  ) );
             on_setStyles( sTmp );
          end else begin
             on_setGenre( sTmp );
          end;
       end;
       iRow := 0;
    end;
    //type
    if on_FindRow( iRow, 0, '<li><b>Format:</b>', slMain) then begin
       sTmp := Trim( Copy( GetListing, 8, 999 ) );
       on_setType( sTmp );
       iRow:=0;
    end;

    // Tracks
    if on_FindRow( iRow, 0, '"dmusic_tracklist_header_default_message"', slMain ) then begin
       GetTracks;
       iRow:=0;
    end;

    //Review
    //if on_FindRow( iRow, 0, '?????"', slMain ) then GetReview;

  finally
    slMain.Free;
    sys_SetStatusText( 0, 'Done' );
  end;

end.

Skunky
Newbie
Newbie
Posts: 14
Joined: Sat Apr 06, 2019 3:57 pm

Re: amazon.sco

Post by Skunky »

ok, so. the first album I try, I can find it on amazon (yay!) but when I hit "grab" the only thing it gets is the "Publisher" field.
thinking it's something odd, I try another couple of other things... it'll grab the Publisher every time I pick the right format (ie, don't pick audio cd or vinyl) but that's all it grabs.
There's also a warning at the top of the page that says "Amazon no longer supports Internet Explorer 6 or 7, and the site may not behave as expected. Please upgrade to a newer browser."
Except I've already got IE11...
removing IE11 and reverting to IE8 gives the same results... warning message, no happiness..
same results with my win10 install as win7...

if I hit "copy to clipboard" all I get is the warning, above, instead of the review....

so do I need to upgrade or downgrade something?
how do I troubleshoot this?
thanks!

User avatar
jtclipper
Administrator
Administrator
Posts: 768
Joined: Tue Aug 10, 2010 12:04 pm

Re: amazon.sco

Post by jtclipper »

Please try to add the following registry setting, since for some reason,Windows 10 is using an outdated rendering engine version or reports a wrong one to the requesting web site.

Code: Select all

KEY = HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION
VALUE REG_DWORD= TheGodFather.exe
add 11001 as decimal

Skunky
Newbie
Newbie
Posts: 14
Joined: Sat Apr 06, 2019 3:57 pm

Re: amazon.sco

Post by Skunky »

WOO HOO! that fixed it. Thank you SO MUCH!

Skunky
Newbie
Newbie
Posts: 14
Joined: Sat Apr 06, 2019 3:57 pm

Re: amazon.sco

Post by Skunky »

So this worked quite well, for a while.
I don't know what amazon changed, but after a long hiatus, I've got another batch of things to tag, and all I can get is the album name and the cover art pic... I uncommented line 105, to make it save the html file that it pulls.. .and it looks like everything is there, but it's not getting into where it needs to go.

I know enough to look at log files, but I apparently don't know enough to figure out where this is broken.

User avatar
jtclipper
Administrator
Administrator
Posts: 768
Joined: Tue Aug 10, 2010 12:04 pm

Re: amazon.sco

Post by jtclipper »

Here is the script with a few changes it works with a few albums i tested

Code: Select all

{https://www.amazon.com}

{?
 TITLE=FORM;field-keywords=%:str
 ALBUM=FORM;field-keywords=%:str
 ARTIST=FORM;field-keywords=%:str
/?}


Program Allmusic;
const LIST_SEP = ',';
var
  slMain: TStringList;
  iPos,iRow: integer;
  sTmp: String;

  //---
  procedure GetImage;
  var
    iPos: integer;
    sLine: string;
  begin
    if on_FindRow( iRow, 0, 'digitalMusicProductImage_feature_div', slMain ) or
       on_FindRow( iRow, 0, '<div class="imgTagWrapper"', slMain ) then begin
       if on_FindRow( iRow, 0, 'alt="', slMain ) then begin
          sLine := slMain.Strings[ iRow ];
          iPos := Pos( 'src="', sLine );
          if iPos > 0 then begin
             sTmp := Copy( sLine, iPos + 5, 99999 );
             iPos := Pos( '"', sTmp );
             if iPos > 0 then begin
                sTmp := Copy( sTmp, 1, iPos -1 );
                on_setPicture( sTmp );
             end;
          end;
       end;
    end;
    iRow := 0;
  end;

  //---
  function GetListing: string;
  begin
    result := Trim( on_cleanHTMLLine( AnsiReplaceText( slMain[ iRow ], '</a>', '</a>' + LIST_SEP ) ) );
    while Pos( '  ', result ) > 0 do result :=  AnsiReplaceText( result, '  ', ' ' );
    result := AnsiReplaceText( result, LIST_SEP + ' ', LIST_SEP );
    if Copy( result, Length( result ), 1 ) = LIST_SEP then result := Copy( result, 1, Length( result ) - 1 );
  end;

  //---
  procedure GetTracks;
  var
    sID, sTrack, sComposer, sPerformer, sTitle, sTime: string;
    iTrack: integer;
  begin

    iTrack := 0;
    while on_FindRow( iRow, 0, '/ref=dm_ws_tlw_trk', slMain ) do begin

       //same track ?
       if Pos( '/ref=dm_ws_tlw_trk' + IntToStr( iTrack ), slMain[ iRow ] ) = 0 then begin

          sID := Copy( slMain[ iRow ], Pos( 'href="/dp/', slMain[ iRow ] ) + 10, 999 );
          sID := Copy( sID, 1,  Pos( '/ref=dm_ws_tlw_trk', sID ) - 1 ) ;

          Inc( iTrack );
          sTrack := IntToStr( iTrack );
          sTitle := on_cleanHTMLLine( slMain[ iRow ] );

          //Track artist?
          if on_FindRow( iRow, 0, '/ref=dm_ws_tlw_art' + sTrack + '"', slMain ) then begin
             sPerformer := on_cleanHTMLLine( slMain[ iRow ] );
          end;
          //Duration
          if on_FindRow( iRow, 0, '"dmusic_tracklist_duration_' + sID + '"', slMain ) then begin
             sTime := slMain[ iRow + 3 ];
          end;

          if on_getIsVarious and (sPerformer <> '') then  sTitle := sPerformer + ' / ' + sTitle;

          on_addTrack( sTrack, sTitle, sComposer, sTime );

       end;

       Inc(iRow);

    end;
  end;

  //---
//  procedure GetReview;
//  begin
//    on_setComment( on_cleanHTMLMultiLine( slMain[ iRow + 2 ] ) );
//  end;

begin

  on_Init(1); // comment this out if you wish to retain current values
  slMain := TStringList.Create;

  try

    iRow := 0;
    on_loadHTML( slMain ); // load the actual page to a stringlist
    slMain.SaveToFile( 'c:\1.htm' ); //uncomment if you want to see the HTML code

    // image if any
    GetImage;

    // album
    if on_FindRow( iRow, 0, 'dmusicProductTitle_feature_div', slMain) then begin
       if on_FindRow( iRow, 0, '<h1 class="', slMain) then begin
          on_setAlbum( on_cleanHTMLLine( slMain[ iRow ] ) );
       end;
       iRow := 0;
    end;
    //artist
    if on_FindRow( iRow, 0, 'ProductInfoArtistLink', slMain) then begin
       sTmp := on_cleanHTMLLine( slMain[ iRow ] );
       //if Copy( sTmp, 0, 4) = 'The ' then sTmp := Copy( sTmp, 5, 9999 ); // uncomment to get rid of THE <artist name>
       on_setArtist ( sTmp );
       if on_getIsVarious then on_setAlbumArtist ( sTmp );
       iRow := 0;
    end;
    //year
    if on_FindRow( iRow, 0, 'ProductInfoReleaseDate', slMain) then begin
       on_setYear( on_cleanHTMLLine( slMain[ iRow+1 ] ) );
       iRow := 0;
    end;
    //label
    if on_FindRow( iRow, 0, '<strong>Label:</strong>', slMain) then begin
       sTmp := on_cleanHTMLLine( slMain[ iRow ] );
       on_setLabel( Copy( sTmp, 8, 9999 ) );
       iRow := 0;
    end;
    //genre
    if on_FindRow( iRow, 0, '<strong>Genres:</strong>', slMain) then begin
       if on_FindRow( iRow, 0, '<li><a href="', slMain) then begin
          sTmp := GetListing;
          iPos := Pos( ',', sTmp );
          if iPos > 0 then begin
             on_setGenre( Copy( sTmp, 1, iPos -1  ) );
             on_setStyles( sTmp );
          end else begin
             on_setGenre( sTmp );
          end;
       end;
       iRow := 0;
    end;
    //type
    if on_FindRow( iRow, 0, '<li><b>Format:</b>', slMain) then begin
       sTmp := Trim( Copy( GetListing, 8, 999 ) );
       on_setType( sTmp );
       iRow:=0;
    end;

    // Tracks
    if on_FindRow( iRow, 0, 'dmusic_tracklist_header_default_message', slMain ) then begin
       GetTracks;
       iRow:=0;
    end;

    //Review
    //if on_FindRow( iRow, 0, '?????"', slMain ) then GetReview;

  finally
    slMain.Free;
    sys_SetStatusText( 0, 'Done' );
  end;

end.

Skunky
Newbie
Newbie
Posts: 14
Joined: Sat Apr 06, 2019 3:57 pm

Re: amazon.sco

Post by Skunky »

ummmmmmmmmmm, behaves exactly the same way, gets the album art and the album name, but that's all...
the 1.htm file that each generate is exactly the same. what am I missing here?

User avatar
jtclipper
Administrator
Administrator
Posts: 768
Joined: Tue Aug 10, 2010 12:04 pm

Re: amazon.sco

Post by jtclipper »

Are you sure it is a digital music album ?
If it is send me the url and the html file

Skunky
Newbie
Newbie
Posts: 14
Joined: Sat Apr 06, 2019 3:57 pm

Re: amazon.sco

Post by Skunky »

ok. the 1.htm file is 527k, do you want me to paste it somewhere, or? I'm trying "clint black out of sane" right now...

User avatar
jtclipper
Administrator
Administrator
Posts: 768
Joined: Tue Aug 10, 2010 12:04 pm

Re: amazon.sco

Post by jtclipper »

You can mail it to me

Post Reply