const URLString = '
http://webservices.amazon.de/onca/xml?Service=AWSECommerceService&AWSAccessKeyId='+ YOURAMAZONID +
+ '
&AssociateTag=&Operation=ItemSearch&SearchIndex=Music&Keywords=';
function TForm1.GetCoverFromAmazon(KeyWords:
string): Boolean;
var
PICString :
String;
TestFile: PChar;
lStream: TFileStream;
ConnectionOK : Boolean;
fa: TFileAttributes;
Picfoundandloaded : Boolean;
i : Integer;
begin
try
if not assigned(XidHTTP)
then XidHTTP := TIdhttp.Create(
Nil);
Result := False;
if Keywords = '
'
then begin
Result := False;
Exit;
end;
//Suchen
if Fileexists(PrgPfad + '
temp\actualTitle.txt')
then deletefile(PrgPfad + '
temp\actualTitle.txt');
ConnectionOK := True;
lStream:=TFileStream.Create(PrgPfad + '
temp\actualTitle.txt', fmCreate
or fmShareDenyNone);
try
//Suchergebnis Seite von amazon runterladen
XidHTTP.Get(URLString + Keywords + '
&ResponseGroup=Medium', lStream);
except
ConnectionOK := False;
end;
lStream.Free;
//Suchergebnis durchchecken
if ConnectionOK
then begin
if Fileexists(PrgPfad + '
temp\actualTitle.txt')
then begin
FXMLFile := TStringList.Create;
FXMLFile.LoadFromFile(PrgPfad + '
temp\actualTitle.txt');
PICString := SearchinXML;
PICString := trim(PICString);
FXMLFile.Free;
end;
end;
if PICString = '
'
then begin
Result := False;
Exit;
end;
//File runterladen
if Fileexists(AmazonCoverPath)
then deletefile(AmazonCoverPath);
lStream:=TFileStream.Create(AmazonCoverPath, fmCreate
or fmShareDenyNone);
try
XidHTTP.Get(PICString, lStream);
Picfoundandloaded := True;
except
Picfoundandloaded := False;
end;
lStream.Free;
//File anzeigen
if Picfoundandloaded
then begin
if CopyAmazonPicToFolder
then begin
DateiInfoform.CopytoTitle(Self);
if MRPlaylist.ActivePlaylist.Cell[11,ACTINDEX].AsInteger = -1
then begin
CoverSearchPath := ExtractFilePath(ActFile);
TRenewCover.create(False);
end;
end;
fa := GetFileAttributes(AmazonCoverPath);
if readonly in fa
then begin
TestFile := PChar(AmazonCoverPath);
if SetFileAttributes(Testfile, FILE_ATTRIBUTE_NORMAL)
then Resizepicture((AmazonCoverPath), DeskDisplay.AlbumCover.Width, DeskDisplay.AlbumCover.Height);
end else Resizepicture((AmazonCoverPath), DeskDisplay.AlbumCover.Width, DeskDisplay.AlbumCover.Height);
OldCover := (AmazonCoverPath);
Deskdisplay.LoadnextCover(OldCover,False);
Result := True;
end else Result := False;
except
Result := False;
end;
end;
function TForm1.SearchInXML:
String;
var
i, x,
Imagepos,
MedPos : Integer;
St,ZZZ : WideString;
NewFile : TStringList;
begin
for i := 0
to FXMLFile.Count -1
do
begin
St := FXMLFile.Strings[i];
if Pos('
<MEDIUMIMAGE>',Uppercase(St))<>0
then begin
MedPos := Pos('
<MEDIUMIMAGE>',Uppercase(St));
for x := MedPos
to MedPos + 30
do begin
ZZZ := copy(St,x,x+2);
Imagepos := Pos('
.JPG',Uppercase(ZZZ));
Result := Copy(ZZZ,19,Imagepos-15);
Exit;
end;
end;
end;
end;