Get MP3 ID3 (V2) tags using id3v2

It's hard for me to understand the V2 ID3 tag format. I just want to get the 'Genre' ID3 tag of an MP3 file, but id3v2 returns more information than I need, and I don’t understand what this data represents.

For example, I use the following bash code:

id3v2 -l "$FILE" | grep -i "content type" 

Which returns something in the lines:

TCON (Content type): Jazz (8)

Actually, I just want to know if it’s safe for me to think that it will always be a format, and is it safe for me to do the following?

 id3v2 -l "$FILE" | grep -i "content type" | sed "s/^.*: //" | sed "s/ (.*$//" 

(which will lead to jazz.)

I am trying to find the best way to get the ID3 tag 'Genre'. Thanks so much for any suggestions.

+4
source share
1 answer

I think it is safe to assume that the string will be prefixed with TCON, so I would rather look for it (it will also be safe).

 id3v2 -l "$FILE" | sed -n '/^TCON/s/^.*: //p' | sed 's/ (.*//' 

(no need to run grep)


From / usr / share / doc / id3lib-3.8.3 / doc / id3v2.3.0.txt

TCON

The "content type" that was previously saved as a single byte is only a numeric value, now a numeric string. You can use one or more types like ID3v1.1, or since the list of categories will be impossible to maintain with accurate and updated categories, define your own.

Links to ID3v1 genres can enter "(", and then the number from the list of genres (Appendix A.) as the first byte and end with the symbol ")". This is optional followed by refinement, for example. "(21)" or "(4) Eurodisc." Several links can be made in the same frame, for example. "(51) (39)". If the refinement should start with the letter "(" the character should replace ("(for example," ((I can define any genre) "or" (55) ((I think ...). Content types are defined in ID3v2 and implemented in the same way , as well as the number types of the number notation, for example. "(RX)".

  RX Remix CR Cover 
+3
source

Source: https://habr.com/ru/post/1343481/


All Articles