Page 1 of 1

[DE] New Amazon Script

Posted: 2005-02-19 14:41:11
by haluto
Hi antp,

in the german script for Amazon the URL-button does'nt work and that was angry. So i create :) a script based on Grasmo's Superscript and it works very well, but it imported only pics. Maybe some german users like it.

PS: AMC is super!! Sorry for my bad english!

Code: Select all

// GETINFO SCRIPTING
// AMAZON PICTURE IMPORT (large picture O N L Y)
// Created by haluto    (haluto@web.de)     19.02.2005
// Based on Grasmo's Superscript and
//   - IMDB script
//   - OMDb/IMDB script
//   - Amazon (US & DE) script
//
//  don't forget the credits of the original scripts - they did most of the work!
//
// requries Ant Movie Catalog 3.4.0

program AmazonPictureImport_DE;
 const
//Set this to False if you wish to pick the Amazon Picture manual (german or english)
  AutomaticAmazonPicPick = FALSE;
//Set this to False if you wish the script not automize everything
  TotalAutomatic = FALSE;

var
 MovieName, Amazon_num: string;
 TheMovieTitle: string;
 TheMovieAddress: string;
 OMDb_link: string;

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 GetToken(aString, SepChar: String; TokenNum: Integer):String;
 var
  Token     : string;
  StrLen    : Integer;
  TNum      : Integer;
  TEnd      : Integer;
begin
 StrLen := Length(aString);
 TNum   := 1;
 TEnd   := StrLen;
 while ((TNum <= TokenNum) and (TEnd <> 0)) do
  begin
   TEnd := Pos(SepChar,aString);
   if TEnd <> 0 then
    begin
     Token := Copy(aString,1,TEnd-1);
     Delete(aString,1,TEnd);
     TNum := TNum + 1;
    end
   else
    Token := aString;
  end;
 if TNum >= TokenNum then
  GetToken := Token
 else
  GetToken := '';
end;

function AsinParse(Line : string): string;
begin
 Result := GetToken(GetToken(Line,'.',2),Chr(34),1);
end;

procedure GetAmazonPic;
 var
  LineNr, I: Integer;
  AmazonPage, AmazonPageNOHTML: TStringList;
  AmazonPage2, AmazonPageNOHTML2: TStringList;
  TempHold, TempHold2, THolder: string;
  FoundSomething: integer;
  mov, dlink: string;
  TheLink: string;
begin
  dlink := '';
  TheLink := '';
  mov := GetField(fieldTranslatedTitle);
  if mov = '' then
   begin
    mov := GetField(fieldOriginalTitle);
    if mov = '' then
     mov := MovieName;
   end;
  FoundSomething := 1;
  AmazonPage := TStringList.Create;
  AmazonPage.Text := GetPage('http://www.amazon.de/exec/obidos/search-handle-url/index=dvd-de&field-title=' + StringReplace(UrlEncode(mov),'+', '%20'));
  PickTreeClear;
  if FindLine('Infos zu diesem Titel',AmazonPage,1) <> -1 then
   begin
    PickTreeAdd('Amazon(DE) Pictures für [' + mov + ']','');
    LineNr := FindLine('<input type="hidden" name="asin.',AmazonPage,1);
    dlink := 'http://images-eu.amazon.com/images/P/' + AsinParse(AmazonPage.Getstring(LineNr)) + '.03.LZZZZZZZ.jpg';
    PickTreeAdd(mov, dlink);
   end;
  if FindLine('Wir haben keine genauen Treffer für Ihre Suche für ',AmazonPage,1) <> -1 then
   FoundSomething := 0;
  if (FindLine('Die besten Treffer',AmazonPage,1) <> -1) OR (FindLine('Alle Ergebnisse für',AmazonPage,1) <> -1) then
   begin
    I := 1;
    PickTreeAdd('Amazon(DE) Pictures für [' + mov + ']','');
    while (i <= AmazonPage.Count-1) do
     begin
      THolder := AmazonPage.GetString(i);
      HTMLRemoveTags(THolder);
      if (Pos('/exec/obidos/ASIN/',AmazonPage.GetString(i)) <> 0) and (THolder <> '') and (Pos('Preis: EUR',AmazonPage.GetString(i)) = 0) and (Pos('THUMBZZZ',AmazonPage.GetString(i)) = 0) then
       PickTreeAdd(THolder,'http://images-eu.amazon.com/images/P/' + GetToken(AmazonPage.GetString(i),'/',5) + '.03.LZZZZZZZ.jpg');
      if THolder = mov then
       dlink := 'http://images-eu.amazon.com/images/P/' + GetToken(AmazonPage.GetString(i),'/',5) + '.03.LZZZZZZZ.jpg';
      i := i + 1;
     end
   end;
  If AutomaticAmazonPicPick and (dlink <> '') then
   begin
    GetPicture(dlink,False);
    exit;
   end;
  mov := GetField(fieldOriginalTitle);
  if mov = '' then
   begin
    mov := GetField(fieldTranslatedTitle);
    if mov = '' then
     mov := MovieName;
   end;
  AmazonPage2 := TStringList.Create;
  AmazonPage2.Text := GetPage('http://www.amazon.com/exec/obidos/search-handle-url/index=dvd&field-title=' + StringReplace(UrlEncode(GetField(fieldOriginalTitle)),'+', '%20'));
  AmazonPageNOHTML2 := TStringList.Create;
  AmazonPageNOHTML2.Text := AmazonPage2.Text;
  TempHold2 := AmazonPageNOHTML2.Text;
  HTMLRemoveTags(TempHold2);
  AmazonPageNOHTML2.Text := TempHold2;
  if FindLine('Amazon.com: DVD:',AmazonPage2,1) <> -1 then
   begin
    LineNr := FindLine('<input type="hidden" name="asin.',AmazonPage2,1);
    if FoundSomething = 0 then
     begin
      GetPicture('http://images.amazon.com/images/P/' + AsinParse(AmazonPage2.Getstring(LineNr)) + '.01.LZZZZZZZ.jpg', false);
      exit;
     end
    else
     begin
      PickTreeAdd('Amazon(US) Pictures für [' + mov + ']','');
      PickTreeAdd(mov, 'http://images.amazon.com/images/P/' + AsinParse(AmazonPage2.Getstring(LineNr)) + '.01.LZZZZZZZ.jpg');
     end;
   end;
   if FindLine('DVD Search Results: we were unable to find exact matches for your search for',AmazonPage,1) <> -1 then
    if FoundSomething = 0 then
     exit;
   if (FindLine('Below are results for',AmazonPage2,1) <> -1) OR (FindLine('All results',AmazonPage2,1) <> -1) OR (FindLine('Most popular results for',AmazonPage2,1) <> -1) then
    begin
     I := 1;
      PickTreeAdd('Amazon(US) Pictures für [' + mov + ']','');
     while (i <= AmazonPage2.Count-1) do
      begin
       THolder := AmazonPage2.GetString(i);
       HTMLRemoveTags(THolder);
       if (Pos('/exec/obidos/ASIN/',AmazonPage2.GetString(i)) <> 0) and (THolder <> '') and (Pos('Buy new',AmazonPage2.GetString(i)) = 0) and (Pos('Used & new from',AmazonPage2.GetString(i)) = 0) and (Pos('THUMBZZZ',AmazonPage2.GetString(i)) = 0) then
        begin
         PickTreeAdd(THolder,'http://images.amazon.com/images/P/' + GetToken(AmazonPage2.GetString(i),'/',5)+ + '.01.LZZZZZZZ.jpg');
         if THolder = mov then
          dlink := 'http://images.amazon.com/images/P/' + GetToken(AmazonPage2.GetString(i),'/',5)+ + '.01.LZZZZZZZ.jpg';
        end;
       if (Pos('/exec/obidos/tg/detail/',AmazonPage2.GetString(i)) <> 0) and (THolder <> '') and (Pos('Buy new',AmazonPage2.GetString(i)) = 0) and (Pos('Used & new from',AmazonPage2.GetString(i)) = 0) and (Pos('THUMBZZZ',AmazonPage2.GetString(i)) = 0) and (Pos('http://www.amazon.com',AmazonPage.GetString(i)) = 0) and (Pos('In-store Pickup',AmazonPage.GetString(i)) = 0) then
        begin
         PickTreeAdd(THolder,'http://images.amazon.com/images/P/' + GetToken(AmazonPage2.GetString(i),'/',7)+ + '.01.LZZZZZZZ.jpg');
         if THolder = mov then
          dlink := 'http://images.amazon.com/images/P/' + GetToken(AmazonPage2.GetString(i),'/',7)+ + '.01.LZZZZZZZ.jpg';
        end;
       i := i + 1;
      end
    end
  If AutomaticAmazonPicPick and (dlink <> '') then
   begin
    GetPicture(dlink,False);
    exit;
   end;
  if TotalAutomatic and (dlink <> '') then
   GetPicture(dlink,False)
  else
   if PickTreeExec(THolder) then
    GetPicture(THolder,False);
end;

begin
 if CheckVersion(3,4,0) then
   begin
   OMDb_link := '';
   TheMovieTitle:='';
   TheMovieAddress:='';
   MovieName := GetField(fieldTranslatedTitle);
   if MovieName = '' then
    begin
     MovieName := GetField(fieldOriginalTitle);
     if MovieName = '' then
      Input('Movie Title', 'Bitte Titel eingeben :', MovieName);
    end;
   GetAmazonPic;
   DisplayResults;
  end 
 else
  ShowMessage('Dieses Script benötigt eine neuere Version von Ant Movie Catalog (mindestens Version 3.3.0)');
end.

Posted: 2005-02-19 14:59:41
by antp
Thanks.
so this replaces amazon.de.ifs if I understood it well?

[DE] New Amazon Script

Posted: 2005-02-19 15:48:34
by haluto
Yes, so it is

mfg

Posted: 2005-03-08 11:53:44
by Morgensonne
Hi... thanks for porting this script to the german Amazon, but why do i find a title myself at amazon.de and the script only shows me a result from amazon.com? I typed the movietitle exactly as i did in amzon search engine.

Thanks

Posted: 2005-03-09 21:49:22
by haluto
Hallo Morgensonne,
wenn ich Dich richtig verstanden habe, findest Du bei einer manuellen Suche einen Titel bei amazon.de und das Script zeigt nur ein Ergebnis von amazon.com?
Ist mir noch nicht aufgefallen, ich habe einfach Teile der genannten Scripts zusammengefügt und so lange probiert bis bei mir alles geklappt hat. ;)
Selbst programmieren kann ich leider nicht, aber für meine Bedürfnisse reicht das Script. Vielleicht überarbeitet ja jemand das Script der was davon versteht.

Gruß haluto