Script From 3.4.3 to 3.5

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
-xD-
Posts: 27
Joined: 2004-09-09 15:47:49
Location: Ukraine
Contact:

Script From 3.4.3 to 3.5

Post by -xD- »

can any one remake this script to work on amc 3.5
and add audio picture import like in second script! it ver important 4 me!
// GETINFO SCRIPTING
// CMDB import by Peter V.

program CMDB;
var
AlbumName: string;

// simple string procedures
function StringReplaceAll(S, Old, New: string): string;
begin
while Pos(Old, S) > 0 do
S := StringReplace(S, Old, New);
Result := S;
end;
procedure CutAfter(var Str: string; Pattern: string);
begin
Str := Copy(str, Pos(Pattern, Str) + Length(Pattern), Length(Str));
end;
procedure CutBefore(var Str: string; Pattern: string);
begin
Str := Copy(Str, Pos(Pattern, Str), Length(Str));
end;

// Loads and analyses page from internet (list of movies or direct hit)
procedure AnalyzePage(Address: string);
var
Page: TStringList;
begin
Page := TStringList.Create;
Page.Text := GetPage(Address);
// movie list
if Pos('<!-- START ITEM -->', Page.Text) > 0 then
begin
PickTreeClear;
PickTreeAdd('Search results', '');
AddAlbumsTitles(Page);
if PickTreeExec(Address) then
AnalyzePage(Address);
// refine search
end
else
if Pos('search could not be completed', Page.Text) > 0 then
begin
ShowMessage('We were unable to find a match. Please refine your search.');
if Input('CDDB Import', 'Enter the title of the album:', AlbumName) then
begin
AlbumName := StringReplace(AlbumName, ' ', '+');
AnalyzePage('http://www.gracenote.com/music/search-a ... st=&qdisc=' + AlbumName +'&qtrack=&n=50&x=0&y=0');
end
// direct hit
end
else
begin
SetField(FieldURL, Address);
AnalyzeAlbumPage(Page)
end;
end;

// Extracts movie details from page
procedure AnalyzeAlbumPage(MoviePage: TStringList);
var
Page: string;
Value,Address: string;
begin
Page := MoviePage.Text;

// Страна США
Value := 'США';
SetField(fieldCountry, Value);

// Тип Записи
// Value := 'CD-ROM';
// SetField(fieldMediaType, Value);

// Артист / Альбом
SetField(fieldOriginalTitle, GetStringFromHTML(Page, 'cddb_returns', '<b>', '</b><br>'));

// Название Альбома
Value := GetStringFromHTML(Page, '<title>', '', '</title>');
Value := StringReplace(Value, 'Gracenote: Albums - ', '');
SetField(fieldProducer, Value);

// Исполнитель
SetField(fieldDirector, GetStringFromHTML(Page, 'cddb_main_area', 'Artist Info : ', '</a>'));

// Год
SetField(fieldYear, GetStringFromHTML(Page, 'cddb_main_area', 'Year: ', '<br>'));

// Лейбл
Value := GetStringFromHTML(Page, 'cddb_main_area', 'Label: ', '<');
if Pos('main_area', Value) > 0 then
Value := '';
SetField(fieldSource, Value );

// Трек Лист
Value := GetStringFromHTML(Page, 'cddb_main_area', 'Track Title', '</table>');
Value := StringReplace(Value, ' 1.', '1.');
Value := StringReplace(Value, '.', '. ');
// Value := 'Трек Лист :'+ Value; - Для добавления своего в базу...
SetField(fieldActors, Value);

// Image
//Value := GetStringFromHTML(Page, 'http://images.amazon.com/', '', '"');
//if Length(Value) > 0 then GetPicture(Value, False);

DisplayResults;
end;

// Adds movie titles from search results to tree
procedure AddAlbumsTitles(ResultsPage: TStringList);
var
Page: string;
MovieTitle, MovieAddress: string;
begin
Page := ResultsPage.Text;
// Every movie entry begins with string "<!-- START ITEM -->"
while Pos('<!-- START ITEM -->', Page) > 0 do begin
CutBefore(Page, '<!-- START ITEM -->');
MovieAddress := 'http://gracenote.com' + GetStringFromHTML(Page, 'A HREF="', '', '" >');
MovieAddress := StringReplace(MovieAddress, 'A HREF="', '');
MovieTitle := GetStringFromHTML(Page, '<A', '', '</A>');
CutAfter(Page, '<!-- END ITEM -->');
// add movie to list
PickTreeAdd(MovieTitle, MovieAddress);
end;
end;

// Extracts single movie detail (like director, genre) from page
function GetStringFromHTML(Page, StartTag, CutTag, EndTag: string): string;
begin
Result := '';
// recognition tag - if present, extract detail from page, otherwise assume detail is not present
if Pos(StartTag, Page) > 0 then begin
CutBefore(Page, StartTag);
// optional cut tag helps finding right string in html page
if Length(CutTag) > 0 then
CutAfter(Page, CutTag);
// movie detail copied with html tags up to end string
Result := Copy(Page, 0, Pos(EndTag, Page) - 1);
// remove html tags and decode html string
HTMLRemoveTags(Result);
Result := StringReplace(Result, '<br>', '');
HTMLDecode(Result);
Result := StringReplace(Result, 'Downloads Available', '');
// ShowMessage('DEBUG: GetStringFromHTML - StartTag "'+StartTag+'", CutTag "'+CutTag+'", EndTag "'+EndTag+'", Result "'+Result+'" ___ '+Page);
end;
end;

procedure RemovePronoun(var Str: string);
var
i: Integer;
s: string;
c: char;
begin
// remove pronouns
if (Copy(Str, 0, 2) = 'L ') or (Copy(Str, 0, 2) = 'A ') then
Str := Copy(Str, 3, Length(Str) - 2)
else if (Copy(Str, 0, 3) = 'Le ') or (Copy(Str, 0, 3) = 'La ') or (Copy(Str, 0, 3) = 'Un ') then
Str := Copy(Str, 4, Length(Str) - 3)
else if (Copy(Str, 0, 4) = 'Les ') or (Copy(Str, 0, 4) = 'Une ') or (Copy(Str, 0, 4) = 'The ') then
Str := Copy(Str, 5, Length(Str) - 4);

// remove non-letters, non-digits and non-spaces
s := '';
for i := 1 to Length(Str) do begin
c := StrGet(Str, i);
if ((c<'a') or (c>'z')) and
((c<'A') or (c>'Z')) and
((c<'0') or (c>'9')) and
(c<>' ') then
else
s := s + Copy(Str, i, 1);
end;
Str := s;
end;

begin
if CheckVersion(3,4,0) then
begin
AlbumName := GetField(fieldOriginalTitle);
if AlbumName = '' then
AlbumName := GetField(fieldTranslatedTitle);
if Input('CDDB Import', 'Enter the title of the album:', AlbumName) then
begin
AlbumName := StringReplace(AlbumName, ' ', '+');
AnalyzePage('http://www.gracenote.com/music/search-a ... st=&qdisc=' + AlbumName +'&qtrack=&n=50&x=0&y=0');
end;
end
else
ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.0)');
end.
// GETINFO SCRIPTING
// Amazon.fr CD Audios

(***************************************************
* Script d'importation pour : *
* AMAZON FRANCE , http://www.amazon.fr *
* *
* Script by Chunky *
* *
* A utiliser avec Ant Movie Catalog 3.4.0 *
* www.ant.be.tf/moviecatalog ··· www.buypin.com *
* *
* The source code of the script can be used in *
* another program only if full credits to *
* script author and a link to Ant Movie Catalog *
* website are given in the About box or in *
* the documentation of the program *
***************************************************)

program AMAZON_FR;

//Paramиtres du script
const

// Mettre les valeurs а True pour importer les champs, ou False pour ne pas en tenir compte
ConfirmTitre = True; // False : ne demande pas de confirmation du titre avant recherche
TempsPause = 500; // 1000 = 1 Seconde (permet d'йviter les timeout en cas de saturation serveur)
ImportImage = True; // False : n'importe pas d'image
ImportGrandeImage = True; // False : petite image importйe
ImportPistes = True; // False : n'importe pas la liste des chansons
ImportAlbum = True; // False : n'importe pas le titre de l'album
ImportInterprete = True; // False : n'importe pas l'interprete
ImportCommentaire = True; // False : n'importe pas le commentaire
ImportDate = True; // False : n'importe pas la date de parution
ImportAddImport = False; // False : remplace le contenu des champs par les donnйes importйes

var
MusicName: 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;

procedure AnalyzePage(Address: string);
var
Page: TStringList;
LineNr: Integer;

begin
Sleep(TempsPause); // Attente X seconde : Evite les timeout sur le serveur
Page := TStringList.Create;
Page.Text := GetPage(Address);
if pos('Sur ce CD', Page.Text) > 0 then
begin
AnalyzeMoviePage(Page);
end
else

if pos('satisfaisante pour votre recherche sur', Page.Text) > 0 then
begin
ShowMessage('Aucun Film Trouvй pour : ' + MusicName);
end else

if pos('Les articles les plus recherchés correspondant à', Page.Text) > 0 then
begin
PickTreeClear;
LineNr := 0;
LineNr := FindLine('résultats au total pour', Page, LineNr);
if LineNr > -1 then
begin
//PickTreeAdd('Films Trouvйs :', '');
PickTreeAdd('Films Trouvйs pour ' + MusicName + ' :', '');
AddMoviesTitles(Page, LineNr);
end;
if PickTreeExec(Address) then
AnalyzePage(Address);
end else

begin
PickTreeClear;
LineNr := 0;
LineNr := FindLine('résultats au total pour', Page, LineNr);
if LineNr > -1 then
begin
//PickTreeAdd('Films Trouvйs :', '');
PickTreeAdd('Films Trouvйs pour ' + MusicName + ' :', '');
AddMoviesTitles(Page, LineNr);
end;
if PickTreeExec(Address) then
AnalyzePage(Address);
end;

Page.Free;
end;

procedure AnalyzeMoviePage(Page: TStringList);
var
Line, Value, Value2, FullValue: string;
LineNr: Integer;
BeginPos, EndPos: Integer;
Dummy: string;


begin

// Image
if ImportImage then
begin
LineNr := FindLine('<a href="http://images-eu.amazon.com/images/P/', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('src="', Line) + 4;
Delete(Line, 1, BeginPos);
EndPos := pos('"', Line);
Value := copy(Line, 1, EndPos - 1);
if ImportGrandeImage then
Value := StringReplace(Value, 'MZZZZZZZ', 'LZZZZZZZ'); // Change l'URL pour prendre la grande au lieu de la petite image
Sleep(TempsPause*3); // Attente 2X seconde : Evite les timeout sur le serveur
GetPicture(Value, False); // False = stocke l'image dans la base
end;
end;


DisplayResults;
end;

procedure AddMoviesTitles(Page: TStringList; var LineNr: Integer);
var
Line: string;
MovieTitle, MovieAddress: string;
StartPos: Integer;
StartImg: Integer;
StartLst: Integer;
LastLine: Integer;

begin
repeat
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
LastLine := Page.count;
StartPos := pos('<a href=/exec/obidos/ASIN/', Line);
StartImg := pos('<img src="http://images-eu.amazon.com/images/', Line);
StartLst := pos('</a>', Line);
if StartPos+StartImg+StartLst < StartPos+StartPos+StartPos-StartImg-StartLst then
begin
Startpos := Startpos + 9;
MovieAddress := copy(Line, StartPos, pos('qid', Line) - StartPos);
StartPos := pos('<b>', Line) + 3;
MovieTitle := copy(Line, StartPos, (StartPos + 150)- StartPos);
HTMLDecode(Movietitle);
PickTreeAdd(MovieTitle, 'http://www.amazon.fr/' + MovieAddress);
end;
until (LineNr > Lastline);
end;

begin
if CheckVersion(3,4,0) then
begin
MusicName := GetField(fieldTranslatedTitle);
if MusicName = '' then
MusicName := GetField(fieldOriginalTitle);

if ConfirmTitre then
begin
if Input('Amazon.fr Import', 'Entrer le titre de l artiste ou de l album... :', MusicName) then
begin
AnalyzePage('http://www.amazon.fr/exec/obidos/search ... MusicName));
end;
end else
begin
AnalyzePage('http://www.amazon.fr/exec/obidos/search ... MusicName));
end;
end else
ShowMessage('Ce script requiert une version plus rйcente de Ant Movie Catalog (au moins la version 3.4.0)');
end.
kolia
Posts: 56
Joined: 2003-02-19 16:02:46

Post by kolia »

why don't you use the converter found here
for both scripts and only check to import picture from second script?
It would be faster than waiting for somebody else to fix it...
-xD-
Posts: 27
Joined: 2004-09-09 15:47:49
Location: Ukraine
Contact:

Post by -xD- »

kolia wrote:why don't you use the converter found here
for both scripts and only check to import picture from second script?
It would be faster than waiting for somebody else to fix it...
i need to make from this 2 scripts 1!
to take a info and picture
i cant do it
coz i dont andestand nothing in scripting :((
kolia
Posts: 56
Joined: 2003-02-19 16:02:46

Post by kolia »

What I meant was:
1) use the converter to convert scripts to 3.5
2) import with script 1 (unchecking the picture field -just for faster import)
3) import with script 2 checking only the picture field
Post Reply