[Java] Get tag information from music files

Introduction

The tag information (song name, album name, artist name, etc.) of the song file can be easily edited from various media players. Especially in iTunes, it is very convenient to use Gracenote to automatically acquire tag information at the same time as importing from a CD. However, in some cases, the acquired tag information may be __ not your favorite __. To give an example

etc... It is troublesome to edit these songs one by one, so I always wanted to be able to manipulate the tag information from the system. (Although you will also need CDDB that meets the above requirements ...) This time, regarding the processing to get the tag information from the manipulating the tag information from the system, the result of verifying the library called JAudioTaggerwith the combination of theJava language and SpringBoot` is left as a memorandum.

Edit pom.xml

Add the following dependencies to dependencies in pom.xml

<dependency>
  <groupId>org</groupId>
  <artifactId>jaudiotagger</artifactId>
  <version>2.0.3</version>
</dependency>

Reading tag information

First, check the tag information of the appropriate song imported into iTunes tag_ss.png

Now let's actually read the tag information from the Java code (see below for the code)

AudioFile audioFile = AudioFileIO.read(File object that reads a music file);
Tag tag = audioFile.getTag();

System.out.println(tag.getFirst(FieldKey.TITLE));
System.out.println(tag.getFirst(FieldKey.ARTIST));
System.out.println(tag.getFirst(FieldKey.ALBUM_ARTIST));
System.out.println(tag.getFirst(FieldKey.ALBUM));
System.out.println(tag.getFirst(FieldKey.YEAR));
System.out.println(tag.getFirst(FieldKey.COMPOSER));
System.out.println(tag.getFirst(FieldKey.GENRE));

The output result is as follows.

Who will ring the bell?
Keyakizaka46
Keyakizaka46
Who will ring the bell?
2020
Yuki Tsujimura
J-POP

By the way, FieldKey seems to be able to get something like the following

FieldKey Tag information that can be obtained
TITLE Song name
TITLE_SORT Song name(Read)
ARTIST artist name
ARTIST_SORT artist name(Read)
ALBUM_ARTIST Album artist
ALBUM_ARTIST_SORT Album artist(Read)
ALBUM Album name
ALBUM_SORT Album name(Read)
YEAR Album release year
COMPOSER composer
COMPOSER_SORT composer(Read)
GENRE Genre

It seems that you can get various other fields (Reference: Mapping table)

in conclusion

This time I verified getting tag information, but next I would like to verify writing tag information. Also, I would like to verify the operation of tag information in languages other than Java` when I have time. Last but not least, with subscriptions becoming mainstream these days, manipulating local music files may be nonsense (laughs).

Recommended Posts

[Java] Get tag information from music files
Get caller information from stack trace (java)
Get EXIF information in Java
Get country from IP address (Java)
Get "2-4, 7, 9" from [4, 7, 9, 2, 3]
Get history from Zabbix server in Java
Get block information with Hyperledger Iroha's Java SDK
How to get Class from Element in Java
Get unixtime (seconds) from ZonedDateTime in Scala / Java
Library "OSHI" to get system information in Java
[Java] Get multiple values from one return value
[Java] Get a random value from an array
[Java] Get KFunction from Method / Constructor in Java [Kotlin]
[Java] Get metadata from files with Apathce Tika, and get image / video width and height from metadata [Kotlin]
[Swift5] Get array (individual) information from JSON using library'SwiftyJSON'
Get location information quickly
Changes from Java 8 to Java 11
Sum from Java_1 to 100
[Java] Get miscellaneous dates
Eval Java source from Java
Access API.AI from Java
[Java] Initialize, add, get
From Java to Ruby !!
Get Android location information
Get weather forecasts from Watson Weather Company Data in simple Java
Get to the abbreviations from 5 examples of iterating Java lists
[Java] Get Charset with Apathce Tika / Initialize String from Charset [Kotlin]
Get video information from Nikorepo and throw it to Slack
How to get the longest information from Twitter as of 12/12/2016
[Kotlin] Get Java Constructor / Method from KFunction and call it
Easily get an integer from a system property in Java
Get attributes and values from an XML file in Java
CData Software Hands-on (Get Twitter data from Java console application)
Get a non-empty collection from an Optional stream in java