Page 1 of 1

[REL] AllMusic Script

Posted: 2011-10-29 05:29:36
by fulvio53s03
Released a new script with 3 options:
a) Mode
- 0 Normal (you must provide album title in Translated Title Field)
- 1 Batch (you must provide album Url in Url Field)
b) Type Search
- 1 Exact expression (no relevance to blanks embedded)
- 2 Any word
c) Type Order
- 1 search results ordered by Artist
- 2 search results ordered by Album Title
- 3 search results ordered by Relevance (according to Allmusic)

Script "Allmusic from URL" is now no more useful and can be deleted.



Code: Select all

(***************************************************

Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/

[Infos]
Authors=Fulvio53s03
Title=AllMusic IT
Description=import artist and/or album
Site=http://www.allmusic.com
Language=IT
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
GetInfo=1

[Options]
Mode=1|0|0=normal mode|1=batch mode (url)
TypeSearch=1|1|1=search for exact expression|2=search for any word
TypeOrder=3|3|1=order by Artist|2=order by Album Title|3=order by relevance

***************************************************)

// needs the following units
// StringUtils7552.pas
//
program AllMusic;
uses
   StringUtils7552;
   
const
   AllMusicUrl = 'http://www.allmusic.com';                // base url
   AllAlbumUrl = 'http://www.allmusic.com';                // base url
   batchlogfic = 'c:\amc_Album_searchlog.txt';             // log for batch mode
   debug = false;                                          // debug mode on/off
   debugrep = 'c:\';                                       // directory where to save files

var
   Credit_address: String;
   AlbumName, firstcall, abort, name, Dati_traccia, autori: String;
   Releases, Commento, save_value, indirizzo_pagina, ordine_lista, Salva_autore: String;
   value, sw_serie, StartDelimiter, endDelimiter : string;
   CharNormal, CharAbNormal: string;
   Album_ok: boolean;
   BatchMode, Tipo_Ricerca, Tipo_Sort: Integer;
   len_dopo, len_prima, num_char, num_linee, lungo: Integer;
   CharCut, NumChar: integer;
   min_albName, min_alb, dopo, prima, brani, Track, dati_track: String;
   batchlog, confbatch, memo: TstringList;
   pag_ricerca, save_pag, dati_album, artist, initchar, endchar: string;
   sw_giri, year: string;
   albumok: boolean;
   contatore: integer;
   

//------------------------------------------------------------------------------
// list of albums or artist
//------------------------------------------------------------------------------
procedure GetList;   
//     /filter:all/order:relevance-desc   3
//     /filter:all/order:title-asc        2
//     /filter:all/order:label-asc
//     /filter:all/order:year-asc
//     /filter:all/order:artist-asc       1

var
   Address, Line, Page, urlmusic, album, albumtest, label, genre: String;
   Editore: string;
   Relevance: String;
   ValRelev: integer;
   found: boolean;
   i, lgth_dati_album: integer;

begin
   PickTreeClear;                                                    // clear list
   if Tipo_Sort = 1 then
      ordine_lista := '/filter:all/order:artist-asc';
   if Tipo_Sort = 2 then
      ordine_lista := '/filter:all/order:title-asc';
   if Tipo_Sort = 3 then
      ordine_lista := '';
//      ordine_lista := '/filter:all/order:relevance-desc';

   indirizzo_pagina :=  AllMusicUrl+'/search/';
   Address :=  AllMusicUrl + '/search/album/' + UrlEncode(AlbumName) + ordine_lista;       //fs
   Page := GetPage(Address);
//   SetField(fieldVideoFormat, Address);         //fs debug
   SetField(fieldURL, Address);

   found := False;
   PickTreeAdd('List of albums or artists', '');
   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;
   pag_ricerca := TextBetween(Page, 'table class="search-results"', '</table>');

   Normalizza_Page(pag_ricerca);

//fs $$$$$$$$$$$$$$$$$$$$$$$$$$$$$ nuova funzione di ricerca indirizzi sulla pagina $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
      save_pag := pag_ricerca;
      initchar := '<td class';
      pag_ricerca := initchar + '<tr>' + textafter(pag_ricerca, initchar);
      initchar := '<tr';
      endchar  := '</tr>';
      dati_album := initchar + TextBetween (pag_ricerca, initchar, endchar) + endchar;     //dati_album contiene la prima riga della ricerca
      delete(Pag_ricerca, 1, length(dati_album));

      lungo := (Length(initchar) + length(endchar));
      while Length(Dati_Album) > Lungo do
         begin
         initchar := '<td>';
         endchar  := '</td>';
         Address := textbetween(dati_album, initchar, endchar);
         delete(Dati_album, 1, (length(Address) + length(Initchar) + length(endchar)));
         initchar := 'href="';
         endchar  := '"';
         Address := textbetween(Address, initchar, endchar);
         delete(Dati_album, 1, (pos(Address, Dati_Album)+ length(Address) + length(endchar)));

         endchar  := '</a>';
         album := textbefore(dati_album, endchar, '');
         delete(Dati_album, 1, (pos(endchar, Dati_album))+ length(endchar));

         setfield(fielddescription, dati_album);     // memo temporaneo dati per ricerca album
         initchar := '<td>';
         endchar  := '</td';
         artist := textbetween(dati_album, initchar, endchar);
         lungo := pos(endchar, Dati_album)+ length(endchar);
         delete(Dati_album, 1, lungo);
         lungo := length(Dati_album);

         editore := textbetween(dati_album, initchar, endchar);
         lungo := pos(endchar, Dati_album)+ length(endchar);
         delete(Dati_album, 1, lungo);
         lungo := length(Dati_album);

         year := textbetween(Dati_album, initchar, endchar);
         delete(Dati_album, 1, (length(year) + length(Initchar) + length(endchar)));
         lungo := length(dati_album);

         album_ok := false;
         verifica_tipo_ricerca(album);
         if album_ok then
            PickTreeAdd(artist + ' - ' + album + ' (' + editore + ' ' + year + ')', Address);

         initchar := '<tr';
         endchar  := '</tr>';
         lungo := (Length(initchar) + length(endchar));
         if  Length(Dati_Album) > Lungo then
             found := True;
         dati_album := initchar + TextBetween (pag_ricerca, initchar, endchar) + endchar;     //dati_album contiene i dati dell'album
         lgth_dati_album := length(Dati_album);
         delete(Pag_ricerca, 1, lgth_dati_album);
      end;
//fs $$$$$$$$$$$$$$$$$$$$$$$$ fine nuova funzione di ricerca indirizzi sulla pagina $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

   if not found then
   begin
      LogMessage('No album found for '+AlbumName);
      exit;
   end;
   if PickTreeExec(Address) then
      begin
      AnalyzeMusicPage(Address);                                    // Album page
      end
   else
      LogMessage('No album selected');
end;

procedure verifica_tipo_ricerca(Dati_paragrafo: string);
var
   Campo: String;
   posizione: integer;
begin
// ************** ricerca esatta indipendente da maiuscole, minuscole e spazi ***********
//      if ContainsStr(album, albumName)
      CharAbNormal := ' ';
      CharNormal := '';
      If Tipo_ricerca = 1 then                                              // tipo ricerca esatta di albumName
         begin
          min_alb := AnsiLowerCase(Dati_paragrafo);
          HTMLDecode(min_alb);                                              // Clean description from HTML codes (if some exist)
          min_alb := StringReplace(min_alb, CharAbNormal, CharNormal);

          min_albName := AnsiLowerCase(albumName);
          HTMLDecode(min_albName);                                          // Clean description from HTML codes (if some exist)
          min_albName := StringReplace(min_albName, CharAbNormal, CharNormal);

          posizione := pos(min_albname, min_alb);
          if posizione > 0 then
             album_ok := True;
      end;
      If Tipo_ricerca = 2 then                                              // tipo ricerca esatta di albumName
         album_ok := true;
end;

//------------------------------------------------------------------------------
// ANALYZE MUSIC PAGE
//------------------------------------------------------------------------------
procedure AnalyzeMusicPage(Address: string);
var
   Page, Line, urlmusic, cover, Lenght, Minu, Pays: String;
   Autore, Commenti: String;
   i: 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);
   SetField(fieldDate, DateToStr(Date));
   Normalizza_Page(Page);
   albumok := True;

//*** artist url
   urlmusic := 'href="/cg/amg.dll';                               // url to search (first occurence)
   Value := TextBetween(Page, '<span class="title">', 'class="subtitle');   

//*** artist name (=OriginalTitle)
//*** artist name (=Director) - sracer
   Value := TextBetween(Page, '<div class="subtitle">', '</div>');
//   Value := TextBetween(Value, '">', '</a>');
   SetField(fieldDirector, FormatText(Value));
   SetField(fieldOriginalTitle, FormatText(Value));
   Salva_autore :=FormatText(Value);
   
//*** album title (=TranslatedTitle)
   Value := TextBetween(Page, '<h1 class="title">', '</h1>');
   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, '<h3>Release Date</h3>', '<h3>');
   Value := FormatText(Value);
   i := LastPos(' ', Value);                                          // extract year only
   if i > 0 then Value := Copy(Value, i+1, length(Value));
   SetField(fieldYear, Value);

//*** genre (= category)
   Value := TextBetween(Page, '<h3>Genre</h3>', '</li>');
   SetField(fieldCategory, FormatText(Value));

//*** cover
   cover := TextBetween(Page, '<!--Begin Album Photo-->', '</table>');
   cover := TextBetween(cover, 'img src="', '"');
   if CanSetPicture then
      GetPicture(cover);

//*** label
   Value := FormatText(TextBetween(Page, '<h3>Label</h3>', '</p>'));
   if Value = '' then
      SetField(fieldProducer, 'No label');
   if Value <> '' then
      SetField(fieldProducer, Value);

//*** album review (= comments)
   Value := FormatText(TextBetween(Page, '<div id="review">', '</div>'));
   Value := StringReplace(Value, ('Review' + CRLF), 'Review ');
   Value := StringReplace(Value, (CRLF + ' '), CRLF);
   Value := StringReplace(Value, (CRLF + CRLF), CRLF);

   if Value = '' then
      Commenti := 'No Review Available'
   else
      Commenti := Value;

//   GetReleases;
   Value := TextBetween(Page, '<div id="releases">', '</div>');
   GetReleases;
   Commenti := Commenti + CRLF + Releases;
   Setfield(FieldComments, commenti);
   
   Value := Page;
   elimina_espansioni;
   Value := TextBetween(Value, '<div id="tracks">', '</div>');
   brani := '';
   estrazione_tracce;
   delete(Page, 1, length(Value));

   SetField(fieldDescription, brani);

   Credit_address := Address + '/credits';
   AnalyzeCreditsPage;
end;

procedure elimina_espansioni;
var
  espansione, resto_espansione: String;
  lgthcontrol: integer;
begin
  initchar := '<div class="expand">';     // <td id="expand-title" class="cell">
  endchar  := '</div>';
  lgthcontrol := length(value);
  espansione  := textbetween(value, initchar, endchar);
  while length(espansione) > 0 do
    begin
      espansione := initchar + espansione + endchar;                                  //fs 2011.10.24
//      resto_espansione := '<td class="cell">' + FormatText(espansione) + '</td>';   //fs 2011.10.24
      resto_espansione := '<tr ' + FormatText(espansione) + '</tr>';                  //fs 2011.10.24
      Value := StringReplace(Value, espansione, resto_espansione);                    //fs 2011.10.24
//fs 2011.10.24      delete(Value, pos(initchar, value), (length(initchar) + length(espansione) + length(endchar)));
      espansione := textbetween(Value, initchar, endchar);
    end;
  lgthcontrol := length(value);
end;

procedure elimina_urls_autori;
var
  espansione: String;
  lgthcontrol: integer;
begin
  initchar := '<a href="';     // <td id="expand-title" class="cell">
  endchar  := '">';
  lgthcontrol := length(value);
  espansione  := textbetween(value, initchar, endchar);
  while length(espansione) > 0 do
    begin
      delete(Value, pos(initchar, value), (length(initchar) + length(espansione) + length(endchar)));
      espansione := textbetween(Value, initchar, endchar);
    end;
  lgthcontrol := length(value);
  CharAbNormal := '</a>';
  CharNormal := '';
  Value := StringReplace(Value, CharAbNormal, CharNormal);
end;
//

procedure GetReleases;
var
   Dato_Release: String;
begin
   CharAbNormal := '<td class="cell">';                       //elimino i dati inutili
   CharNormal := '';
   Value := StringReplace(Value, CharAbNormal, CharNormal);
   CharAbNormal := '</td>';
   CharNormal := ' ';
   Value := StringReplace(Value, CharAbNormal, CharNormal);
   CharAbNormal := CRLF;
   CharNormal := '';
   Value := StringReplace(Value, CharAbNormal, CharNormal);

   StartDelimiter := '<tr class="visible">';                  //mi posiziono su inizio dati significativi
   EndDelimiter   := '</tr>';
   lungo := length(textbefore(Value, StartDelimiter, ''));
   delete(Value, 1, lungo);

   Lungo := (Length(StartDelimiter) + length(EndDelimiter));
   Dato_release := StartDelimiter + TextBetween(Value, StartDelimiter, EndDelimiter) + EndDelimiter;
   delete(Value, 1, length(Dato_release));
   Dato_release := Trim(TextBetween(Value, StartDelimiter, EndDelimiter));
   Releases := '--- Releases: ---' + CRLF + Dato_release;
   while Length(Dato_Release) > Lungo do
      begin
      Dato_release := StartDelimiter + TextBetween(Value, StartDelimiter, EndDelimiter) + EndDelimiter;
      delete(Value, 1, length(Dato_release));
//      Dato_release := FormatText(Dato_release);
      Dato_release := Trim(TextBetween(Value, StartDelimiter, EndDelimiter));
      Releases := Releases + CRLF + Dato_release;
      end;
end;
//

//fs ************************** nuova estrazione tracce *****************************************
Procedure estrazione_tracce;
Begin
    pag_ricerca := value;
    if debug then
       DumpPage(debugrep+'AllMusicList_pag_ricerca.txt', pag_ricerca);                // debug
    endchar := '</tr>';
    lungo := length(textbefore(pag_ricerca, endchar, '')) + length(endchar);
    delete(Pag_ricerca, 1, lungo);

    initchar := '<tr';
    endchar := '</tr>';
    lungo := (Length(initchar) + length(endchar));
    Dati_traccia := initchar + TextBetween(Pag_ricerca, initchar, endchar) + endchar;
    delete(Pag_ricerca, 1, length(Dati_traccia));

    while Length(Dati_traccia) > Lungo do
      begin
       dati_track := '';
       track := '';
       initchar := '<td class="cell">';
       endchar  := '</td>';
       track := textbetween(dati_traccia, initchar, endchar);           //n.d'ordine
       dati_track := dati_track + track;
       if length(track) > 0 then
          brani := brani + track + '  ';
       delete(Dati_traccia, 1, (pos(Initchar, dati_traccia) + length(track) + length(initchar) + length(endchar)));

       initchar := '<td class="cell">';
       endchar  := '</td>';
       track := textbetween(dati_traccia, initchar, endchar);          //titolo brano
       dati_track := dati_track + track;
       delete(Dati_traccia, 1, (length(track) + length(Initchar) + length(endchar)));

       initchar := '">';
       endchar  := '</a>';
       track := textbetween(track, initchar, endchar);                 //autori
       dati_track := dati_track + track;
       if length(track) > 0 then
            brani := brani + track + '  ';
       delete(Dati_traccia, 1, (pos(track, Dati_traccia)+ length(track) + length(endchar)));

       initchar := '<td class="cell">';
       endchar  := '</td>';
       autori := textbetween(Dati_traccia, initchar, endchar);
       Value := autori;
       elimina_urls_autori;
       track := fulltrim(Value);
       dati_track := dati_track + track;
       if length(track) > 0 then
          brani := brani + '  (' + track + ')  ';
       delete(Dati_traccia, 1, (pos(endchar, Dati_traccia))+ length(endchar));

       initchar := '<td class="cell">';
       endchar  := '</td';
       track := textbetween(dati_traccia, initchar, endchar);
       dati_track := dati_track + track;
       if length(track) > 0 then
          brani := brani + track;
       if length(dati_track) > 0 then
          brani := brani + CRLF;

       initchar := '<tr';
       endchar  := '</tr>';
       lungo := (Length(initchar) + length(endchar));
       dati_traccia := initchar + TextBetween (pag_ricerca, initchar, endchar) + endchar;     //dati_album contiene i dati dell'album
       delete(Pag_ricerca, 1, length(Dati_traccia));
    end;
end;
//fs ********************* fine nuova estrazione tracce *****************************************

//------------------------------------------------------------------------------
// ANALYZE Credits PAGE
//------------------------------------------------------------------------------
procedure AnalyzeCreditsPage;
var
   Page, Line, urlmusic, cover, Lenght: String;
   i: Integer;
   j: Real;

begin
   Page := GetPage(Credit_address);
   Normalizza_Page(Page);
   NumChar := length(Page);
   if debug then
      DumpPage(debugrep+'AllMusicCreditDetail.txt', Page);             // debug
   if Pos('Credits', Page) = 0 then                              // may be this test is OK?
   Begin
      LogMessage('Error while reading credits page');
      exit;
   end;
   albumok := True;
// ***************************** estrae i credits ***********************************************
//   Value := TextBetween(Page, '<div id="tabcontent_2">', '<div id="tabcontent_3">');
   Value := TextBetween(Page, '<div id="results-table">', '<!-- End Credits Table -->');
   NumChar := length(Value);
   Getcredits;
// ************************ fine estrae i credits (copiato dalle tracce) ************************
   Save_value := '"' + Salva_autore + '"' + CRLF + Save_Value;
   SetField(fieldActors, Save_value);
end;

procedure GetCredits;
Begin
   Save_Value := '';
   Commento := '* ';
   While Commento <> '' do
      begin
      StartDelimiter := '<td class="sorted-cell';
      CharCut := Pos(StartDelimiter, Value);
      EndDelimiter   := '</td>';
      Commento := TextBetween(Value, StartDelimiter, EndDelimiter); // estrae nome
      CharCut := CharCut + length(StartDelimiter) + length(Commento) + length(EndDelimiter);
      delete(Value, 1, CharCut);
      Commento := StartDelimiter + Commento;
      HTMLRemoveTags(Commento);
      HTMLDecode(Commento);
      Commento := trim(Commento);
      Save_Value := Save_value + commento;
      if commento <> '' then
      Save_Value := Save_value + ': ';
      StartDelimiter := '<td class="cell">';
      CharCut := Pos(StartDelimiter, Value);
      EndDelimiter   := '</td>';
      Commento := TextBetween(Value, StartDelimiter, EndDelimiter); // estrae strumento
      CharCut := CharCut + length(StartDelimiter) + length(Commento) + length(EndDelimiter);
      delete(Value, 1, CharCut);
      HTMLRemoveTags(Commento);
      HTMLDecode(Commento);
      Commento := trim(Commento);
      if commento <> '' then
         Save_Value := Save_value + commento + ';' + crlf;
      end;
    Value := Save_value;
end;

Procedure Normalizza_page(Pagina: string);    // elimina i crlf, trasforma delimiters maiuscoli in minuscoli
begin
  CharAbNormal := crlf;
  CharNormal := ' ';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
  CharAbNormal := '<B';
  CharNormal := '<b';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
  CharAbNormal := '</B';
  CharNormal := '</b';
  pagina := StringReplace(Value, CharAbNormal, CharNormal);
//  CharAbNormal := '  ';
//  CharNormal := ' ';
//  Value := StringReplace(Page, CharAbNormal, CharNormal);
  CharAbNormal := '<FONT';
  CharNormal := '<font';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
  CharAbNormal := '</FONT';
  CharNormal := '</font';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
  CharAbNormal := '<TR';
  CharNormal := '<tr';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
  CharAbNormal := '</TR';
  CharNormal := '</tr';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
  CharAbNormal := '<TD';
  CharNormal := '<td';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
  CharAbNormal := '</TD';
  CharNormal := '</td';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
  CharAbNormal := '<DIV';
  CharNormal := '<div';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
  CharAbNormal := '</DIV';
  CharNormal := '</div';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
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(fieldUrl);                      // 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;
   AlbumName := GetField(fieldTranslatedTitle);           // get album name
   value := getField(fieldOriginalTitle);
   repeat
   if not Input('AllMusic - ' + Value, 'Enter the name of the album :' + crlf, AlbumName) or (AlbumName = '') then exit;
   GetList;
      until albumok;
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)
      BatchMode := GetOption('Mode');
      Tipo_ricerca := GetOption('TypeSearch');
      Tipo_Sort := GetOption('TypeOrder');
      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('Did you save your database?');
         confbatch.Add('*** Address to extract must be supplied in Field Url ***');
         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.
:grinking:

Posted: 2011-10-30 15:26:50
by hariskar
Thanks a lot!!! This is very good news!
I am searching for albums or artists, but the Disk selection list is always empty. What am I doing wrong?

Posted: 2011-10-30 16:32:32
by fulvio53s03
hariskar wrote:Thanks a lot!!! This is very good news!
I am searching for albums or artists, but the Disk selection list is always empty. What am I doing wrong?
What are you looking for? which words?
Any way, I saw that Allmusic site search provides differents results each time, so you can:
a) make search directly on the site
b) copy/paste the URL of the artist/title selected (i.e. http://www.allmusic.com/album/tupelo-honey-r13457 if you search for 'Tupelo Honey') in the URL field of your AMC Database record
c) execute AllMusic script (with Option Mode = 1)
d) do you extract something? problem belongs to AllMusic site search.
Do you extract nothing? Problem belongs to AntMusicCatalog (probably to AllMusic script not perfect).

Anyway .......let's know your search....... :ha:

Posted: 2011-10-30 19:03:47
by hariskar
What I am doing is:
Tools/Scripting... (Script options: AlbumOpt 1, Mode 0), Select the AllMusic script /Run, "Enter the name of the album": Scorpions and then a window opens that says Disc selection/ List of albums or artists and it is empty.
The same happens if I choose AlbumOpt 2 and put an album, eg Lovedrive.

Thank you!

Posted: 2011-10-30 22:06:27
by fulvio53s03
hariskar wrote:What I am doing is:
Tools/Scripting... (Script options: AlbumOpt 1, Mode 0), Select the AllMusic script /Run, "Enter the name of the album": Scorpions and then a window opens that says Disc selection/ List of albums or artists and it is empty.
The same happens if I choose AlbumOpt 2 and put an album, eg Lovedrive.

Thank you!
OK. I think to see the problem... a little misunderstooding between original and translated title. Tomorrow, after some little tests, I'll supply corrections.

For now, please provide in translated title your search parameters before starting the script (and the script should be OK).
bye. ;)

.... later .....

... as I said.... now it must be correct.

Code: Select all

(***************************************************

Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/

[Infos]
Authors=Fulvio53s03
Title=AllMusic IT
Description=import artist and/or album
Site=http://www.allmusic.com
Language=IT, 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
GetInfo=1

[Options]
Mode=0|0|0=normal mode|1=batch mode (url)
TypeSearch=1|1|1=search for exact expression|2=search for any word
TypeOrder=3|3|1=order by Artist|2=order by Album Title|3=order by relevance

***************************************************)

// needs the following units
// StringUtils7552.pas
//
program AllMusic;
uses
   StringUtils7552;
   
const
   AllMusicUrl = 'http://www.allmusic.com';                // base url
   AllAlbumUrl = 'http://www.allmusic.com';                // base url
   batchlogfic = 'c:\amc_Album_searchlog.txt';             // log for batch mode
   debug = false;                                          // debug mode on/off
   debugrep = 'c:\';                                       // directory where to save files

var
   Credit_address: String;
   AlbumName, firstcall, abort, name, Dati_traccia, autori: String;
   Releases, Commento, save_value, indirizzo_pagina, ordine_lista, Salva_autore: String;
   value, sw_serie, StartDelimiter, endDelimiter : string;
   CharNormal, CharAbNormal: string;
   Album_ok: boolean;
   BatchMode, Tipo_Ricerca, Tipo_Sort: Integer;
   len_dopo, len_prima, num_char, num_linee, lungo: Integer;
   CharCut, NumChar: integer;
   min_albName, min_alb, dopo, prima, brani, Track, dati_track: String;
   batchlog, confbatch, memo: TstringList;
   pag_ricerca, save_pag, dati_album, artist, initchar, endchar: string;
   sw_giri, year: string;
   albumok: boolean;
   contatore: integer;
   

//------------------------------------------------------------------------------
// list of albums or artist
//------------------------------------------------------------------------------
procedure GetList;   
//     /filter:all/order:relevance-desc   3
//     /filter:all/order:title-asc        2
//     /filter:all/order:label-asc
//     /filter:all/order:year-asc
//     /filter:all/order:artist-asc       1

var
   Address, Line, Page, urlmusic, album, albumtest, label, genre: String;
   Editore: string;
   Relevance: String;
   ValRelev: integer;
   found: boolean;
   i, lgth_dati_album: integer;

begin
   PickTreeClear;                                                    // clear list
   if Tipo_Sort = 1 then
      ordine_lista := '/filter:all/order:artist-asc';
   if Tipo_Sort = 2 then
      ordine_lista := '/filter:all/order:title-asc';
   if Tipo_Sort = 3 then
      ordine_lista := '';
//      ordine_lista := '/filter:all/order:relevance-desc';

   indirizzo_pagina :=  AllMusicUrl+'/search/';
   Address :=  AllMusicUrl + '/search/album/' + UrlEncode(AlbumName) + ordine_lista;       //fs
   Page := GetPage(Address);
//   SetField(fieldVideoFormat, Address);         //fs debug
   SetField(fieldURL, Address);

   found := False;
   PickTreeAdd('List of albums or artists', '');
   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;
   pag_ricerca := TextBetween(Page, 'table class="search-results"', '</table>');

   Normalizza_Page(pag_ricerca);

//fs $$$$$$$$$$$$$$$$$$$$$$$$$$$$$ nuova funzione di ricerca indirizzi sulla pagina $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
      save_pag := pag_ricerca;
      initchar := '<td class';
      pag_ricerca := initchar + '<tr>' + textafter(pag_ricerca, initchar);
      initchar := '<tr';
      endchar  := '</tr>';
      dati_album := initchar + TextBetween (pag_ricerca, initchar, endchar) + endchar;     //dati_album contiene la prima riga della ricerca
      delete(Pag_ricerca, 1, length(dati_album));

      lungo := (Length(initchar) + length(endchar));
      while Length(Dati_Album) > Lungo do
         begin
         initchar := '<td>';
         endchar  := '</td>';
         Address := textbetween(dati_album, initchar, endchar);
         delete(Dati_album, 1, (length(Address) + length(Initchar) + length(endchar)));
         initchar := 'href="';
         endchar  := '"';
         Address := textbetween(Address, initchar, endchar);
         delete(Dati_album, 1, (pos(Address, Dati_Album)+ length(Address) + length(endchar)));

         endchar  := '</a>';
         album := textbefore(dati_album, endchar, '');
         delete(Dati_album, 1, (pos(endchar, Dati_album))+ length(endchar));

         setfield(fielddescription, dati_album);     // memo temporaneo dati per ricerca album
         initchar := '<td>';
         endchar  := '</td';
         artist := textbetween(dati_album, initchar, endchar);
         lungo := pos(endchar, Dati_album)+ length(endchar);
         delete(Dati_album, 1, lungo);
         lungo := length(Dati_album);

         editore := textbetween(dati_album, initchar, endchar);
         lungo := pos(endchar, Dati_album)+ length(endchar);
         delete(Dati_album, 1, lungo);
         lungo := length(Dati_album);

         year := textbetween(Dati_album, initchar, endchar);
         delete(Dati_album, 1, (length(year) + length(Initchar) + length(endchar)));
         lungo := length(dati_album);

         album_ok := false;
         verifica_tipo_ricerca(album);
         if album_ok then
            PickTreeAdd(artist + ' - ' + album + ' (' + editore + ' ' + year + ')', Address);

         initchar := '<tr';
         endchar  := '</tr>';
         lungo := (Length(initchar) + length(endchar));
         if  Length(Dati_Album) > Lungo then
             found := True;
         dati_album := initchar + TextBetween (pag_ricerca, initchar, endchar) + endchar;     //dati_album contiene i dati dell'album
         lgth_dati_album := length(Dati_album);
         delete(Pag_ricerca, 1, lgth_dati_album);
      end;
//fs $$$$$$$$$$$$$$$$$$$$$$$$ fine nuova funzione di ricerca indirizzi sulla pagina $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

   if not found then
   begin
      LogMessage('No album found for '+AlbumName);
      exit;
   end;
   if PickTreeExec(Address) then
      begin
      AnalyzeMusicPage(Address);                                    // Album page
      end
   else
      LogMessage('No album selected');
end;

procedure verifica_tipo_ricerca(Dati_paragrafo: string);
var
   Campo: String;
   posizione: integer;
begin
// ************** ricerca esatta indipendente da maiuscole, minuscole e spazi ***********
//      if ContainsStr(album, albumName)
      CharAbNormal := ' ';
      CharNormal := '';
      If Tipo_ricerca = 1 then                                              // tipo ricerca esatta di albumName
         begin
          min_alb := AnsiLowerCase(Dati_paragrafo);
          HTMLDecode(min_alb);                                              // Clean description from HTML codes (if some exist)
          min_alb := StringReplace(min_alb, CharAbNormal, CharNormal);

          min_albName := AnsiLowerCase(albumName);
          HTMLDecode(min_albName);                                          // Clean description from HTML codes (if some exist)
          min_albName := StringReplace(min_albName, CharAbNormal, CharNormal);

          posizione := pos(min_albname, min_alb);
          if posizione > 0 then
             album_ok := True;
      end;
      If Tipo_ricerca = 2 then                                              // tipo ricerca esatta di albumName
         album_ok := true;
end;

//------------------------------------------------------------------------------
// ANALYZE MUSIC PAGE
//------------------------------------------------------------------------------
procedure AnalyzeMusicPage(Address: string);
var
   Page, Line, urlmusic, cover, Lenght, Minu, Pays: String;
   Autore, Commenti: String;
   i: 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);
   SetField(fieldDate, DateToStr(Date));
   Normalizza_Page(Page);
   albumok := True;

//*** artist url
   urlmusic := 'href="/cg/amg.dll';                               // url to search (first occurence)
   Value := TextBetween(Page, '<span class="title">', 'class="subtitle');   

//*** artist name (=OriginalTitle)
//*** artist name (=Director) - sracer
   Value := TextBetween(Page, '<div class="subtitle">', '</div>');
//   Value := TextBetween(Value, '">', '</a>');
   SetField(fieldDirector, FormatText(Value));
   SetField(fieldOriginalTitle, FormatText(Value));
   Salva_autore :=FormatText(Value);
   
//*** album title (=TranslatedTitle)
   Value := TextBetween(Page, '<h1 class="title">', '</h1>');
   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, '<h3>Release Date</h3>', '<h3>');
   Value := FormatText(Value);
   i := LastPos(' ', Value);                                          // extract year only
   if i > 0 then Value := Copy(Value, i+1, length(Value));
   SetField(fieldYear, Value);

//*** genre (= category)
   Value := TextBetween(Page, '<h3>Genre</h3>', '</li>');
   SetField(fieldCategory, FormatText(Value));

//*** cover
   cover := TextBetween(Page, '<!--Begin Album Photo-->', '</table>');
   cover := TextBetween(cover, 'img src="', '"');
   if CanSetPicture then
      GetPicture(cover);

//*** label
   Value := FormatText(TextBetween(Page, '<h3>Label</h3>', '</p>'));
   if Value = '' then
      SetField(fieldProducer, 'No label');
   if Value <> '' then
      SetField(fieldProducer, Value);

//*** album review (= comments)
   Value := FormatText(TextBetween(Page, '<div id="review">', '</div>'));
   Value := StringReplace(Value, ('Review' + CRLF), 'Review ');
   Value := StringReplace(Value, (CRLF + ' '), CRLF);
   Value := StringReplace(Value, (CRLF + CRLF), CRLF);

   if Value = '' then
      Commenti := 'No Review Available'
   else
      Commenti := Value;

//   GetReleases;
   Value := TextBetween(Page, '<div id="releases">', '</div>');
   GetReleases;
   Commenti := Commenti + CRLF + Releases;
   Setfield(FieldComments, commenti);
   
   Value := Page;
   elimina_espansioni;
   Value := TextBetween(Value, '<div id="tracks">', '</div>');
   brani := '';
   estrazione_tracce;
   delete(Page, 1, length(Value));

   SetField(fieldDescription, brani);

   Credit_address := Address + '/credits';
   AnalyzeCreditsPage;
end;

procedure elimina_espansioni;
var
  espansione, resto_espansione: String;
  lgthcontrol: integer;
begin
  initchar := '<div class="expand">';     // <td id="expand-title" class="cell">
  endchar  := '</div>';
  lgthcontrol := length(value);
  espansione  := textbetween(value, initchar, endchar);
  while length(espansione) > 0 do
    begin
      espansione := initchar + espansione + endchar;                                  //fs 2011.10.24
//      resto_espansione := '<td class="cell">' + FormatText(espansione) + '</td>';   //fs 2011.10.24
      resto_espansione := '<tr ' + FormatText(espansione) + '</tr>';                  //fs 2011.10.24
      Value := StringReplace(Value, espansione, resto_espansione);                    //fs 2011.10.24
//fs 2011.10.24      delete(Value, pos(initchar, value), (length(initchar) + length(espansione) + length(endchar)));
      espansione := textbetween(Value, initchar, endchar);
    end;
  lgthcontrol := length(value);
end;

procedure elimina_urls_autori;
var
  espansione: String;
  lgthcontrol: integer;
begin
  initchar := '<a href="';     // <td id="expand-title" class="cell">
  endchar  := '">';
  lgthcontrol := length(value);
  espansione  := textbetween(value, initchar, endchar);
  while length(espansione) > 0 do
    begin
      delete(Value, pos(initchar, value), (length(initchar) + length(espansione) + length(endchar)));
      espansione := textbetween(Value, initchar, endchar);
    end;
  lgthcontrol := length(value);
  CharAbNormal := '</a>';
  CharNormal := '';
  Value := StringReplace(Value, CharAbNormal, CharNormal);
end;
//

procedure GetReleases;
var
   Dato_Release: String;
begin
   CharAbNormal := '<td class="cell">';                       //elimino i dati inutili
   CharNormal := '';
   Value := StringReplace(Value, CharAbNormal, CharNormal);
   CharAbNormal := '</td>';
   CharNormal := ' ';
   Value := StringReplace(Value, CharAbNormal, CharNormal);
   CharAbNormal := CRLF;
   CharNormal := '';
   Value := StringReplace(Value, CharAbNormal, CharNormal);

   StartDelimiter := '<tr class="visible">';                  //mi posiziono su inizio dati significativi
   EndDelimiter   := '</tr>';
   lungo := length(textbefore(Value, StartDelimiter, ''));
   delete(Value, 1, lungo);

   Lungo := (Length(StartDelimiter) + length(EndDelimiter));
   Dato_release := StartDelimiter + TextBetween(Value, StartDelimiter, EndDelimiter) + EndDelimiter;
   delete(Value, 1, length(Dato_release));
   Dato_release := Trim(TextBetween(Value, StartDelimiter, EndDelimiter));
   Releases := '--- Releases: ---' + CRLF + Dato_release;
   while Length(Dato_Release) > Lungo do
      begin
      Dato_release := StartDelimiter + TextBetween(Value, StartDelimiter, EndDelimiter) + EndDelimiter;
      delete(Value, 1, length(Dato_release));
//      Dato_release := FormatText(Dato_release);
      Dato_release := Trim(TextBetween(Value, StartDelimiter, EndDelimiter));
      Releases := Releases + CRLF + Dato_release;
      end;
end;
//

//fs ************************** nuova estrazione tracce *****************************************
Procedure estrazione_tracce;
Begin
    pag_ricerca := value;
    if debug then
       DumpPage(debugrep+'AllMusicList_pag_ricerca.txt', pag_ricerca);                // debug
    endchar := '</tr>';
    lungo := length(textbefore(pag_ricerca, endchar, '')) + length(endchar);
    delete(Pag_ricerca, 1, lungo);

    initchar := '<tr';
    endchar := '</tr>';
    lungo := (Length(initchar) + length(endchar));
    Dati_traccia := initchar + TextBetween(Pag_ricerca, initchar, endchar) + endchar;
    delete(Pag_ricerca, 1, length(Dati_traccia));

    while Length(Dati_traccia) > Lungo do
      begin
       dati_track := '';
       track := '';
       initchar := '<td class="cell">';
       endchar  := '</td>';
       track := textbetween(dati_traccia, initchar, endchar);           //n.d'ordine
       dati_track := dati_track + track;
       if length(track) > 0 then
          brani := brani + track + '  ';
       delete(Dati_traccia, 1, (pos(Initchar, dati_traccia) + length(track) + length(initchar) + length(endchar)));

       initchar := '<td class="cell">';
       endchar  := '</td>';
       track := textbetween(dati_traccia, initchar, endchar);          //titolo brano
       dati_track := dati_track + track;
       delete(Dati_traccia, 1, (length(track) + length(Initchar) + length(endchar)));

       initchar := '">';
       endchar  := '</a>';
       track := textbetween(track, initchar, endchar);                 //autori
       dati_track := dati_track + track;
       if length(track) > 0 then
            brani := brani + track + '  ';
       delete(Dati_traccia, 1, (pos(track, Dati_traccia)+ length(track) + length(endchar)));

       initchar := '<td class="cell">';
       endchar  := '</td>';
       autori := textbetween(Dati_traccia, initchar, endchar);
       Value := autori;
       elimina_urls_autori;
       track := fulltrim(Value);
       dati_track := dati_track + track;
       if length(track) > 0 then
          brani := brani + '  (' + track + ')  ';
       delete(Dati_traccia, 1, (pos(endchar, Dati_traccia))+ length(endchar));

       initchar := '<td class="cell">';
       endchar  := '</td';
       track := textbetween(dati_traccia, initchar, endchar);
       dati_track := dati_track + track;
       if length(track) > 0 then
          brani := brani + track;
       if length(dati_track) > 0 then
          brani := brani + CRLF;

       initchar := '<tr';
       endchar  := '</tr>';
       lungo := (Length(initchar) + length(endchar));
       dati_traccia := initchar + TextBetween (pag_ricerca, initchar, endchar) + endchar;     //dati_album contiene i dati dell'album
       delete(Pag_ricerca, 1, length(Dati_traccia));
    end;
end;
//fs ********************* fine nuova estrazione tracce *****************************************

//------------------------------------------------------------------------------
// ANALYZE Credits PAGE
//------------------------------------------------------------------------------
procedure AnalyzeCreditsPage;
var
   Page, Line, urlmusic, cover, Lenght: String;
   i: Integer;
   j: Real;

begin
   Page := GetPage(Credit_address);
   Normalizza_Page(Page);
   NumChar := length(Page);
   if debug then
      DumpPage(debugrep+'AllMusicCreditDetail.txt', Page);             // debug
   if Pos('Credits', Page) = 0 then                              // may be this test is OK?
   Begin
      LogMessage('Error while reading credits page');
      exit;
   end;
   albumok := True;
// ***************************** estrae i credits ***********************************************
//   Value := TextBetween(Page, '<div id="tabcontent_2">', '<div id="tabcontent_3">');
   Value := TextBetween(Page, '<div id="results-table">', '<!-- End Credits Table -->');
   NumChar := length(Value);
   Getcredits;
// ************************ fine estrae i credits (copiato dalle tracce) ************************
   Save_value := '"' + Salva_autore + '"' + CRLF + Save_Value;
   SetField(fieldActors, Save_value);
end;

procedure GetCredits;
Begin
   Save_Value := '';
   Commento := '* ';
   While Commento <> '' do
      begin
      StartDelimiter := '<td class="sorted-cell';
      CharCut := Pos(StartDelimiter, Value);
      EndDelimiter   := '</td>';
      Commento := TextBetween(Value, StartDelimiter, EndDelimiter); // estrae nome
      CharCut := CharCut + length(StartDelimiter) + length(Commento) + length(EndDelimiter);
      delete(Value, 1, CharCut);
      Commento := StartDelimiter + Commento;
      HTMLRemoveTags(Commento);
      HTMLDecode(Commento);
      Commento := trim(Commento);
      Save_Value := Save_value + commento;
      if commento <> '' then
      Save_Value := Save_value + ': ';
      StartDelimiter := '<td class="cell">';
      CharCut := Pos(StartDelimiter, Value);
      EndDelimiter   := '</td>';
      Commento := TextBetween(Value, StartDelimiter, EndDelimiter); // estrae strumento
      CharCut := CharCut + length(StartDelimiter) + length(Commento) + length(EndDelimiter);
      delete(Value, 1, CharCut);
      HTMLRemoveTags(Commento);
      HTMLDecode(Commento);
      Commento := trim(Commento);
      if commento <> '' then
         Save_Value := Save_value + commento + ';' + crlf;
      end;
    Value := Save_value;
end;

Procedure Normalizza_page(Pagina: string);    // elimina i crlf, trasforma delimiters maiuscoli in minuscoli
begin
  CharAbNormal := crlf;
  CharNormal := ' ';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
  CharAbNormal := '<B';
  CharNormal := '<b';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
  CharAbNormal := '</B';
  CharNormal := '</b';
  pagina := StringReplace(Value, CharAbNormal, CharNormal);
//  CharAbNormal := '  ';
//  CharNormal := ' ';
//  Value := StringReplace(Page, CharAbNormal, CharNormal);
  CharAbNormal := '<FONT';
  CharNormal := '<font';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
  CharAbNormal := '</FONT';
  CharNormal := '</font';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
  CharAbNormal := '<TR';
  CharNormal := '<tr';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
  CharAbNormal := '</TR';
  CharNormal := '</tr';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
  CharAbNormal := '<TD';
  CharNormal := '<td';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
  CharAbNormal := '</TD';
  CharNormal := '</td';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
  CharAbNormal := '<DIV';
  CharNormal := '<div';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
  CharAbNormal := '</DIV';
  CharNormal := '</div';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
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(fieldUrl);                      // 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;
   AlbumName := GetField(fieldTranslatedTitle);           // get album name
   value := getField(fieldTranslatedTitle);
   repeat
   if not Input('AllMusic - ' + Value, 'Enter the name of the album :' + crlf, AlbumName) or (AlbumName = '') then exit;
   GetList;
      until albumok;
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)
      BatchMode := GetOption('Mode');
      Tipo_ricerca := GetOption('TypeSearch');
      Tipo_Sort := GetOption('TypeOrder');
      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('Did you save your database?');
         confbatch.Add('*** Address to extract must be supplied in Field Url ***');
         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.
:grinking:

unknown identifier, FULLTRIM at line 408

Posted: 2011-10-31 23:32:53
by ilobiti
IN LINE 408
track := fulltrim(Value);

I GET THE ERROR MESSAGE
unknown identifier, FULLTRIM at line 408

??? Thanks, Henry

Re: unknown identifier, FULLTRIM at line 408

Posted: 2011-11-01 06:32:06
by fulvio53s03
ilobiti wrote:IN LINE 408
track := fulltrim(Value);
I GET THE ERROR MESSAGE
unknown identifier, FULLTRIM at line 408
??? Thanks, Henry
Function Fulltrim is contained in stringutils1.pas, you must update it. :)

Posted: 2011-11-01 06:50:40
by hariskar
Thank you, where can we find the update? In latest beta version?

Posted: 2011-11-01 07:08:03
by fulvio53s03
hariskar wrote:Thank you, where can we find the update? In latest beta version?
It is present also in this official version.
You need only to run Update Scripts.
bye ;)

Posted: 2011-11-01 07:51:15
by hariskar
It works! Thank you!!

field TRACK NAME and TRACKS

Posted: 2011-11-01 08:02:27
by ilobiti
First of All - Thanks for Your great script !!!

I am sure that my problems a self inflicted - but perhaps You see an easy solution?

I would like to organize my mp3's that are each in folders named by artist and album.

When I import the mp3 names into AMC and execute Your script:

field TRACK NAME is filled with Artist Name

e.g. Amy Winehouse

field TRACKS is filled with the Credits of the songs ? instead the tracks on the album

e.g. "Amy Winehouse"
Nick Ashford: Composer;
Victor Axelrod: Clapping, Handclapping, Piano, Wurlitzer;
Harry "Rockbarry" Benson: Photography;
Mark Berrow: Violin;
Dave Bishop: Sax (Baritone);
Rachel Bolt: Viola;
Thomas Brenneck: Guitar;
Chris Davies: Sax (Alto);
Shomari "Sho" Dillon: Assistant, Assistant Engineer;
Liz Edwards: Violin;
Chris Elliott: Conductor, Orchestral Arrangements, Orchestration;
Tom Elmhirst: Mixing;
Cochemea Gastelum: Sax (Baritone);

Any suggestion what I do wrong ?

Thanks Henry

Re: field TRACK NAME and TRACKS

Posted: 2011-11-01 09:13:06
by fulvio53s03
ilobiti wrote:First of All - Thanks for Your great script !!!
When I import the mp3 names into AMC and execute Your script:
a) field TRACK NAME is filled with Artist Name
e.g. Amy Winehouse
b) field TRACKS is filled with the Credits of the songs ? instead the tracks on the album
Any suggestion what I do wrong ?
Thanks Henry
Oh well....
a) how do you import mp3 names? In my script I put Artist name both in Original Title Field and Director Field
b) Which field is TRACKS field?

I think everything could be a little more understandable if you set English language in AMC (which is the language file You are now using?).

:)

TRACK NAME and TRACKS

Posted: 2011-11-01 10:58:21
by ilobiti
I am using the :
MUSIC CATALOG Version 0.91 - Sept 13 2007
with the language file:
MusicCatalog-English.lng
and Your new version of the script.

I add my list as csv files.

I said fields, but it is not the variable name.
It is the name that is shown on the screen.
I add a screenshot.

Image

thanks Henry

Posted: 2011-11-01 16:23:15
by fulvio53s03
@ ilobiti
last official release is 3.5.1 ... I think you should update your program :hihi:
Anyway, your program's behavior is correct, the only problem is about fields names in your language file.
Sorry but My script puts credits in your so-called field "TRACKS" and I'm not intentioned to change it (I have more than 7.000 albums cataloged.....). ;)
Perhaps the better thing you can do is to change your "unofficial" language file....
With friendship
:)

Language file

Posted: 2011-11-01 16:44:29
by ilobiti
I am using 3.5.1.

Which language file do u use ?
The orginal Ant Movie Catalog one ?

thanks Henry

Posted: 2011-11-01 17:12:41
by fulvio53s03
from ilobiti:
MUSIC CATALOG Version 0.91 - Sept 13 2007
with the language file:
MusicCatalog-English.lng
@ilobiti
Well updated.
I Use the Original Ant language
:)