You can add, edit, remove or extract various properties of audio files stored in the form of metadata programmatically. You can easily extract metadata properties such as title, artist, and genre from audio files programmatically on the cloud. In this article, you will learn how to extract the metadata of MP3 audio files using a REST API in Java.
The following topics are discussed/covered in this article:
- MP3 Metadata Extraction REST API and Java SDK
- Extract Metadata of MP3 Files using REST API in Java
- Metadata Extraction by Matching Exact Phrase using Java
- Metadata Extraction by Regular Expression using Java
- Extract Metadata by Property Name using Java
- Extract Metadata by Property Value using Java
MP3 Metadata Extraction REST API and Java SDK
I will be using the Java SDK of GroupDocs.Metadata Cloud API for extracting metadata of MP3 audio files. It allows you to add, edit, retrieve, and remove metadata properties from over 60 types of documents, images, and multimedia file formats. You just need to define the search criteria and the API will take care of the specified metadata operations within supported file formats. The API works with the most notable metadata standards such as built-in, XMP, EXIF, IPTC, Image Resource Blocks, ID3, and custom metadata properties. It also provides .NET SDK as its document metadata manipulation family members for the Cloud API.
You can easily use GroupDocs.Metadata Cloud in your Maven-based Java applications by adding the following pom.xml configuration.
<repository>
<id>groupdocs-artifact-repository</id>
<name>GroupDocs Artifact Repository</name>
<url>http://repository.groupdocs.cloud/repo</url>
</repository>
<dependency>
<groupId>com.groupdocs</groupId>
<artifactId>groupdocs-metadata-cloud</artifactId>
<version>20.4</version>
<scope>compile</scope>
</dependency>
Please get your Client ID and Secret from the dashboard before following the mentioned steps. Once you have your ID and secret, add in the code as shown below:
Extract Metadata of MP3 Files using REST API in Java
You can easily extract metadata of MP3 audio files by following the simple steps given below:
- Upload the MP3 file to the Cloud
- Extract Metadata of MP3 Audio Files using Java
Upload the File
Firstly, upload the MP3 audio file to the Cloud using the code sample given below:
As a result, the uploaded MP3 file will be available in the files section of your dashboard on the cloud.
Extract Metadata of MP3 Audio Files using Java
You can extract all the metadata properties of MP3 audio files programmatically by following the steps given below.
- Create an instance of the MetadataApi
- Create an instance of the FileInfo
- Set the MP3 file path
- Create an instance of the ExtractOptions
- Assign the FileInfo to the ExtractOptions
- Create the ExtractRequest
- Call the MetadataApi.extract() method and get results
The following code sample shows how to extract metadata of an MP3 file using a REST API.
FileFormat: 21
Tag for property: name - FileFormat, category - Content
MimeType: audio/mpeg
Tag for property: name - FileFormat, category - Content
HeaderPosition: 2402
MpegAudioVersion: 3
Layer: 3
HasCrc: True
Bitrate: 224
Frequency: 32000
PaddingBit: 0
PrivateBit: False
Channel: 0
ModeExtensionBits: 0
Copyright: False
Original: True
Emphasis: 0
Version: ID3v1.1
Genre: 255
Album: YouTube Audio Library
Artist: Kevin MacLeod
Comment: This is sample comment.
Tag for property: name - Comment, category - Content
Title: Impact Moderato
Tag for property: name - Title, category - Content
Year: 2021
Tag for property: name - IntellectualContentCreated, category - Time
TrackNumber: 1
Version: ID3v2.3.0
TagSize: 2402
TALB: null
TPE1: null
TPE2: null
COMM: null
Tag for property: name - Comment, category - Content
TCOM: null
TPOS: null
TCON: null
TIT2: null
Tag for property: name - Title, category - Content
TRCK: null
TYER: null
Tag for property: name - IntellectualContentCreated, category - Time
title: Impact Moderato
Tag for property: name - Title, category - Content
artist: Kevin MacLeod
album: YouTube Audio Library
year: 2021
track: 1
genre: Cinematic
Tag for property: name - Type, category - Content
comment: This is sample comment.
Tag for property: name - Comment, category - Content
albumartist: MacLeod Kevin
composer: Kevin
discnumber: 101
Metadata Extraction by Matching Exact Phrase using Java
You can extract the metadata property of MP3 files matching the exact phrase by following the steps given below:
- Create an instance of MetadataApi
- Create an instance of the MatchOptions and set ExactPhrase to true
- Initialize an instance of the NameOptions
- Provide value to match and set MatchOptions
- Create an instance of the SearchCriteria and set NameOptions
- Create an instance of the FileInfo
- Set the MP3 file path
- Create an instance of the ExtractOptions
- Assign the defined SearchCriteria and FileInfo to the ExtractOptions
- Create the ExtractRequest
- Call the MetadataApi.extract() method and get results
The following code sample shows how to extract metadata by matching exact phrase using a REST API.
MimeType: audio/mpeg
Tag for property: name - FileFormat, category - Content
Metadata Extraction by Regular Expression using Java
You can define search criteria to extract the metadata of MP3 files using the regular expression by following the steps given below:
- Create an instance of the MetadataApi
- Initialize an instance of the MatchOptions and set IsRegex to true
- Create an instance of the NameOptions
- Provide regular expression and set MatchOptions
- Create an instance of the SearchCriteria and set NameOptions
- Create an instance of the FileInfo
- Set the MP3 file path
- Create an instance of the ExtractOptions
- Assign the defined SearchCriteria and FileInfo to the ExtractOptions
- Create the ExtractRequest
- Call the MetadataApi.extract() method and get results
The following code sample shows how to extract metadata searching by regular expression using a REST API.
Copyright: False
Comment: This is sample comment.
Tag for property: name - Comment, category - Content
COMM: GroupDocs.Metadata.Formats.Audio.ID3V2CommentFrame
Tag for property: name - Comment, category - Content
CommEncoding: 1
CommLanguage: eng
CommShortContentDescription:
CommText: This is sample comment.
comment: This is sample comment.
Tag for property: name - Comment, category - Content
composer: Kevin
Extract Metadata by Property Name using Java
You can define search criteria to extract the metadata of MP3 files for a specific property by following the steps given below:
- Create an instance of the MetadataApi
- Initialize an instance of the NameOptions and set the value
- Create an instance of the SearchCriteria and set NameOptions
- Create an instance of the FileInfo
- Set the MP3 file path
- Create an instance of the ExtractOptions
- Assign the defined SearchCriteria and FileInfo to the ExtractOptions
- Create the ExtractRequest
- Call the MetadataApi.extract() method and get results
The following code sample shows how to extract metadata by searching a property name using a REST API.
Artist: Kevin MacLeod
artist: Kevin MacLeod
albumartist: MacLeod Kevin
Extract Metadata by Property Value using Java
You can define search criteria to extract the metadata of MP3 files matching with the property value by following the steps given below:
- Create an instance of the MetadataApi
- Create an instance of the ValueOptions
- Provide the value to search and its type
- Create an instance of the SearchCriteria and set ValueOptions
- Create an instance of the FileInfo
- Set the MP3 file path
- Create an instance of the ExtractOptions
- Assign the defined SearchCriteria and FileInfo to the ExtractOptions
- Create the ExtractRequest
- Call the MetadataApi.extract() method and get results
The following code snippet shows how to extract metadata by searching property value using a REST API.
Title: Impact Moderato
Tag for property: name - Title, category - Content
TextValue: Impact Moderato
Try Online
Please try the following free online MP3 metadata extraction tool, which is developed using the above API. https://products.groupdocs.app/metadata/total
Conclusion
In this article, you have learned how to extract the Metadata of MP3 audio files on the cloud. You have also learned how to extract metadata by defining search criteria such as matching exact phrases, using a regular expression, and by property name or value. This article also explained how to programmatically upload an MP3 audio file on the cloud. You can learn even more about GroupDocs.Metadata extraction Cloud API using the documentation. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser. In case of any ambiguity, please feel free to contact us on the forum.