I rewrote Allmusic script that gave too much results for my searches.
Now it shows only albums who contain the exact string search.
i.e. with allmusic classic script if you look for 'Common One' you will se all albums containing 'Common' or 'One' (a lot)!
with my script you obtain the albums containing 'Common One'.
Here you are the script:
Code: Select all
(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[Infos]
Authors=Frenchfrog2 - AMCMP3 changes by sracer, exact search by Fulvio53s03
Title=AllMusic - Exact Album
Description=import artist and/or album
Site=http://www.allmusic.com
Language=EN
Version=1.0
Requires=3.5.0
Comments=this script is based on the script AllGame from Scorpion7552.
License=* 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 |
GetInfo=1
[Options]
AlbumOpt=2|2|1=search for artist|2=search for album|3=search for song
Mode=0|0|0=normal mode|1=batch mode (url)
***************************************************)
// needs the following units
// StringUtils1.pas, StringUtils7552.pas
//
program AllMusic;
uses
StringUtils7552, Stringutils1;
const
AllMusicUrl = 'http://www.allmusic.com'; // base url
batchlogfic = 'c:\amc_AllGame_batchlog.txt'; // log for batch mode
debug = false; // debug mode on/off
debugrep = 'd:\data\disk1\temp'; // directory where to save files
var
AlbumName, dfltAlbumc, firstcall, abort, name: String;
indirizzo_pagina, valore_ricerca: String;
BatchMode, dfltAlbum: Integer;
len_dopo, len_prima, num_char: Integer;
dopo, prima: String;
batchlog, confbatch, memo: TstringList;
albumok: boolean;
//------------------------------------------------------------------------------
// list of albums or artist
//------------------------------------------------------------------------------
procedure GetList;
var
Address, Table, Line, Page, urlmusic, year, album, albumtest, label, genre, Linet: String;
found: boolean;
i: integer;
begin
PickTreeClear; // clear list
indirizzo_pagina := AllMusicUrl+'/cg/amg.dll';
valore_ricerca := 'sql='+UrlEncode(AlbumName)+'&OPT1='+dfltAlbumc+'&Submit=Go&P=amg';
found := False;
PickTreeAdd('List of albums or artists', '');
Page := PostPage(indirizzo_pagina, valore_ricerca);
if debug then
DumpPage(debugrep+'AllMusicList.txt', Page); // debug
if Pos('Album Search Results for:', Page) = 0 then
begin
LogMessage('Error while reading selection page - no results found');
exit;
end;
// selection table
// note: the results are displayed on one page and are sorted by relevance
Table := TextBetween(Page, '<!--Begin Search Results-->', 'End of List');
if debug then
DumpPage(debugrep+'AllMusicListShort.txt', Table); // debug
Table := TextAfter(Table, 'Year');
memo := TStringList.Create;
memo.Text := StringReplace(Table, '</tr>', crlf); // separate lines
if debug then
begin
Linet := StringReplace(Table, '</tr>', crlf);
DumpPage(debugrep+'AllMusicStringList.txt', Linet); // debug
end;
urlmusic := 'href="/cg/amg.dll'; // url to search (first occurence)
for i := 0 to memo.Count-1 do // list of albums
begin
Line := memo.GetString(i); // extract current line
Address := GetUrl(Line, urlmusic, AllMusicUrl); // get url of album page
if Address = '' then continue; // no url: header or empty line
Line := TextAfter(Line, '<td class="cell">');
Line := StringReplace(Line, '</TD>', sepchar1); // separate fields with </TD>
year := Trim(TextBefore(Line, sepchar1, '')); // year of the album
Line := RemainingText;
Line := TextAfter(Line, '>');
name := TranslateSpecial(Trim(TextBefore(Line, sepchar1, ''))); // name of the artist
Line := RemainingText;
Line := TextAfter(Line, urlmusic);
Line := TextAfter(Line, '>');
albumtest := Trim(TextBefore(Line, 'src', ''));
if albumtest = '<img' then
begin
Address := GetUrl(Line, urlmusic, AllMusicUrl); // get url of album page
if Address = '' then continue; // no url: header or empty line
Line := TextAfter(Line, urlmusic);
Line := TextAfter(Line, '>');
end;
album := TranslateSpecial(Trim(TextBefore(Line, '</a>', ''))); // name of the album
Line := RemainingText;
Line := TextAfter(Line, sepchar1);
Line := TextAfter(Line, sepchar1);
Line := TextAfter(Line, '>');
label := Trim(TextBefore(Line, sepchar1, '')); // label of the album
Line := RemainingText;
Line := TextAfter(Line, urlmusic);
Line := TextAfter(Line, '>');
genre := Trim(TextBefore(Line, '</a>', '')); // genre of the album
// ************** ricerca esatta ***********
// if ContainsStr(album, albumName) // albumName è il criterio di ricerca
num_char := 0;
if album = albumName then
num_char := 7;
prima := TextBefore(album, albumName, '');
len_prima := length(prima);
dopo := TextAfter(album, albumName);
len_dopo := length(dopo);
num_char := num_char + len_prima + len_dopo;
// **********fine ricerca esatta ***********
// if year <> '' then
if num_char > 0 then
begin
PickTreeAdd(name+' - '+album+' ('+year+')', Address);
found := True;
end;
end; {for i}
memo.Free;
if not found then
begin
LogMessage('No album found for '+AlbumName);
exit;
end;
PickTreeSort; // sort the list
if PickTreeExec(Address) then
AnalyzeMusicPage(Address) // music page
else
LogMessage('No album selected');
end;
//------------------------------------------------------------------------------
// ANALYZE MUSIC PAGE
//------------------------------------------------------------------------------
procedure AnalyzeMusicPage(Address: string);
var
Page, Line, Linet, urlmusic, artisturl, Value, cover, Track, Lenght, Minu, Seco, Pays, usastates: String;
i, TMinu, TSeco: Integer;
j: Real;
begin
Page := GetPage(Address);
if debug then
DumpPage(debugrep+'AllMusicPageDetail.txt', Page); // debug
if Pos('Artist', Page) = 0 then // may be this test is OK?
Begin
LogMessage('Error while reading album page');
exit;
end;
SetField(fieldURL, Address);
albumok := True;
//*** artist url
urlmusic := 'href="/cg/amg.dll'; // url to search (first occurence)
Value := TextBetween(Page, '<span class="title">', 'class="subtitle');
artisturl := AllMusicUrl+TranslateSpecial(TextBetween(Value, '<a href="', ' "'));
//*** artist name (=TranslatedTitle)
//*** artist name (=Director) - sracer
Value := TextBetween(Page, 'class="subtitle">', '</a>');
SetField(fieldMedia, FormatText(Value));
//*** album title (=originalTitle)
Value := TextBetween(Page, '<span class="title">', '</span>');
SetField(fieldTranslatedTitle, FormatText(Value));
//*** rating (<img src="/img/stars/st_rX.gif" with X = rating: 1=1 star to 9=5 stars)
// X=1 (1) x=2 (1.5) ... x=9 (5) ==> rating = (x+1) for 0 to 10
Value := TextBetween(Page, '<img src="/i/pages/site/stars/st_r', '.gif"');
if Value <> '' then
begin
i := StrToInt(Value, 0);
j := (i + 1); // rating from 0 to 10
// uncomment next line if you want a rating from 0 to 5 (by half point)
// j := (i + 1) /2;
SetField(fieldRating, FloatToStr(j));
end;
//*** release date (year only) ('month year' 'month day, year' or 'year')
Value := TextBetween(Page, '<span>Release Date</span>', '</table>');
Value := FormatText(Value);
i := LastPos(' ', Value); // extract year only
if i > 0 then Value := Copy(Value, i+1, length(Value));
SetField(fieldYear, Value);
//*** label (= director)
// Value := TextBetween(Page,'<span>Label</span>', '</table>');
// SetField(fieldDirector, FormatText(Value));
//*** type (= country)
Value := FormatText(TextBetween(Page, '<span>Type</span>', '</table>'));
// if Value = '' then
// SetField(fieldCountry,'Standard');
// if Value <> '' then
// SetField(fieldCountry, Value);
// if Value = 'Explicit Lyrics' then
// SetField(fieldCountry,'Standard');
//*** genre (= category)
Value := TextBetween(Page, '<span>Styles</span>', '</li>');
SetField(fieldCategory, FormatText(Value));
//*** cover
cover := TextBetween(Page, '<!--Begin Album Photo-->', '</table>');
cover := TextBetween(cover, 'img src="', '"');
if CanSetPicture then
GetPicture(cover);
//*** album review (= comments)
Value := FormatText(TextBetween(Page, '<!--Begin Center Content-->', '</table>'));
Value := TextAfter(Value, 'Reviewby');
if Value = '' then
SetField(fieldComments, 'No Review Available');
if Value <> '' then
SetField(fieldComments, 'Review by'+Value);
//*** tracks list (= description)
//*** tracks list (= artist) - sracer
Value := TextBetween(Page, '<!--Begin Center Content-->', '<!--End Center Content-->');
if debug then
DumpPage(debugrep+'AllMusicPagetracks.txt', Value); // debug
Value := TextAfter(Value, '>Time');
Value := TextAfter(Value, '</table>');
Value := TextAfter(Value, '</TD>');
Value := TextAfter(Value, '</TD>');
Value := StringReplace(Value, crlf, ''); // separate lines
memo := TStringList.Create;
memo.Text := StringReplace(Value, '</tr>', crlf); // separate lines
if debug then
begin
Linet := StringReplace(Value, '</tr>', crlf);
DumpPage(debugrep+'AllMusicPageDetailList.txt', Linet); // debug
end;
Value := '';
Minu := '';
Seco := '';
TMinu := 0;
TSeco := 0;
for i := 0 to memo.Count-1 do // list of tracks
begin
Line := memo.GetString(i); // extract current line
Line := TextAfter(Line, '<TD class="cell">');
Line := StringReplace(Line, '</TD>', sepchar1); // separate fields with </TD>
Track := Trim(TextBefore(Line, sepchar1, ''));
if Track <> '' then
begin
Value := Value+Track; // number of track
Line := RemainingText;
Value := Value+'. '+FormatText(Trim(TextBefore(Line, sepchar1, ''))); // title of track
Line := RemainingText;
Line := TextAfter(Line, sepchar1); // not usefull info
Lenght := FormatText(Trim(TextBefore(Line, sepchar1, ''))); // lenght of track
Minu := Trim(TextBefore(Lenght, ':', ''));
Seco := Trim(TextAfter(Lenght, ':'));
TMinu := TMinu + StrToInt(Minu, 0); // extract the minutes
TSeco := TSeco + StrToInt(Seco, 0); // extract the seconds
if TSeco > 60 then
begin
TMinu := TMinu + 1;
TSeco := TSeco - 60;
end;
Value := Value+' ('+Lenght+')';
Value := Value+crlf;
end;
end;
SetField(fieldActors, Value);
//*** length (only show the minutes)
if TSeco > 30 then
TMinu := Tminu + 1;
SetField(fieldLength, IntToStr(TMinu));
//*** media name (= artist - title) default setting
// SetField(fieldMedia, GetField(fieldTranslatedTitle)+' - '+GetField(fieldOriginalTitle));
// SetField(fieldMedia, GetField(fieldDirector)+' - '+GetField(fieldOriginalTitle));
//*** media type (= JewelCase) default setting
//*** media type (= CD) default setting - sracer
SetField(fieldMediaType, 'CD');
//*** audio format (= VideoFormat = CD) default setting
// SetField(fieldVideoFormat, 'CD');
//*** source (= AudioFormat = Achat) default setting
SetField(fieldAudioFormat, 'CD Audio');
//*** number of disks (= VideoBitrate = 1) default setting
// SetField(fieldVideoBitrate, '1');
//*** country of the artist
Page := GetPage(artisturl);
if debug then
DumpPage(debugrep+'AllMusicArtistDetail.txt', Page); // debug
if pos('<!--Begin Formed-->', Page) > 0 then
Value := TextBetween(Page, '<!--Begin Formed-->', '<!--End Formed-->');
if pos('<!--Begin Born-->', Page) > 0 then
Value := TextBetween(Page, '<!--Begin Born-->', '<!--End Born-->');
if debug then
DumpPage(debugrep+'AllMusicArtistDetailshort.txt', Value); // debug
Value := TextAfter(Value, '<a href=');
Value := TextAfter(Value, '<a href=');
Value := TextBetween(Value, '>', '<');
Pays := TextAfter(Value, ', ');
// SetField(fieldSource, Pays);
// SetField(fieldProducer, 'English');
// if Pays = 'France' then SetField(fieldProducer, 'French');
// if Pays = 'Spain' then SetField(fieldProducer, 'Spanish');
// if Pays = 'Italia' then SetField(fieldProducer, 'Italian');
usastates := 'WA,MT,ND,MN,WI,MI,YT,NH,ME,NY,RI,MA,CT,NJ,DE,MD,DC,PA,OH,IN,IL,IA,SD,NE,WY,ID,OR,CA,NV,UT,AZ,CO,NM,KS,OK,TX,MO,AR,LA,KY,TN,MS,AL,FL,GA,SC,NC,VA,WV,HI,AK';
// if pos(Pays,usastates) > 0 then
// begin
// SetField(fieldSource, 'United States Of America');
// SetField(fieldProducer, 'English');
// end;
end;
//------------------------------------------------------------------------------
// extract 'various infos'
//------------------------------------------------------------------------------
function ExtrInfo(str1, str2: string) :string;
begin
str1 := FormatText(TextBetween(str1, str2, '</table>'));
if str1 <> '' then str1 := crlf+str2+': '+str1;
result := str1;
end;
//------------------------------------------------------------------------------
// set show warning (normal mode) or add to log (batch mode)
//------------------------------------------------------------------------------
procedure LogMessage(m: string);
begin
if BatchMode > 0 then
AddToLog('item '+GetField(fieldNumber)+': '+m)
else
ShowWarning(m);
end;
//------------------------------------------------------------------------------
// add a message in the batch log and save to disk
// (because I don't know when it's finished...)
//------------------------------------------------------------------------------
procedure AddToLog(m: string);
begin
batchlog.Add(m);
batchlog.SaveToFile(batchlogfic);
end;
//------------------------------------------------------------------------------
// process batch mode
//------------------------------------------------------------------------------
procedure AllMusicBatch;
begin
AlbumName := GetField(fieldTranslatedTitle); // if no url or another site then ignore
if (AlbumName <> '') and (Pos(AllAlbumUrl, AlbumName) > 0) then
AnalyzeMusicPage(AlbumName)
else
LogMessage('ignored url="'+AlbumName+'"');
end;
//------------------------------------------------------------------------------
// process normal mode
//------------------------------------------------------------------------------
procedure AllMusicNorm;
begin
albumok := False;
if dfltAlbum = 1 then
begin
LogMessage('Sorry this functionality is not operational for now');
// dfltAlbumc := '1';
// AlbumName := GetField(fieldTranslatedTitle); // get artist name
// repeat
// if not Input('AllMusic.com Import', 'Enter the name of the artist :', AlbumName) or (AlbumName = '') then exit;
// GetList;
// until albumok;
end;
if dfltAlbum = 2 then
begin
dfltAlbumc := '2';
AlbumName := GetField(fieldTranslatedTitle); // get album name
repeat
if not Input('AllMusic.com Import', 'Enter the name of the album :', AlbumName) or (AlbumName = '') then exit;
GetList;
until albumok;
end;
if dfltAlbum = 3 then
begin
LogMessage('Sorry this functionality is not operational for now');
// dfltAlbumc := '3';
// AlbumName := GetField(fieldOriginalTitle); // get song name
// repeat
// if not Input('AllMusic.com Import', 'Enter the name of the song :', AlbumName) or (AlbumName = '') then exit;
// GetList;
// until albumok;
end;
end;
//------------------------------------------------------------------------------
// start here
//------------------------------------------------------------------------------
begin
if abort = 'o' then exit; // batch mode aborted
if firstcall <> 'done' then
begin // 1st call: init parameters
firstcall := 'done';
if not CheckVersion(3,5,0) then
begin
ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.0)');
abort := 'o';
exit;
end;
// get user's parms (used more than once)
dfltAlbum := GetOption('AlbumOpt');
BatchMode := GetOption('Mode');
if BatchMode > 0 then // batch mode: confirm the choice
begin
batchlog := TStringList.Create; // init batch log
batchlog.Add('starting batch mode');
batchlog.Add(StringOfChar('*',80));
batchlog.SaveToFile(batchlogfic);
// confirmation message
confbatch := TStringList.Create;
confbatch.Add('You have selected the batch mode:');
confbatch.Add('Have you saved your database?');
confbatch.Add('');
confbatch.Add('At the end of treatement:');
confbatch.Add('- look at the file '+batchlogfic+' for errors/infos');
confbatch.Add('- the albums found will be checked, the others not (for the selection)');
confbatch.Add(' (see: Tools/Preferences/Movie list/checkboxes)');
confbatch.Add('');
confbatch.Add('confirm your choice');
if not ShowWarning(confbatch.Text) then
begin
AddToLog('batch mode aborted'); // batch mode not confirmed = abort
abort := 'o';
exit;
end;
end;
end;
// let's go
if BatchMode = 0 then
AllMusicNorm
else
AllMusicBatch;
end.