mp3 ID3标签信息

  • 主题发起人 主题发起人 import
  • 开始时间 开始时间
I

import

Unregistered / Unconfirmed
GUEST, unregistred user!
严黎斌
unit ID3Kernel;
interface
type
Tid3v1= record
Tag: array[0..2] of char; //00..02 , ='TAG'
Title:array[0..$1d] of char; //03..20
Artist:array[0..$1d] of char; //21..3e
Album:array[0..$1d] of char; //3f..5c
Year:array[0..3] of char; //5d..60
Comment:array[0..$1c] of char; //61..7d
Track:byte; //7e
Genre:byte; //7f
end;
function ReadID3v1(strFile:string;var pid3v1:Tid3v1):integer;
function WriteID3v1(strFile:string;var pid3v1:Tid3v1):integer;
function DeleteID3v1(strFile:string):integer;
implementation
function ReadID3v1(strFile:string;var pid3v1:Tid3v1):integer;
var
f1:file of byte;
bytAll: array [0..$7f] of byte;
i: integer;
begin
result:=1;
if strFile='' then exit;
AssignFile(f1,strFile);
FileMode:=0;
Reset(f1);
if FileSize(f1)<=$80 then exit;
Seek(f1, FileSize(f1)-$80);
for i:=0 to $7f do Read(f1,bytAll);
if (bytAll[0]<>ord('T')) and (bytAll[1]<>ord('A'))
and (bytAll[2]<>ord('G')) then exit; // no 'TAG' found
Move(bytAll,pid3v1,$80);
CloseFile(f1);
result:=0;
end;
function WriteID3v1(strFile:string;var pid3v1:Tid3v1):integer;
var
f1:file of byte;
bytAll: array [0..$7f] of byte;
i: integer;
begin
result:=1;
AssignFile(f1,strFile);
FileMode:=2;
Reset(f1);
if FileSize(f1)<=$80 then exit;
Seek(f1, FileSize(f1)-$80);
for i:=0 to $2 do Read(f1,bytAll); // test if 'TAG' exists
if (bytAll[0]=ord('T')) and (bytAll[1]=ord('A'))
and (bytAll[2]=ord('G'))
then Seek(f1,FileSize(f1)-$80)
else Seek(f1,FileSize(f1));
Move(pid3v1,bytAll,$80);
for i:=0 to $7f do Write(f1,bytAll);
CloseFile(f1);
result:=0;
end;
function DeleteID3v1(strFile:string):integer;
var
f1:file of byte;
bytAll: array [0..$7f] of byte;
i: integer;
begin
Result:=1;
AssignFile(f1,strFile);
FileMode:=2;
Reset(f1);
if FileSize(f1)<=$80 then exit;
Seek(f1, FileSize(f1)-$80);
for i:=0 to $2 do Read(f1,bytAll); // test if 'TAG' exists
if (bytAll[0]=ord('T')) and (bytAll[1]=ord('A'))
and (bytAll[2]=ord('G'))
then begin
Seek(f1,FileSize(f1)-$80);
Truncate(f1)
end;
CloseFile(f1);
Result:=0;
end;
end.
***********************************************
{
Byte 1-3 = ID 'TAG'
Byte 4-33 = Titel / Title
Byte 34-63 = Artist
Byte 64-93 = Album
Byte 94-97 = Jahr / Year
Byte 98-127 = Kommentar / Comment
Byte 128 = Genre
}
 
type
TID3Tag = record
ID: string[3];
Titel: string[30];
Artist: string[30];
Album: string[30];
Year: string[4];
Comment: string[30];
Genre: Byte;
end;
const
Genres : array[0..146] 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',
'Alternative Rock','Bass','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 US','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','Rhytmic 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','Heavy Metal','Black Metal','Crossover','Contemporary C',
'Christian Rock','Merengue','Salsa','Thrash Metal','Anime','JPop','SynthPop');
 
var
Form1: TForm1;
implementation
{$R *.dfm}
function readID3Tag(FileName: string): TID3Tag;
var
FS: TFileStream;
Buffer: array [1..128] of Char;
begin
FS := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);
try
FS.Seek(-128, soFromEnd);
FS.Read(Buffer, 128);
with Result do
begin
ID := Copy(Buffer, 1, 3);
Titel := Copy(Buffer, 4, 30);
Artist := Copy(Buffer, 34, 30);
Album := Copy(Buffer, 64, 30);
Year := Copy(Buffer, 94, 4);
Comment := Copy(Buffer, 98, 30);
Genre := Ord(Buffer[128]);
end;
finally
FS.Free;
end;
end;
procedure TfrmMain.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
with readID3Tag(OpenDialog1.FileName) do
begin
LlbID.Caption := 'ID: ' + ID;
LlbTitel.Caption := 'Titel: ' + Titel;
LlbArtist.Caption := 'Artist: ' + Artist;
LlbAlbum.Caption := 'Album: ' + Album;
LlbYear.Caption := 'Year: ' + Year;
LlbComment.Caption := 'Comment: ' + Comment;
if (Genre >= 0) and (Genre <=146) then
LlbGenre.Caption := 'Genre: ' + Genres[Genre]
else
LlbGenre.Caption := 'N/A';
end;
end;
end;
 
后退
顶部