Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read MP3 file tags

I want to have a program that reads metadata from an MP3 file. My program should also able to edit these metadata. What can I do?

I got to search out for some open source code. But they have code; but not simplified idea for my job they are going to do.

When I read further I found the metadata is stored in the MP3 file itself. But I am yet not able to make a full idea of my baby program.

Any help will be appreciated; with a program or very idea (like an algorithm). :)

like image 462
vijay.shad Avatar asked Oct 29 '09 18:10

vijay.shad


People also ask

How do I read MP3 tags?

If you want to view and edit ID3 audio or MP3 tags in VLC Media Player, then it has been really made simple. The quickest way to view/edit it is by using the CTRL + I shortcut key on your PC or by navigating to Tools > Media Information.

What are tags on MP3 files?

An ID3 tag is a type of metadata container used to store information into a media file (traditionally an MP3 audio file). The ID3 tags could include a title, an album title, the artist (author), genre, cover art, the year recorded and other details that are useful for the listener of your show.


2 Answers

The last 128 bytes of a mp3 file contains meta data about the mp3 file., You can write a program to read the last 128 bytes...

UPDATE:

ID3v1 Implementation

The Information is stored in the last 128 bytes of an MP3. The Tag has got the following fields, and the offsets given here, are from 0-127.

 Field      Length    Offsets  Tag        3           0-2  Songname   30          3-32  Artist     30         33-62  Album      30         63-92  Year       4          93-96  Comment    30         97-126  Genre      1           127 

WARINING- This is just an ugly way of getting metadata and it might not actually be there because the world has moved to id3v2. id3v1 is actually obsolete. Id3v2 is more complex than this, so ideally you should use existing libraries to read id3v2 data from mp3s . Just putting this out there.

like image 90
Jaskirat Avatar answered Sep 20 '22 02:09

Jaskirat


You can use apache tika Java API for meta-data parsing from MP3 such as title, album, genre, duraion, composer, artist and etc.. required jars are tika-parsers-1.4, tika-core-1.4.

Sample Program:

package com.parse.mp3; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream;  import org.apache.tika.exception.TikaException; import org.apache.tika.metadata.Metadata; import org.apache.tika.parser.ParseContext; import org.apache.tika.parser.Parser; import org.apache.tika.parser.mp3.Mp3Parser; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler;  public class AudioParser {      /**      * @param args      */     public static void main(String[] args) {         String fileLocation = "G:/asas/album/song.mp3";          try {          InputStream input = new FileInputStream(new File(fileLocation));         ContentHandler handler = new DefaultHandler();         Metadata metadata = new Metadata();         Parser parser = new Mp3Parser();         ParseContext parseCtx = new ParseContext();         parser.parse(input, handler, metadata, parseCtx);         input.close();          // List all metadata         String[] metadataNames = metadata.names();          for(String name : metadataNames){         System.out.println(name + ": " + metadata.get(name));         }          // Retrieve the necessary info from metadata         // Names - title, xmpDM:artist etc. - mentioned below may differ based         System.out.println("----------------------------------------------");         System.out.println("Title: " + metadata.get("title"));         System.out.println("Artists: " + metadata.get("xmpDM:artist"));         System.out.println("Composer : "+metadata.get("xmpDM:composer"));         System.out.println("Genre : "+metadata.get("xmpDM:genre"));         System.out.println("Album : "+metadata.get("xmpDM:album"));          } catch (FileNotFoundException e) {         e.printStackTrace();         } catch (IOException e) {         e.printStackTrace();         } catch (SAXException e) {         e.printStackTrace();         } catch (TikaException e) {         e.printStackTrace();         }         }     } 
like image 31
MADHAIYAN M Avatar answered Sep 20 '22 02:09

MADHAIYAN M