|
unit MauryMp3Tag;
interface
uses
SysUtils, Classes;
type
TTag = packed record
Tag : array[0..2] of Char;
Titolo,
Artista,
Album : array[0..29] of Char;
Anno : array[0..3] of Char;
Commento : array[0..29] of Char;
Genere : Byte;
end;
TMauryMp3Tag = class(TComponent)
private
FFilename: TFileName;
ftitolo: string;
fAlbum: string;
fartista: string;
fAnno: string;
fCommento: string;
fGenere: string;
fGenereB: byte;
procedure Set_Filename(const Value: TFileName);
procedure GetMp3tag(mp3File: string);
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
published
{ Published declarations }
property FileName : TFileName read FFilename write Set_Filename;
property Titolo : string index 1 read ftitolo write ftitolo;
property Artista : string index 2 read fartista write fartista;
property Commento : string index 3 read fCommento write fCommento;
property Album : string index 4 read fAlbum write fAlbum;
property Anno : string index 5 read fAnno write fAnno;
property Genere : string index 6 read fGenere write fGenere;
property GenereB : byte index 7 read fGenereB write fGenereB;
procedure SetTag(mp3File, STitolo, SArtista, SAlbum, SAnno,
SCommento: string; SGenere: byte);
end;
procedure Register;
implementation
const
Max=147;
Generi: array[0..Max] of string = (
'Blues', 'Classic Rock', 'Country', 'Dance', 'Disco', 'Funk', 'Grunge',
'Hip-Hop', 'Jazz', 'Metal', 'New Age', 'Oldies', 'Other', 'Pop', 'R&B',
'Rap', 'Reggae', 'Rock', 'Techno', 'Industrial', 'Alternative', 'Ska',
'Death Metal', 'Pranks', 'Soundtrack', 'Euro-Techno', 'Ambient',
'Trip-Hop', 'Vocal', 'Jazz+Funk', 'Fusion', 'Trance', 'Classical',
'Instrumental', 'Acid', 'House', 'Game', 'Sound Clip', 'Gospel',
'Noise', 'AlternRock', 'Bass', 'Soul', 'Punk', 'Space', 'Meditative',
'Instrumental Pop', 'Instrumental Rock', 'Ethnic', 'Gothic',
'Darkwave', 'Techno-Industrial', 'Electronic', 'Pop-Folk',
'Eurodance', 'Dream', 'Southern Rock', 'Comedy', 'Cult', 'Gangsta',
'Top 40', 'Christian Rap', 'Pop/Funk', 'Jungle', 'Native American',
'Cabaret', 'New Wave', 'Psychadelic', 'Rave', 'Showtunes', 'Trailer',
'Lo-Fi', 'Tribal', 'Acid Punk', 'Acid Jazz', 'Polka', 'Retro',
'Musical', 'Rock & Roll', 'Hard Rock', 'Folk', 'Folk-Rock',
'National Folk', 'Swing', 'Fast Fusion', 'Bebob', 'Latin', 'Revival',
'Celtic', 'Bluegrass', 'Avantgarde', 'Gothic Rock', 'Progressive Rock',
'Psychedelic Rock', 'Symphonic Rock', 'Slow Rock', 'Big Band',
'Chorus', 'Easy Listening', 'Acoustic', 'Humour', 'Speech', 'Chanson',
'Opera', 'Chamber Music', 'Sonata', 'Symphony', 'Booty Bass', 'Primus',
'Porn Groove', 'Satire', 'Slow Jam', 'Club', 'Tango', 'Samba',
'Folklore', 'Ballad', 'Power Ballad', 'Rhythmic Soul', 'Freestyle',
'Duet', 'Punk Rock', 'Drum Solo', 'Acapella', 'Euro-House', 'Dance Hall',
'Goa', 'Drum & Bass', 'Club-House', 'Hardcore', 'Terror', 'Indie',
'BritPop', 'Negerpunk', 'Polsk Punk', 'Beat', 'Christian Gangsta Rap',
'Heavy Metal', 'Black Metal', 'Crossover', 'Contemporary Christian',
'Christian Rock', 'Merengue', 'Salsa', 'Trash Metal', 'Anime', 'Jpop',
'Synthpop' {continua...}
);
procedure Register;
begin
RegisterComponents('MauryTecnologies', [TMauryMp3Tag]);
end;
{ TMauryMp3Tag }
procedure TMauryMp3Tag.Set_Filename(const Value: TFileName);
begin
FFilename := Value;
GetMp3tag(FFilename);
end;
procedure TMauryMp3Tag.GetMp3tag(mp3File :string);
var
Tag : TTag;
fmp3: TFileStream;
begin
fmp3:=TFileStream.Create(mp3File, fmOpenRead);
try
fmp3.position:=fmp3.size-128;
fmp3.Read(Tag,SizeOf(Tag));
finally
fmp3.free;
end;
if Tag.Tag <> 'TAG' then begin
Titolo :='Informazioni Corrote o Non esistenti';
Artista :='Informazioni Corrote o Non esistenti';
Album :='Informazioni Corrote o Non esistenti';
Anno :='Informazioni Corrote o Non esistenti';
Genere :='Informazioni Corrote o Non esistenti';
Commento :='Informazioni Corrote o Non esistenti';
end else begin
Titolo :=Tag.Titolo;
Artista :=Tag.Artista;
Album :=Tag.Album;
Anno :=Tag.Anno;
if Tag.Genere in [0..Max] then
Genere := Generi[Tag.Genere]
else
Genere :='Other';
GenereB := Tag.Genere;
Commento :=Tag.Commento;
end;
end;
procedure TMauryMp3Tag.SetTag(mp3File,STitolo,SArtista,SAlbum,SAnno,SCommento : string;SGenere : byte);
var
fMP3: file of Byte;
PrecTag,Nuovo : TTag;
i : integer;
begin
try
AssignFile(fMP3, mp3File);
Reset(fMP3);
try
Seek(fMP3, FileSize(fMP3) - 128);
BlockRead(fMP3, PrecTag, SizeOf(PrecTag));
if PrecTag.Tag = 'TAG' then
Seek(fMP3, FileSize(fMP3) - 128)
else
Seek(fMP3, FileSize(fMP3));
Nuovo.Tag := PrecTag.Tag;
if STitolo = '' then
STitolo := 'No Title';
for i := 0 to 29 do
Nuovo.Titolo[i] := STitolo[i+1];
if SArtista = '' then
SArtista := 'No Artist';
for i := 0 to 29 do
Nuovo.Artista[i] := SArtista[i+1];
if SAlbum = '' then
SAlbum := 'No Album';
for i := 0 to 29 do
Nuovo.Album[i] := SAlbum[i+1];
if SAnno = '' then
SAnno := 'No Year';
for i := 0 to 3 do
Nuovo.Anno[i] := SAnno[i+1];
if SCommento = '' then
SCommento := 'No Comment';
for i := 0 to 29 do
Nuovo.Commento[i] := SCommento[i+1];
Nuovo.Genere := SGenere;
BlockWrite(fMP3, Nuovo, SizeOf(Nuovo));
finally
end;
finally
CloseFile(fMP3);
end;
end;
end.
|
|