Rel 2.0.1. with minor changes (
' page doesn't contain images).
Code: Select all
(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[Infos]
Authors=Fulvio53s03
Title=Discogs
Description=import album
Site=https://www.discogs.com
Language=IT, EN
Version=2.0.1
Requires=4.2.1.3
Comments=It can be used to search informations (mode=0) and to extract them to your AMC d.b. or to extract directly informations (mode=1), if you already know your album address' page in discogs. For a better selecting informations, you can also supply Artist's name in Original Title field and the information: CD, Album, LP ecc. in Media Type field. 2018.04.03 use https!
License=* The source code of the script can be used in |* another program only if full credits to Fulvio53s03 |* script
GetInfo=1
RequiresMovies=1
[Options]
Mode=1|0|0=normal mode|1=batch mode (url)
Tips=0|0|0=don' show|1=show tips
[Parameters]
***************************************************)
// 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 discogs;
uses
StringUtils7552;
const
discogsUrl = 'https://www.discogs.com'; // base url
batchlogfic = 'c:\Temp_discogs\discogs_batch.txt'; // log for batch mode
debug_search = false; // debug mode on/off su ricerca dischi
debug_album = false; // debug mode on/off su estrazione dati album
folder = 'c:\Temp_discogs\'; // directory where to save files
inizio_e_fine_traccia = '<td class="tracklist_track_pos">';
inizio_credits = '<li>';
fine_credits = '</li>';
trattino = #251;
CRLFspace = CRLF + ' ';
var
cover, cover_1, cover_2, cover_3, addr_cover: String;
titolo_disco: string;
nuovo_anno, mese_anno, solo_anno, data_rilascio, label: String;
Credit_address, Readdress, Address, Page: String;
AlbumName, ArtistName, firstcall, abort, name: string;
Dati_tracce, Dati_credits, autori: String;
Formato, artista: String;
pag_ricerca: String;
Autore, style, Commenti, str_min: String;
campo_companies, campo_note, barcode, releases: String;
Commento, ordine_lista, Salva_autore: String;
value, save_value: string;
CharNormal, CharAbNormal: string;
Album_ok: boolean;
BatchMode, Show_tips: integer;
pos1, pos2: integer;
index, lungo: Integer;
brani, Track, newtrack, old_track, datitrack: String;
titolo_e_autore, titolo: String;
batchlog, confbatch: TstringList;
save_pag, pag_wiki, artist, initchar, endchar, end_info_gen: string;
albumok: boolean;
//------------------------------------------------------------------------------
// DISTINGUI PAGINA DELL'INCISIONE MASTER (PER CD COPIATI) DA INCISIONI SPECIFICHE
//------------------------------------------------------------------------------
procedure distingui_release_e_master;
begin
if pos('/master/', Address) > 0 then
begin
batchlog.Add('incisione_master');
batchlog.SaveToFile(batchlogfic);
incisione_master;
exit;
end
else
begin
batchlog.Add('incisione_release');
batchlog.SaveToFile(batchlogfic);
Incisione_release;
exit;
end
end;
//------------------------------------------------------------------------------
// list of albums
//------------------------------------------------------------------------------
procedure GetList;
var
Urlmusic, album, albumtest, label, genre: String;
Save_address, Title_album, indir_album, indir_title_album: String;
Info_disco, end_disco, artist_album, tipo_release, altri_dati: String;
dati_album, init_list, end_list: String;
Desc_ricerca: String;
ctr_loop: integer;
found: boolean;
i, lgth_dati_album, lgth_pag_ricerca: integer;
// https://www.discogs.com/search/?q=bitches+brew
begin
PickTreeClear; // clear list
Address := discogsUrl + '/search/?q=' + artista + ' ' + AlbumName + '&layout=sm';
Address := UrlEncode(Address);
Desc_ricerca := '"' + AlbumName + '"';
if length(ArtistName) > 0 then
Desc_ricerca := Desc_ricerca + ', ' + ArtistName;
if length(formato) > 0 then
Desc_ricerca := Desc_ricerca + ', ' + formato;
Page := GetPage(Address); //https://www.discogs.com/search/?q=intrigo+bollente&type=all
Save_address := Address;
Page := stringreplace(Page, '–', ' '); //FS2021-03-15 carattere speciale
Page := UTF8decode(Page);
SetField(fieldURL, Address);
HTMLdecode(Page);
found := False;
// PickTreeAdd('List of albums found for' + '"' + AlbumName + '"', '');
PickTreeAdd('List of albums found for ' + Desc_ricerca, '');
if debug_search then
DumpPage(folder+'discogsList.html', Page); // debug
if Pos('find anything', Page) <> 0 then
begin
LogMessage('Error while reading selection page - no results found for ' + Desc_ricerca);
ShowMessage('Non trovato: ' + Artista + ' - ' + Albumname);
albumok := True; //FS2021-03-15
exit;
end;
// init_list := '<div class="pagination_controls ">';
// end_list := '<div class="pagination bottom ">';
init_list := '<div id="pjax_container">'; //Intrigo - Bollente
end_list := '<div class="sticky_footer">'; //Intrigo - Bollente
pag_ricerca := init_list + TextBetween(Page, init_list, end_list) + end_list; //elenco titoli richiesti
lgth_pag_ricerca := length(pag_ricerca);
Normalizza_Page(pag_ricerca);
info_disco := '<div class="card_body">';
end_disco := '<div class="card_actions">'; //2021-03-15 Bollente
save_pag := pag_ricerca;
if debug_search then
DumpPage(folder+'discogs_pag_ricerca.html', pag_ricerca); // debug
// dati_album := info_disco + TextBetween (pag_ricerca, info_disco, info_disco) + info_disco; //2021-03-15 Bollente
dati_album := info_disco + TextBetween (pag_ricerca, info_disco, end_disco) + info_disco; //2021-03-15 Bollente
//dati_album contiene recursivamente i dati degli album
lgth_dati_album := length(dati_album);
if debug_search then
DumpPage(folder+'discogs_dati_album.html', dati_album); // debug
delete(Pag_ricerca, 1, length(dati_album) - length(endchar));
ctr_loop := 0;
lungo := (Length(info_disco) + length(info_disco));
while (lgth_dati_album > Lungo) and (ctr_loop < 50) do //estraggo al massimo 50 titoli
begin
ctr_loop := ctr_loop + 1;
initchar := '<a class="search_result_title';
endchar := '</a>';
indir_title_album := textBetween(dati_album, initchar, endchar) + endchar;
initchar := 'href="';
endchar := '"';
Address := discogsUrl + textBetween(indir_title_album,initchar, endchar);
initchar := '<a href="/artist';
endchar := '</span>';
artist_album := textBetween(dati_album,initchar, endchar); //Artista
initchar := '>';
endchar := '<';
artist_album := textBetween(artist_album,initchar, endchar); //Artista
initchar := '>';
endchar := '</a>';
Title_album := textBetween(indir_title_album,initchar, endchar); //titolo dell'album
initchar := '<p class="card_status">';
endchar := '</p>';
tipo_release := textbetween(dati_album, initchar, endchar);
tipo_release := FormatText(tipo_release); //tipo release
initchar := '<p class="card_info">';
endchar := '</p>';
altri_dati := textbetween(Dati_album, initchar, endchar);
altri_dati := FormatText(altri_dati);
Title_Album := artist_album + ' - ' + Title_Album + ' (' + tipo_release + ', ' + altri_dati + ')';
Title_Album := stringreplace(Title_Album, CRLF, '');
Title_Album := stringreplace(Title_Album, ' Needs Vote,', '');
PickTreeAdd(Title_Album, Address);
found := True;
delete(Pag_ricerca, 1, lgth_dati_album);
Pag_ricerca := Pag_ricerca + info_disco; //fs 2015_01_12
lgth_pag_ricerca := length(Pag_ricerca);
dati_album := info_disco + TextBetween (pag_ricerca, info_disco, end_disco); //recursivamente i dati degli album
lgth_dati_album := length(Dati_album);
end;
if not found then
begin
LogMessage('No album found for '+AlbumName);
albumok := True; //FS2021-03-14
exit;
end;
if PickTreeExec(Address) then
begin
AnalyzeMusicPage; // Album page
end
else
LogMessage('No album selected');
end;
//-------------------------------- Specifiche Record
Procedure Incisione_release;
//-------------------------------- Specifiche Record
begin
// seconda distinzione: lay-out della pagina
release_tipo_pagina;
//*** artists
initchar := '<section id="release-credits"';
endchar := '</section>';
Value := TextBetween(Page, initchar, endchar);
batchlog.Add('release image');
batchlog.SaveToFile(batchlogfic);
//https://www.discogs.com/Ahmad-Jamal-Volume-1-The-Three-Strings/release/5906035
// Gong-Flying-Teapot-Radio-Gnome-Invisible-Part-1
//https://www.discogs.com/release/5906035-Volume-1-The-Three-Strings/images
//FS2021-03-15 sostituito Albumname con fieldurl con Address
Address := Address; //debug
cover_1 := 'https://www.discogs.com' + '/release/';
cover_2 := textafter(Address, '/release/') + '-';
cover_3 := textbetween(Address, 'https://www.discogs.com/', '/release/') + '/images';
addr_cover := cover_1 + cover_2 + cover_3;
if CanSetPicture then
estrai_immagine;
end;
//-------------------------------- Specifiche Record
Procedure Incisione_master;
//-------------------------------- Specifiche Record
begin
// seconda distinzione: lay-out della pagina
master_tipo_pagina;
//*** artists
initchar := '<section id="release-credits"';
endchar := '</section>';
Value := TextBetween(Page, initchar, endchar);
batchlog.Add('master image');
batchlog.SaveToFile(batchlogfic);
addr_cover := TextBetween(Page, 'class="image_gallery image_gallery_large"', '</div>');
addr_cover := TextBetween(addr_cover, 'href="', '"');
cover_1 := 'https://www.discogs.com';
cover_2 := cover_1 + addr_cover;
addr_cover := cover_2;
if CanSetPicture then
estrai_immagine;
end;
//******************** inizio nuova estrazione credits *****************************************
Procedure estrazione_credits_release;
var
lgth_track: integer;
oldtrack: string;
Begin
// normalizza_page(Value); //fs2015.01.15
initchar := inizio_credits;
endchar := fine_credits;
oldtrack := '';
lungo := (Length(initchar) + length(endchar));
Dati_tracce := initchar + TextBetween(Value, initchar, endchar) + endchar;
// if debug_album then
// DumpPage(folder+'discogsinfo_dati_tracce.html', Value);
while Length(Dati_tracce) > Lungo do //esegui se trovato qualcosa
begin
datitrack := '';
track := '';
initchar := '<span class="role';
endchar := '</span>';
datitrack := initchar + textbetween(dati_tracce, initchar, endchar) + endchar + ' '; //ruolo
HTMLRemoveTags(datitrack);
initchar := 'class="rollover_link">';
endchar := '</li>';
track := textbetween(dati_tracce, initchar, endchar);
HTMLRemoveTags(track);
if length(track) = 0 then
begin
initchar := '</span>';
track := textbetween(dati_tracce, initchar, endchar);
end;
track := FormatText(track);
track := StringReplace(track, CRLF, '');
datitrack := datitrack + fulltrim(track); //nomi
datitrack := stringReplace(datitrack, '*', ''); //fs2015.01.21
// dati del brano raccolti in datitrack
if track <> oldtrack then
brani := brani + datitrack + CRLF;
oldtrack := track;
// reimposto l'area su cui loopare
initchar := inizio_credits;
endchar := fine_credits;
delete(Value, 1, length(Dati_tracce) - length(inizio_credits));
dati_tracce := initchar + TextBetween (Value, initchar, endchar) + endchar;
end;
brani := brani; //per debug
end;
//fs ********************* fine nuova estrazione credits *****************************************
//******************** inizio nuova estrazione credits *****************************************
Procedure estrazione_tracce_release;
var
lgth_track: integer;
oldtrack: string;
Begin
if debug_album then
DumpPage(folder+'discogs_tracce_release.html', value);
if pos('aria-hidden="true"', Page) > 0 then //FS2021-03-14
begin //FS2021-03-14
pag_wiki := Value; //FS2021-03-14
pulisci_wiki_collaterali; //FS2021-03-14
Value := pag_wiki; //FS2021-03-14
end; //FS2021-03-14
value := stringreplace(value, '</tr>', (CRLF + '</tr>'));
// pos1 := pos('<div class="measure<div>', value); //A3 Machine Song*** Credits = Acoustic Guitar, Piano –
// value := stringreplace(value, '<div class="credits_12-wp">', ('xyz xyz *** Credits = ')); //FS2021-03-14
pos1 := pos('</span> – <span', value); //A3 Machine Song*** Credits = Acoustic Guitar, Piano –
value := stringreplace(value, '<div><span>', ('<div><span>' + 'xyz xyz')); //FS2021-03-14
value := stringreplace(value, '</td>', ('xyz' + '</td>'));
value := stringreplace(value, '<span', ('xyz' + '<span'));
value := stringreplace(value, '</span> – <span', '</span>:<span');
value := Formattext(value);
value := stringreplace(value, 'xyz xyz', ' -');
value := stringreplace(value, 'xyz', ' ');
brani := value;
end;
//fs ********************* fine nuova estrazione credits *****************************************
//******************** inizio nuova estrazione credits per incisione master**************************
Procedure estrazione_credits_master;
var
lgth_track: integer;
oldtrack: string;
Begin
Dati_credits := Value;
// if debug_album then
// DumpPage(folder+'discogscredits_master.html', dati_credits);
Dati_credits := RemoveSpaces(Dati_credits, True);
dati_credits := stringreplace(dati_credits, '<li>', (CRLF + '<li>'));
dati_credits := stringreplace(dati_credits, '<span class="credits_info">', ('<span class="credits_info">' + ' - '));
dati_credits := FormatText(dati_credits);
Dati_credits := stringreplace(dati_credits, (CRLF + ' '), CRLF);
// HtmlRemoveTags(dati_credits);
brani := Dati_credits; //per debug
end;
//fs ********************* fine nuova estrazione credits *****************************************
//------------------------------------------------------------------------------
// RELEASE - estrazione dati tipo pagina 1 generali (titolo, autore, casa, genere ecc.)
//------------------------------------------------------------------------------
procedure release_pagina_1;
var
info_generali, temp: string;
begin
info_generali := initchar + TextBetween(Page, initchar, end_info_gen) + end_info_gen;
// if debug_album then
// DumpPage(folder+'discogsinfo_release_pag1.html', info_generali);
//************* produttore
initchar := '<div class="content_3IW3p">'; //fs2021-01-29
endchar := '</div>'; //fs2021-01-29
temp := initchar + textbetween(info_generali, initchar, endchar); //fs2021-01-29
HtmlRemoveTags(temp); //fs2021-01-29
temp := StringReplace(temp, 'Label', ''); //fs2021-01-29
label := fulltrim(temp);
initchar := '<div class="label_2GDTZ">Series'; //fs2021-01-29 Label - Series
endchar := '<div class="label_2GDTZ">Format'; //fs2021-01-29
temp := initchar + textbetween(info_generali, initchar, endchar); //fs2021-01-29
HtmlRemoveTags(temp); //fs2021-01-29
temp := StringReplace(temp, 'Series', '');
if length(fulltrim(temp)) > 0 then //fs2021-01-29
label := label + ' - ' + fulltrim(temp); //fs2021-01-29
SetField(fieldproducer, label);
//******** fine produttore
//************* Artista (Titolo Originale) e titolo album
initchar := '<h1 class="header_3FV2N">';
endchar := '</h1>';
label := initchar + textbetween(info_generali, initchar, endchar) + endchar;
initchar := '<span class="link_15cpV">';
endchar := '</span>';
artista := textbetween(label, initchar, endchar);
HtmlRemoveTags(Artista);
SetField(fieldOriginalTitle, artista);
HtmlRemoveTags(label);
label := stringreplace(label, artista, '');
// titolo_disco := textafter(label, trattino);
Delete(label, 1, 2); //cancella divisore e spazio iniziali
titolo_disco := fulltrim(label);
SetField(fieldtranslatedTitle, titolo_disco);
initchar := '<div class="label_2GDTZ">Country';
endchar := '<div class="label_2GDTZ">Released';
label := textbetween(info_generali, initchar, endchar);
label := FormatText(label);
label:=stringReplace(label, ':', '');
SetField(fieldcountry, label); //paese
initchar := '<div class="label_2GDTZ">Released';
endchar := '</a>';
label := textbetween(info_generali, initchar, endchar);
label := textbetween(label, 'year=', '"');
SetField(fieldyear, label);
initchar := '<div class="label_2GDTZ">Genre';
endchar := end_info_gen;
temp := textbetween(info_generali, initchar, endchar);
label := FormatText(temp);
endchar := textafter(label, 'Style:'); //divisore iniziale per lo stile
if endchar = '' then
label := StringReplace(label, 'Style:', '')
else
label := StringReplace(label, 'Style:', ' Style: ');
label:=stringReplace(label, ':', '');
SetField(fieldcategory, label); //genere e style (se presente)
value := '';
initchar := '<h3>Credits</h3>';
endchar := '<h3>Notes</h3>';
// ------------------ altri H3 ---------------------
//<h3>Barcode and Other Identifiers</h3> //<h3>Other Versions</h3>
//<h3>Recommendations</h3> //<h3>Reviews</h3>
pos1 := pos(initchar, Page);
pos2 := pos(endchar, Page);
Value := TextBetween(Page, initchar, endchar);
if value = '' then
begin
endchar := '<h3>Barcode and Other Identifiers</h3>';
Value := TextBetween(Page, initchar, endchar);
end;
// if debug_album then
// DumpPage(folder+'discogscredits.html', Value);
batchlog.Add('Release 1 credits');
batchlog.SaveToFile(batchlogfic);
brani := '';
estrazione_credits_release;
value := brani; //fs2015.01.21
value := stringreplace(value, ' ', ' '); //fs2015.01.21
SetField(fieldActors, value); //fs2021-02-19
initchar := '<table class="';
endchar := '</table>';
value := initchar + textBetween(Page, initchar, endchar) + endchar;
estrazione_tracce_release;
value := brani;
SetField(FieldDescription, Value);
//*** companies class="section companies
campo_companies := '';
initchar := '<section id="release-companies"';
endchar := '</section>';
campo_companies := initchar + TextBetween(Page, initchar, endchar) + endchar;
begin
// campo_companies := StringReplace(campo_companies, '<br><br>', CRLF); //mancano i barcode
// campo_companies := StringReplace(campo_companies, '</h3>', ('</h3>' + CRLF)); //mancano i barcode
campo_companies := StringReplace(campo_companies, '</li>', (CRLF + '</li>'));
campo_companies := StringReplace(campo_companies, '</h3>', (CRLF + '</h3>'));
HTMLRemoveTags(campo_companies);
end;
//*** note
initchar := '<section id="release-notes"';
endchar := '<div class="main_2FbVC"';
campo_note := initchar + TextBetween(Page, initchar, endchar);
// if debug_album then
// DumpPage(folder+'discogsrelease1_note.html', campo_note);
if campo_note <> (initchar + endchar) then
begin
campo_note := StringReplace(campo_note, '<br><br>', CRLF); //mancano i barcode
campo_note := StringReplace(campo_note, '</h3>', ('</h3>' + CRLF)); //mancano i barcode
HTMLRemoveTags(campo_note);
end
else
campo_note := '';
//*** barcode
initchar := '<section id="release-barcodes"';
endchar := '<div class="main_2FbVC"';
barcode := initchar + TextBetween(Page, initchar, endchar);
// if debug_album then
// DumpPage(folder+'discogsrelease1_barcode.html', barcode);
if campo_note <> (initchar + endchar) then
begin
barcode := StringReplace(barcode, '</li>', (CRLF + '</li>'));
barcode := StringReplace(barcode, '</h3>', ('</h3>' + CRLF));
HTMLRemoveTags(barcode);
end
else
barcode := '';
Value := '';
if barcode <> '' then
Value := barcode;
if campo_note <> '' then
Value := campo_note + Value;
if campo_companies <> '' then
Value := campo_companies + CRLF + value;
value := stringreplace(Value, (CRLF + CRLF), CRLF);
SetField(fieldComments, value);
//Companies, etc.Phonographic Copyright ? Distribution MusidiscMade By MPObbb Notes
//aaa Barcode and Other Identifiers
//Barcode: 3 229265 566428
//Matrix / Runout: MCD 139231 MPO 01 @
//Price Code: MU 760
//SPARS CODE: AAD
//Rights Society: [logo] SACEM SGDL SACD SDRM
end;
//------------------------------------------------------------------------------
procedure MyTrim;
var
newfield, oldfield: string;
begin
NewField := ' ';
OldField := #9;
value := StringReplace(Value, OldField, NewField);
OldField := #10;
value := StringReplace(Value, OldField, NewField);
value := StringReplace(Value, OldField, NewField);
end;
//------------------------------------------------------------------------------
// RELEASE - estrazione dati tipo pagina 2 generali (titolo, autore, casa, genere ecc.)
//------------------------------------------------------------------------------
procedure release_pagina_2;
var
info_generali, temp: string;
begin
info_generali := initchar + TextBetween(Page, initchar, end_info_gen) + end_info_gen;
if debug_album then
DumpPage(folder+'discogsinfo_generali_t1.html', Value);
initchar := '<div class="label_2GDTZ">Label'; //fs2021-01-29
endchar := '<div class="label_2GDTZ">Series'; //fs2021-01-29
temp := initchar + textbetween(value, initchar, endchar); //fs2021-01-29
HtmlRemoveTags(temp); //fs2021-01-29
temp := StringReplace(temp, 'Label:', ''); //fs2021-01-29
label := fulltrim(temp);
// proseguire con le correzioni
initchar := '<div class="label_2GDTZ">Series'; //fs2021-01-29
endchar := '<div class="label_2GDTZ">Format'; //fs2021-01-29
temp := initchar + textbetween(value, initchar, endchar); //fs2021-01-29
HtmlRemoveTags(temp); //fs2021-01-29
temp := StringReplace(temp, 'Label:', '');
if length(fulltrim(temp)) > 0 then //fs2021-01-29
label := label + ' - ' + fulltrim(temp); //fs2021-01-29
SetField(fieldproducer, label);
initchar := '<h1 id="profile_title"';
endchar := '</h1>';
label := initchar + textbetween(Value, initchar, endchar) + endchar;
initchar := '<span title="';
endchar := '</span>';
// endchar := '-';
artista := initchar + textBetween(label, '<span title="', endchar) + endchar;
label := stringreplace(label, artista, '');
HtmlRemoveTags(artista);
artista := fulltrim(artista);
SetField(fieldOriginalTitle, artista);
initchar := '</span>';
endchar := '<span>';
artista := initchar + textBetween(label, initchar, endchar) + endchar;
label := stringreplace(label, artista, '');
HtmlRemoveTags(label);
titolo_disco := fulltrim(label);
SetField(fieldtranslatedTitle, titolo_disco);
initchar := '<div class="head">Format:</div>'; //formato LP/Album/CD/ristampa ecc.
endchar := '</div>';
label := textbetween(Value, initchar, endchar) + endchar;
label := FormatText(label);
label := stringReplace(label, CRLF, '');
label := stringreplace (label, ' ', ' ');
label := stringreplace (label, ' ', ' ');
SetField(fieldvideoformat, label); //formato
initchar := '<div class="profile">';
endchar := '</div>';
label := textbetween(Value, '<div class="head">Country:</div>', endchar) + endchar;
label := FormatText(label);
SetField(fieldcountry, label); //paese
label := textbetween(Value, '<div class="head">Released:</div>', endchar) + endchar;
label := FormatText(label);
SetField(fieldyear, label);
//fs20150728 estrazione data della release
nuovo_anno := getfield(fieldYear); //fs20150728 //anno
if length(nuovo_anno) = 0 then
estrai_data_released;
label := textbetween(Value, '<div class="head">Genre:</div>', endchar) + endchar;
label := FormatText(label);
style := textbetween(Value, '<div class="head">Style:</div>', endchar) + endchar;
style := FormatText(style);
if length(style) > 0 then
label := label + ' (' + style + ')';
SetField(fieldcategory, label); //genere
//*********************fine dati generali ****************************
initchar := '<section id="release-credits"';
endchar := '</section>';
Value := TextBetween(Page, initchar, endchar);
if debug_album then
DumpPage(folder+'discogscredits.html', Value);
batchlog.Add('Release 2 credits');
batchlog.SaveToFile(batchlogfic);
brani := '';
estrazione_credits_release;
value := brani; //fs2015.01.21
value := stringreplace(value, ' ', ' '); //fs2015.01.21
SetField(fieldActors, value); //fs2021-02-19
end;
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// MASTER - estrazione dati tipo pagina 1 generali (titolo, autore, casa, genere ecc.)
//------------------------------------------------------------------------------
procedure master_pagina_1;
var
info_generali, temp: string;
begin
info_generali := initchar + TextBetween(Page, initchar, end_info_gen) + end_info_gen;
// if debug_album then
// DumpPage(folder+'discogsinfo_generali_t1.html', info_generali);
//************* produttore
initchar := '<div class="content_3IW3p">'; //fs2021-01-29
endchar := '</div>'; //fs2021-01-29
temp := initchar + textbetween(info_generali, initchar, endchar); //fs2021-01-29
HtmlRemoveTags(temp); //fs2021-01-29
temp := StringReplace(temp, 'Label', ''); //fs2021-01-29
label := fulltrim(temp);
initchar := '<div class="label_2GDTZ">Series'; //fs2021-01-29 Label - Series
endchar := '<div class="label_2GDTZ">Format'; //fs2021-01-29
temp := initchar + textbetween(info_generali, initchar, endchar); //fs2021-01-29
HtmlRemoveTags(temp); //fs2021-01-29
temp := StringReplace(temp, 'Series', '');
if length(fulltrim(temp)) > 0 then //fs2021-01-29
label := label + ' - ' + fulltrim(temp); //fs2021-01-29
SetField(fieldproducer, label);
//************* Artista (Titolo Originale) e titolo album
initchar := '<h1 class="header_3FV2N">';
endchar := '</h1>';
label := initchar + textbetween(info_generali, initchar, endchar) + endchar;
initchar := '<span class="link_15cpV">';
endchar := '</span>';
artista := textbetween(label, initchar, endchar);
HtmlRemoveTags(Artista);
SetField(fieldOriginalTitle, artista);
HtmlRemoveTags(label);
label := stringreplace(label, artista, '');
// titolo_disco := textafter(label, trattino);
Delete(label, 1, 2); //cancella divisore e spazio iniziali
titolo_disco := fulltrim(label);
SetField(fieldtranslatedTitle, titolo_disco);
initchar := '<div class="label_2GDTZ">Country';
endchar := '<div class="label_2GDTZ">Released';
label := textbetween(info_generali, initchar, endchar);
label := FormatText(label);
label:=stringReplace(label, ':', '');
SetField(fieldcountry, label); //paese
initchar := '<div class="label_2GDTZ">Released';
endchar := '</a>';
label := textbetween(info_generali, initchar, endchar);
label := textbetween(label, 'year=', '"');
SetField(fieldyear, label);
initchar := '<div class="label_2GDTZ">Genre';
endchar := end_info_gen;
temp := textbetween(info_generali, initchar, endchar);
label := FormatText(temp);
endchar := textafter(label, 'Style:'); //divisore iniziale per lo stile
if endchar = '' then
label := StringReplace(label, 'Style:', '')
else
label := StringReplace(label, 'Style:', ' Style: ');
label:=stringReplace(label, ':', '');
SetField(fieldcategory, label); //genere e style (se presente)
initchar := '<section id="release-credits"';
endchar := '</section>';
Value := TextBetween(Page, initchar, endchar);
if debug_album then
DumpPage(folder+'discogscredits.html', Value);
batchlog.Add('Master 1 credits');
batchlog.SaveToFile(batchlogfic);
brani := '';
estrazione_credits_master;
value := brani; //fs2015.01.21
value := stringreplace(value, ' ', ' '); //fs2015.01.21
SetField(fieldActors, value); //fs2021-02-19
initchar := '<table class="playlist">';
endchar := '</table>'
value := textBetween(Page, initchar, endchar);
estrazione_tracce_master;
value := brani;
SetField(FieldDescription, Value);
end;
//------------------------------------------------------------------------------
procedure estrazione_tracce_master;
var
info_generali, temp: string;
begin
Dati_tracce := Value;
// Dati_tracce := RemoveSpaces(Dati_tracce, True);
if debug_album then
DumpPage(folder+'discogstracce_master.html', dati_tracce);
Dati_tracce := RemoveSpaces(Dati_tracce, True);
dati_tracce := stringreplace(dati_tracce, '<tr class=', (CRLF + '<tr class='));
dati_tracce := stringreplace(dati_tracce, '<td class=', ('<td class=' + 'xyz-xyz'));
dati_tracce := stringreplace(dati_tracce, '<span class="tracklist_track_title">',
('xyz-xyz' + '<span class="tracklist_track_title">'));
dati_tracce := stringreplace(dati_tracce, '</a>*</td>','</a></td>');
dati_tracce := FormatText(dati_tracce);
dati_tracce := stringreplace(dati_tracce,'xyz', ' ');
Dati_tracce := stringreplace(dati_tracce, (CRLF + ' '), CRLF);
// HtmlRemoveTags(dati_credits);
brani := Dati_tracce; //per debug
end;
//------------------------------------------------------------------------------
// MASTER - estrazione dati tipo pagina 2 generali (titolo, autore, casa, genere ecc.)
//------------------------------------------------------------------------------
procedure master_pagina_2;
var
info_generali, temp: string;
begin
info_generali := initchar + TextBetween(Page, initchar, end_info_gen) + end_info_gen;
if debug_album then
DumpPage(folder+'discogsinfo_master_pag2.html', info_generali);
//************* nessun produttore per incisione master
SetField(fieldproducer, 'Master/Generic Release');
//******** fine produttore
initchar := '<h1 id="profile_title"'; //2021-03-12
endchar := '</h1>';
label := initchar + textbetween(Page, initchar, endchar) + endchar;
initchar := '<span title="';
endchar := '</span>';
// endchar := '-';
artista := initchar + textBetween(label, '<span title="', endchar) + endchar;
label := stringreplace(label, artista, '');
HtmlRemoveTags(artista);
artista := fulltrim(artista);
SetField(fieldOriginalTitle, artista);
initchar := '</span>';
endchar := '<span>';
artista := initchar + textBetween(label, initchar, endchar) + endchar;
label := stringreplace(label, artista, '');
initchar := '<span>';
endchar := '</span>';
label := initchar + textBetween(label, initchar, endchar) + endchar;
HtmlRemoveTags(label);
titolo_disco := fulltrim(label);
SetField(fieldtranslatedTitle, titolo_disco);
//*********** nessun formato per incisione master;
//formato LP/Album/CD/ristampa ecc. SetField(fieldvideoformat, label); //formato
initchar := '<div class="head">Genre:</div>';
endchar := '<div class="head">Year:</div>';
label := textbetween(info_generali, initchar, endchar);
HtmlRemoveTags(label);
label := stringreplace(label, 'Style:', ' ');
label := fulltrim(label);
SetField(fieldcategory, label);
// SetField(fieldcountry, label); //paese non presente nell'incisione master
initchar := '<div class="head">Year:</div>';
endchar := '</div>';
label := textbetween(info_generali, initchar, endchar);
label := FormatText(label);
SetField(fieldyear, label);
//*********************fine dati generali ********************************
pos1 := pos('class="section master-release-credits', Page);
initchar := 'class="section master-release-credits';
endchar := '<!-- /master credits -->';
Value := '<div ' + TextBetween(Page, initchar, endchar);
if debug_album then
DumpPage(folder+'discogscredits_master 2.html', Value);
batchlog.Add('Master 2 credits');
batchlog.SaveToFile(batchlogfic);
brani := '';
estrazione_credits_master;
value := brani; //fs2015.01.21
value := stringreplace(value, ' ', ' '); //fs2015.01.21
SetField(fieldActors, value); //fs2021-02-19
initchar := '<table class="playlist">';
endchar := '</table>';
value := textBetween(Page, initchar, endchar);
estrazione_tracce_master;
value := brani;
SetField(FieldDescription, Value);
//*** note non presenti su master release
value := 'Master release. No comments'; //FS20210314
SetField(fieldComments, value);
end;
//------------------------------------------------------------------------------
procedure estrai_data_released;
begin
// ShowMessage('data di rilascio ' + nuovo_anno);
label := StringReplace(label, ' ', '/');
data_rilascio := label;
mese_anno := Textafter(data_rilascio, '/');
solo_anno := Textafter(mese_anno, '/');
if length(solo_anno) > 0 then
begin
setfield(fieldyear, solo_anno);
end
else
setfield(fieldyear, solo_anno);
end;
//------------------------------------------------------------------------------
procedure master_tipo_pagina;
begin
initchar := '<section id="release-stats"';
end_info_gen := '<section id="release-tracklist"';
pos1 := pos(initchar, Page);
pos2 := pos(end_info_gen, Page);
if (pos1 > 0) and (pos2 > 0) then
begin
ShowMessage('Master pagina 1 da verificare!');
master_pagina_1;
batchlog.Add('Tipo pagina = 1');
batchlog.SaveToFile(batchlogfic);
exit;
end;
initchar := '<div class="profile">';
end_info_gen := '<div id="tracklist" class="section tracklist"';
pos1 := pos(initchar, Page);
pos2 := pos(end_info_gen, Page);
if (pos1 > 0) and (pos2 > 0) then
begin
master_pagina_2;
batchlog.Add('Tipo pagina = 2');
batchlog.SaveToFile(batchlogfic);
exit;
end;
end;
procedure pulisci_wiki_collaterali;
var
init_wikinote, end_wikinote, wikinote: string;
credits_hidden: string; //non visibile in codice pagina, creato tramite javascript nel codice estratto
posizione: integer;
begin
init_wikinote := '<div class="credits';
end_wikinote := '<div class="measure';
wikinote := textbetween(pag_wiki, init_wikinote, end_wikinote);
wikinote := init_wikinote + wikinote; //ricostruisco tag html
// wikinote := init_wikinote + wikinote + end_wikinote; //ricostruisco tag html
posizione := pos(init_wikinote, pag_wiki);
while posizione > 0 do
begin
pag_wiki := stringreplace(pag_wiki, wikinote, '');
wikinote := textbetween(pag_wiki, init_wikinote, end_wikinote); //elimina note wiki da trama
// wikinote := init_wikinote + wikinote + end_wikinote;
wikinote := init_wikinote + wikinote + end_wikinote;
pag_wiki := stringreplace(pag_wiki, wikinote, '');
posizione := pos(init_wikinote, pag_wiki);
end
// credits_hidden := '<div class="measure_17Kyu credits_12-wp" aria-hidden="true"><div>'; //mantenere in attesa di verifica
credits_hidden := '_17Kyu credits_12-wp" aria-hidden="true">';
pag_wiki := stringreplace(pag_wiki, credits_hidden, ''); //fine pulizia [......]
// if debug_album then
// DumpPage(folder+'discogswikinote.html', pag_wiki); // debug_album
end;
//------------------------------------------------------------------------------
procedure release_tipo_pagina;
begin
initchar := '<section id="release-stats"';
end_info_gen := '<section id="release-tracklist"';
pos1 := pos(initchar, Page);
pos2 := pos(end_info_gen, Page);
if (pos1 > 0) and (pos2 > 0) then
begin
batchlog.Add('release pagina = 1');
batchlog.SaveToFile(batchlogfic);
release_pagina_1;
exit;
end;
initchar := '<div class="profile">';
end_info_gen := '<div id="tracklist" class="section tracklist"';
pos1 := pos(initchar, Page);
pos2 := pos(endchar, Page);
if (pos1 > 0) and (pos2 > 0) then
begin
ShowMessage('Release pagina 2 da verificare!');
batchlog.Add('release pagina = 2');
batchlog.SaveToFile(batchlogfic);
release_pagina_2;
exit;
end;
end;
//------------------------------------------------------------------------------
// ANALYZE MUSIC PAGE
//------------------------------------------------------------------------------
procedure AnalyzeMusicPage;
var
urlmusic, Lenght, Pays: String;
minu, minuti, ore, lgth_comm, save_lgth_comm, i: integer;
j: Real;
begin
Page := GetPage(Address);
Page := stringreplace(Page, '–', ' '); //FS2021-03-15 carattere speciale
Page := UTF8decode(Page);
HTMLdecode(Page);
if debug_album then
DumpPage(folder+'discogsPageDetailHTMLdecode.html', Page); // debug_album
Page := StringReplace(Page, '>Hide Credits<', '><');
Readdress := '';
Readdress := textbetween(Page, '<meta property="og:url" content="', '">');
if length(Readdress) > 0 then
Address := Readdress;
if Pos('<div class="head', Page) = 0 then //inizio dati da estrarre
Begin
ShowMessage('Pagina album errata - Error while reading album page');
exit;
end;
SetField(fieldURL, Address);
SetField(fieldDate, DateToStr(Date));
Normalizza_Page(Page);
albumok := True;
// prima distinzione: tipo di informazioni (incisione master o release specifica)
distingui_release_e_master;
end;
procedure estrai_immagine;
Begin
Page := GetPage(addr_cover); //pagina delle locandina
Page := UTF8decode(Page);
pos1 := pos('There are no images', Page);
if pos1 = 0 then
begin
addr_cover := TextBetween(Page, '<div id="view_images">', '</div>');
addr_cover := Textbetween(addr_cover, '<img src="', '"');
GetPicture(addr_cover); //prima locandina
end;
end;
Procedure Normalizza_page(Pagina: string); // elimina i crlf, trasforma delimiters maiuscoli in minuscoli
begin
pagina := RegExprSetReplace('<([^>]+)>', pagina, '<\L\1>', true);
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 := '<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 normal mode
//------------------------------------------------------------------------------
procedure discogsNorm;
begin
albumok := False;
AlbumName := GetField(fieldTranslatedTitle); // get album name
ArtistName := getField(fieldOriginalTitle); // get artist
if Show_tips = 1 then
begin
confbatch := TStringList.Create;
confbatch.Add('You have selected the normal mode:');
confbatch.Add('if You supply artist name in Original Title field,');
confbatch.Add('I will search discogs database using both');
confbatch.Add('artist and album name.');
confbatch.Add('Results will be more accurate!');
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
repeat
if not Input('discogs = ' + ArtistName + ' - ' + AlbumName, 'Enter the name of the album :'
+ crlf, AlbumName) or (AlbumName = '') then exit;
formato := getfield(fieldmediatype);
if pos(formato, 'cd') > 0 then
formato:= 'CD';
artista := Artistname;
GetList;
until albumok;
end;
//------------------------------------------------------------------------------
// start here
//------------------------------------------------------------------------------
begin
if abort = 'o' then exit; // batch mode aborted
createfolder(folder); //c:\Temp\discogs
if firstcall <> 'done' then
begin // 1st call: init parameters
firstcall := 'done';
if not CheckVersion(4,2,1) then
begin
ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 4.2.1.3)');
abort := 'o';
exit;
end;
// get user's parms (used more than once)
BatchMode := GetOption('Mode');
Show_tips := GetOption('Tips');
// if BatchMode > -1 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);
confbatch := TStringList.Create;
// confirmation message
if Show_tips = 1 then
begin
confbatch.Add('You selected the batch mode: / Hai selezionato il modo Batch:');
confbatch.Add('Did you save your database? / Hai salvato il Database?');
confbatch.Add('*** Supply Addresses to extract in Url Field Url / Fornisci gli indirizzi da estrarre nel campo 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;
end;
// let's go
if BatchMode = 0 then
discogsNorm
else
begin
AlbumName := GetField(fieldUrl); // if no url or another site then ignore
Albumname := stringreplace(Albumname, 'http://', 'https://'); //2018-04-02 oldaddresses
Address := Albumname;
AnalyzeMusicPage; //directly to page to extract
end;
end.