Recent

Author Topic: MP3 id3 tag v2  (Read 1180 times)

P.curtis

  • Jr. Member
  • **
  • Posts: 80
MP3 id3 tag v2
« on: May 19, 2020, 07:16:39 pm »
Does anyone have a working example of how to get MP3 tags. I'm interested in duration and title.
Thanks in advance.

winni

  • Hero Member
  • *****
  • Posts: 1600
Re: MP3 id3 tag v2
« Reply #1 on: May 19, 2020, 07:35:07 pm »
Hi!

The implementation of Tags in version 2 a bunch of idiotic relations.
The only good solution I know is the tag plugin of BASS:

http://www.un4seen.com/

Tag V1 is simple.
I can search for my code if you need it.

Winni

Fred vS

  • Hero Member
  • *****
  • Posts: 1779
    • StrumPract is the musicians best friend
Re: MP3 id3 tag v2
« Reply #2 on: May 19, 2020, 07:44:17 pm »
Hello.

Code: Pascal  [Select][+][-]
  1. var
  2.   F: file;
  3.   title, album, date, comment, tag : string;
  4.   genre : integer;
  5.   BufferTag: array[1..128] of char;
  6. ...
  7.  
  8.  AssignFile(F, '/dirrectory/of/filename.mp3');
  9.    FileMode:=fmOpenRead + fmShareDenyNone;
  10.    Reset(F, 1);
  11.    Seek(F, FileSize(F) - 128);
  12.    BlockRead(F, BufferTag, SizeOf(BufferTag));
  13.    CloseFile(F);
  14.  
  15.   title := copy(BufferTag, 4, 30);
  16.   artist := copy(BufferTag, 34, 30);
  17.   album := copy(BufferTag, 64, 30);
  18.   date :=  copy(BufferTag, 94, 4);
  19.   comment := copy(BufferTag, 98, 30);
  20.   tag :=  copy(BufferTag, 1, 3);
  21.   genre := ord(BufferTag[128]);
  22.  

For duration it is more tricky, you may use like wini said Bass.
And if you want a free open source solution, maybe take a look at uos.
« Last Edit: May 19, 2020, 07:50:16 pm by Fred vS »
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs

lucamar

  • Hero Member
  • *****
  • Posts: 2962
Re: MP3 id3 tag v2
« Reply #3 on: May 19, 2020, 07:50:07 pm »
See this thread:
Recomendations for audio metadata
Lots of recommendations there, though I ended up using a TProcess and parsing the output of soxi :)

@Fred vS: That will only work to retrieve v1 tags ... and doesn't even check whether they are there! Also it makes too many assumptions about the length and presence of each tag.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Fred vS

  • Hero Member
  • *****
  • Posts: 1779
    • StrumPract is the musicians best friend
Re: MP3 id3 tag v2
« Reply #4 on: May 19, 2020, 07:56:44 pm »
@lucanar, afaik, a mp3 that has v2 (tag info at begin of file) has also v1 (tag info at end).

But yes, it can give the title but not the length.

uos does what you need.
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs

Awkward

  • Jr. Member
  • **
  • Posts: 65
Re: MP3 id3 tag v2
« Reply #5 on: May 19, 2020, 07:59:54 pm »
if you don't want to search and use old (since D3 i think) Audo Tools Library (if i remember right), you can check https://www.3delite.hu/Object Pascal Developer Resources/id3v2library.html
Tags Library there have sources and examples dor other tag formats too

lucamar

  • Hero Member
  • *****
  • Posts: 2962
Re: MP3 id3 tag v2
« Reply #6 on: May 19, 2020, 08:01:48 pm »
@lucanar, afaik, a mp3 that has v2 (tag info at begin of file) has also v1 (tag info at end).

Not necessarily, though it's rather common. The real question, though, is that the OP asked specifically for ID3v2 tags. :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Fred vS

  • Hero Member
  • *****
  • Posts: 1779
    • StrumPract is the musicians best friend
Re: MP3 id3 tag v2
« Reply #7 on: May 19, 2020, 08:07:17 pm »
> The real question, though, is that the OP asked specifically for ID3v2 tags

Ok, ok, so it is exactly the same principle, but from begin of file.

If you read the first 3 bytes, and they are equal to "ID3", then skip to the 7th byte, then read the header size.
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs

winni

  • Hero Member
  • *****
  • Posts: 1600
Re: MP3 id3 tag v2
« Reply #8 on: May 19, 2020, 08:17:34 pm »
Hi!

That's the way to get ID3 Tags version 1:

Code: Pascal  [Select][+][-]
  1. TYPE
  2. TAG_ID3 = record   // 128 byte
  3.     id: Array[0..2] of AnsiChar;
  4.     title: Array[0..29] of AnsiChar;
  5.     artist: Array[0..29] of AnsiChar;
  6.     album: Array[0..29] of AnsiChar;
  7.     year: Array[0..3] of AnsiChar;
  8.     comment: Array[0..29] of AnsiChar;
  9.     genre: Byte;
  10.   end;
  11.  
  12. Function ReadTagID3Tag (fname : String; var Tag: TAG_ID3 ): boolean;
  13. var phyle : File of byte;
  14.       ok : Boolean;
  15.  
  16. begin
  17. fillchar(tag,sizeof(tag),0);
  18. ok := false;
  19. if LazFileUtils.FileExistsUTF8(fname) then
  20.   begin
  21.   {$I-}
  22.   assign (phyle,Fname);
  23.   reset (phyle);
  24.   seek(phyle, fileSize(phyle) -sizeof(tag));
  25.   blockread(phyle,tag,sizeof(tag));
  26.   closeFile (phyle);
  27.   {$I+}
  28.   ok := tag.id = 'TAG';
  29. result := ok;
  30. end;
  31.  
  32. ......
  33. var artist : string;
  34. .....
  35. artist := string(tag.artist);
  36. ..
  37.  
  38.  

The genre byte points to al list of around 200 genre strings.
I add an include file with the genres in the attachment.


Winni

PS.: Had to rename it to '*txt' to get through the "sophisticated" forum filter
« Last Edit: May 19, 2020, 08:22:23 pm by winni »

Fred vS

  • Hero Member
  • *****
  • Posts: 1779
    • StrumPract is the musicians best friend
Re: MP3 id3 tag v2
« Reply #9 on: May 19, 2020, 08:24:34 pm »
> That's the way

Yes (and I dont see any difference with my previous code).
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs

Fred vS

  • Hero Member
  • *****
  • Posts: 1779
    • StrumPract is the musicians best friend
Re: MP3 id3 tag v2
« Reply #10 on: May 19, 2020, 08:39:00 pm »
Quote
If you read the first 3 bytes, and they are equal to "ID3", then skip to the 7th byte, then read the header size.

About the length stored in id3 tag v2, it is a "synchsafe integer".

I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs

Fred vS

  • Hero Member
  • *****
  • Posts: 1779
    • StrumPract is the musicians best friend
Re: MP3 id3 tag v2
« Reply #11 on: May 19, 2020, 08:46:26 pm »
The best ot the best id3 tag v2 Pascal Open Source reader-editor is, imho, the one from OvOPlayer:

https://github.com/varianus/ovoplayer

With his own, independent, tag v2 decoder in Pascal source (WOW):
https://github.com/varianus/ovoplayer/tree/master/src/ovotag

It can deal also with picture.
« Last Edit: May 20, 2020, 12:38:23 am by Fred vS »
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs

P.curtis

  • Jr. Member
  • **
  • Posts: 80
Re: MP3 id3 tag v2
« Reply #12 on: May 19, 2020, 10:26:32 pm »
Fred VS, OVOPlayer looks good.......

Fred vS

  • Hero Member
  • *****
  • Posts: 1779
    • StrumPract is the musicians best friend
Re: MP3 id3 tag v2
« Reply #13 on: May 20, 2020, 12:37:33 am »
Quote
Fred VS, OVOPlayer looks good.......

Imho, OvOPlayer is the tenor of what has be done with Lazarus for audio players.

Like LazPaint who is the reference in graphic application.
 
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs

 

TinyPortal © 2005-2018