Code Monkey home page Code Monkey logo

javascript-id3-reader's Introduction

⚠️ This project has been superseded by jsmediatags and is no longer under maintainance, the reasons:

  • Browser and node support (find it on npm).
  • Better code structure
  • Extensible
  • Unit tests

Use this guide to migrate to jsmediatags.

JavaScript ID3 Reader

This library was originally made by Jacob Seidelin using ID3v1 for demo'ing his BinaryAjax library [http://www.nihilogic.dk/labs/id3/]. It was then extended by me (António Afonso) to include the ID3v2 tag specification [http://www.id3.org/id3v2.4.0-structure], while I was working at Opera Software, in the context of the Unite Media Player application which was developed using server side JavaScript. Joshua Kifer implemented the tag reader for the QuickTime metadata information found in aac files. A new BufferedBinaryFile was created that extends BinaryFile in a way that only required data will be downloaded from the server. This makes it possible to read tag structures such as the Quicktime metadata without having to download the entire file as it was happening in previous versions of this library.

Demo: http://www.aadsm.net/libraries/id3/#demo

Technical Information

This library will only download the relevant data from the mp3 file whenever the webserver supports the HTTP Range feature, otherwise the entire file will be downloaded at the cost of degrading the performance of the library. Another caveat is on the Opera browser, since it lacks support for setting the Range header, the entire file will be downloaded. This library is not complete and there is still some features missing and/or going on:

  • Unsynchronisation support
  • CommonJS support
  • Support for other types of charsets, at the moment only latin1, UTF-8 and UTF-16 are supported, these are the ones defined in the specification. However, the usage of local charsets has been common for a long time specially in Russia, Japan and China. This support can be achieved using chardet and a proper string reader function.

How To Use It

In its simplest form:

ID3.loadTags("filename.mp3", function() {
    var tags = ID3.getAllTags("filename.mp3");
    alert(tags.artist + " - " + tags.title + ", " + tags.album);
});

by specifying specific tags:

ID3.loadTags("filename.mp3", function() {
    var tags = ID3.getAllTags("filename.mp3");
    alert(tags.COMM.data + " - " + tags.TCON.data + ", " + tags.WXXX.data);
},
{tags: ["COMM", "TCON", "WXXX"]});

or even by specifying shortcuts instead of cryptic tags:

ID3.loadTags("filename.mp3", function() {
    var tags = ID3.getAllTags("filename.mp3");
    alert(tags.comment + " - " + tags.track + ", " + tags.lyrics);
},
{tags: ["comment", "track", "lyrics"]});

handling errors:

ID3.loadTags("http://localhost/filename.mp3", function() {
    var tags = ID3.getAllTags("http://localhost/filename.mp3");
    alert(tags.comment + " - " + tags.track + ", " + tags.lyrics);
},
{
    tags: ["comment", "track", "lyrics"],
    onError: function(reason) {
        if (reason.error === "xhr") {
            console.log("There was a network error: ", reason.xhr);
        }
    }
});

Cordova / PhoneGap

Raymond Camden wrote a pretty nice blog post on this topic: http://www.raymondcamden.com/2015/04/30/working-with-mp3s-id3-and-phonegapcordova-2

File API

Reading a music file through the File API can be done by using the FileAPIReader data reader packaged with ID3:

ID3.loadTags("filename.mp3", function() {
    var tags = ID3.getAllTags("filename.mp3");
    alert(tags.comment + " - " + tags.track + ", " + tags.lyrics);
}, {
    dataReader: ID3.FileAPIReader(file)
});

file is a File object as defined by the File API.

Example

See /example for additional information. Besides open http://www.aadsm.net/libraries/id3/ for a live example.

Documentation

ID3.loadTags(url, cb, [options]) url - The URL of the mp3 file to read, this must reside on the same domain (document.domain). cb - The callback function to invoke when the tags are loaded. options - Optional parameters. options.tags - The array of tags and/or shortcuts to read from the ID3 block. Default value is: ["title", "artist", "album", "track"] options.dataReader - The function used to create the data reader out of a url. It receives (url, success: callback function that returns the data reader, fail: callback function to inform an error setting up the reader). By default it will be BufferedBinaryAjax. options.onError - The function that will be called when an error occurs . It receives one argument with an error object. The object has an error property indicating the type of error. In the case the error type is "xhr" then an aditional xhr property is available with the XHR object for inspection.

ID3.getAllTags(url) url - The URL of the mp3 file to read, this must be the same value given to ID3.loadTags(). return value - This function will return the following object structure, for IDv1:

{
    version: "1.1",
    title: string,
    artist: string,
    album: string,
    year: string,
    comment: string,
    track: string,
    genre: string
}

for ID3v2:

{
    version: "2.<major>.<revision>",
    major: integer,
    revision: integer,
    flags: {
        unsynchronisation: boolean,
        extended_header: boolean,
        experimental_indicator: boolean
    },
    size: integer,
    <frame id>*: {
        id: integer,
        size: integer,
        description: string,
        data: <frame structure>
    },
    <shortcut>*: pointer to <frame id>.data
}

for AAC:

{
    album: string,
    artist: string,
    year: integer,
    title: string,
    genre: string,
    track: integer,
    composer': string,
    encoder: string,
    copyright: string,
    picture: {
        format: string,
        data: bytes[]
    },
    grouping: string,
    keyword: string,
    lyrics: string,
    genre: string
}

How to show the cover art from the byte array:

You can do this by using a data: url.

var base64String = "";
for (var i = 0; i < image.data.length; i++) {
    base64String += String.fromCharCode(image.data[i]);
}
var dataUrl = "data:" + image.format + ";base64," + window.btoa(base64String);

Currently supported frames on ID3:

  • APIC/PIC: Attached picture
  • COMM/COM: Comments
  • PCNT/CNT: Play counter
  • T*: Text frames
  • USLT/ULT: Unsychronized lyric/text transcription

Shortcuts:

  • title: TIT2/TT2
  • artist: TPE1/TP1
  • album: TALB/TAL
  • year: TYER/TYE
  • comment: COMM/COM
  • track: TRCK/TRK
  • genre: TCON/TCO
  • picture: APIC/PIC
  • lyrics: USLT/ULT

A comprehensive list of all tags defined in the specification can be found here

Cross-Domain Requests (CORS)

When doing CORS requests the browser is not able to read all response HTTP headers unless the response explicitly allows it to. You need to add the following headers to the response:

Access-Control-Allow-Origin:
Access-Control-Allow-Headers: If-Modified-Since,Range
Access-Control-Expose-Headers: Accept-Ranges,Content-Encoding,Content-Length,Content-Range

Otherwise you could get the error TypeError: block is undefined @ id3/bufferedbinaryajax.js:215

Module Loaders

This package is packaged with browserify --standalone, so it can be used with your favorite flavor of module loaders:

  • requirejs:
require('ID3', function (ID3) {
  // you may now use ID3 methods on the ID3 object.
});
  • CommonJS:
var ID3 = require('ID3');
// do stuff with ID3
  • SES (Secure Ecma Script)
var ID3 = ses.ID3();
// ID3 is available now.
  • No module loader:
var ID3 = window.ID3
// ID3 is exposed as a global, so you can just use it directly or pull it off the window to be explicit.

Node.js

This library is also npm compatible, so it can be required. As of this writing it is not published to the npm repository, but that should be remedied soon.

You can use ID3 either via browserify or directly on the server:

var ID3 = require('id3-reader')

var fileurl = "https://example.com/path/to/music.mp3"

ID3.loadTags(fileurl, function() {
    var tags = ID3.getAllTags(fileurl);
    console.log(tags);
    // tags are now available.
}, {
    onError: function(reason) {
        if (reason.error === "xhr") {
            console.log("There was a network error: ", reason.xhr);
        }
    }
});

Authors

  • Jacob Seidelin
  • António Afonso
  • Joshua Kifer
  • Jesse Ditson

javascript-id3-reader's People

Contributors

aadsm avatar dashersw avatar janrywang avatar jesseditson avatar mrand01 avatar vyorkin avatar xps avatar yangjian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

javascript-id3-reader's Issues

not working in cordova / phonega

hello, in web browser, this plugin works perfectly, but when i compile the apk and then install on my phone, plugin only return object in console.log(ID3) => {}.

thanks!

Problem trying to read local file

Hi,

I'm trying to read a local file. I have a very simple html page that I open as a local file using Firefox 3.6.12. The page has a single button calling a "go()" javascript function that is:
go = function() {
ID3.loadTags("track.MP3", function() {
var tags = ID3.getAllTags(filename);
alert(tags.artist + " - " + tags.title + ", " + tags.album);
});
}

First, the Firefox error console complains about my mp3 file being malformed. I had to add
oHTTP.overrideMimeType('text/plain; charset=x-user-defined');
in bufferedbinaryajax.js before the send call of the HEAD request to remove the message.

But then, nothing happens after the send call of the HEAD request. The onload event doesn't seem to be raised.

I'm not sure but perhaps there is an issue with HEAD request on local files. Any idea/fix/workaround?

Thanks !

Extracting Album Art from MP3 File in AWS S3

Hello,

I have files MP3 in S3 and I'll like to extract the tags and album art from the files. I'm currently extracting successfully the tags but the picture tag is not extracted.

When I use the FileReader API when the MP3 file is on local storage it extracts it successfully. Can you please advise on how I can achieve this on S3?

TypeError: block is undefined @ id3/bufferedbinaryajax.js:215

I found this bug with one on my mp3.

i debug like this :

BEFORE :

this.getByteAt = function(iOffset) {
    var block = getBlockAtOffset(iOffset);
    if( typeof block.data == "string" ) {

AFTER :

this.getByteAt = function(iOffset) {
    var block = getBlockAtOffset(iOffset);
    if(typeof block === "undefined") return 0;
    if( typeof block.data == "string" ) {

it's not perfect but it works. it don't give me an error fatal for my website.

i hope this can help you.

(sorry for my english, i'm french).

Android filesystem / PhoneGap / Cordova

I am using code from your example and when I call function with "fullPath" which is '/Music/song name.mp3' (its on local SD card) please note the space (I hope that is not causing the error)

ID3.loadTags('/Music/song name.mp3', function() {
         _tags = ID3.getAllTags('/Music/song name.mp3');
         console.log(_tags.title + " - " + _tags.album + ", " + _tags.artist);
      }, {tags: ["title", "album", "artist"],
         onError: function(reason) {
            console.log(JSON.stringify(reason));
         }
      });

I get following error (which I do not understand), I have permissions + correct path for sure, because I can play file using org.apache.cordova.media

I also tried file://... with no luck

{
"error":"xhr",
"xhr":{"statusText":"",
       "status":0,
       "response":"",
       "responseType":"",
       "responseXML":null,
       "responseText":"",
       "upload":{"onprogress":null,
                "onloadstart":null,
                "onloadend":null,
                "onload":null,
                "onerror":null,
                "onabort":null},
        "withCredentials":false,
        "readyState":4,
        "timeout":0,
        "onreadystatechange":null,
        "ontimeout":null,
        "onprogress":null,
        "onloadstart":null,
        "onloadend":null,
        "onabort":null}
}

any hints?

Tags are empty for local file, reading from within firefox addon

Any idea why this is not working for local files within a firefox addon?

function getID3 (file) {
    var url = file.name;
    console.log(url); // console.log: addon: /home/user/audio.mp3
    ID3.loadTags(url, function () {
            var tags = ID3.getAllTags(url);
            console.log(tags); // console.log: addon: {}
            console.log(tags.artist); // console.log: addon: null
    }, {
            dataReader: new FileAPIReader(file)
    });
}

var f = new File([""], "/home/user/audio.mp3");
getID3(f);

On filesystem ..

rob@work:~$ pwd
/home/rob
rob@work:~$ ls audio.mp3 
audio.mp3

Using your test page: http://web.ist.utl.pt/antonio.afonso/www.aadsm.net/libraries/id3/, it prints the following output for the local file ..

Artist
    A Perfect Circle
Title
    Annihilation
Album
    eMOTIVe
Year
    2004
Comment
Genre
    Pop/Rock
Track
    1/12

Handle CORS errors / documentation

i do not understand how it is possible to handle CORS errors like "No 'Access-Control-Allow-Origin' header is present on the requested resource." the callback provided by ID3.loadTags is only called on success.

i assume it's somehow possible with the dataReader option but could not yet figure out how.

Can't retrieve song duration tag (TLE/TLEN)

Hi, I'm trying to retrieve the song length using the TLE/TLEN tag, but never get any data from it. I've tried both v2.2 and v2.3 of the tag name, and creating a 'length' shortcut, but no success. I'm using MP3s and I get data from the default tags (where the data is available in the file). Is there something other than adding the appropriate tag or shortcut to the options of loadTags that I have to do?

Here is how I am trying to do it:

if(j < songFiles.length)
    {
        songFilename = "audio/" + songFiles[j].name;

        ID3.loadTags(songFilename, function() {
            tags = ID3.getAllTags(songFilename);

            //alert(ID3.getTag(songFilename, "TLE"));

            var singleSongObject = {
                "song":
                {
                    "title": (tags.title) ? tags.title : '<span class="load-error">&lt;no title data&gt;</span>',
                    "album": (tags.album) ? tags.album : '<span class="load-error">&lt;no album data&gt;</span>',
                    "artist": (tags.artist) ? tags.artist : '<span class="load-error">&lt;no artist data&gt;</span>',
                    "duration": (tags.TLE) ? tags.TLE : '<span class="load-error">&lt;duration data load failed&gt;</span>'
                }
            };

            songList.push(singleSongObject);
        }, {tags: ["title", "album", "artist", "TLE"]});

        setTimeout(arguments.callee, 1000);

        j++;

        songsToLoad = songFiles.length - j;
        songsLoadingLabel = "Loading song data. Songs remaining: ";

        document.getElementById("song-list").innerHTML = '<article id="song-loading"><p>' + songsLoadingLabel + songsToLoad + "</p></article>";
    }

ID3 from streaming (Icecast/SHOUTcast)

Hi António,
Do you know if it's possible to decode the ID3 from a stream?
We plan to use the Web Audio API to decode the metadata but I don't see anything on the web talking about that.
Then I found your solution but I guess it's only for FileAPI?
Thanks in advance,
Greg

Available inside web worker?

Hi! I was trying to use this library inside a web worker, since there might be a lot of files to parse in my case. But I found a reference of document in the minimized script (here in the source code: line 144), which would cause error.
Is it currently possible to use this inside a web worker? If not, is it possible in the future? Thanks.

Support .m4a files

I'm creating a Firefox OS app, and I need to read tags from at least MP3 (common) and M4A (I use this) music formats... Using this library, I can't read those tags, what I get is 'undefined'. I've tried using the Firefox browser and Firefox OS Simulator, none works...
Is M4A supported by this library? If true, how can I read the tags. I'm using FileAPIReader.
captura de pantalla de 2014-09-28 16 34 06
captura de pantalla de 2014-09-28 16 34 14

how to use url

hey there! I've been going over what your doing and im a bit confused as to what kind of data the ID3 class is expecting.

for example, ive got a file input called "fileselect" which im manipulating through jquery:

//functions that get called second

function getDataURL(file, callback){
    reader = new FileReader();
    reader.onload = function(){
        callback(reader.result)
        };
    reader.readAsDataURL(file)
}

function fileLoadCallback(file){console.log(file)}

// heres the jquery that gets called first

jQuery("#fileselect").change(function(){
    file = this.files[0]
    getDataURL(file, fileLoadCallback)


})

and i was hoping to put the ID3 stuff into the callback for the onChange. However, im not sure what the ID3 class is expecting from a url (im testing all of this locally btw). i thought it would want the DataURL generated by readAsDataURL, however, when i give it that, nothing happens. btw the callback looks like this with ID3:

function fileLoadCallback(file){
    console.log(file)
    ID3.loadTags(file,function(){
        var tags = ID3.getAllTags(file);
        console.log(tags.artist)
    })
}

So what kind of URL is it expecting?

Comparison itunes metadata & JS ID3 reader metadata

Hi Antonio,

I'm facing a problem with some songs.
Here is what your parser returns for a song called Neurotron - On a Journey (http://web.ist.utl.pt/antonio.afonso/www.aadsm.net/libraries/id3/)

Artist: Various Artists
Title: On a Journey
Album: The Force, Vol. 2 - EP

Here is what iTunes returns:

Name: On a Journey
Artist: Neurotron
Album Artist: Various Artist
Album: The Force, Vol. 2 - EP

iTunes makes a distinction between Artist and Album Artist.

It I edit the tags manually and remove the value of Album Artist, then your parser returns Neurotron as Artist, which is expected. As a consequence, Album Artisttakes precedence over Artist.

Do you have any idea how to solve that issue?

song.picture.format returns 'undefined' – in my code and in the demo

Hey,

I'm getting lots of Javascript MIME type warnings when using the picture tag code you used in the demo, and have traced this to .picture.format returning 'undefined' instead of, say, 'image/jpeg'. My browser is correctly determining that these are images, so it's not a huge issue, but still is there a fix? I've used Kid3 to confirm that all my MP3 picture files have a suitable MIME type.

Thanks

nodejs module

Do you plan to make your library a nodejs module?

I spent a little while to figure out how to use your library (I thought it was a nodejs module :p).

Error reading image for certain MP3s

I'm using this tool in a podcast subscription extension for chrome (https://chrome.google.com/webstore/detail/podstation/bpcagekijmfcocgjlnnhpdogbplajjfn).

I don't know if the issue is in the way I'm using it or in the tool itself, but for some MP3s the image is not being read properly.

One example is: http://200.147.22.65/meialua/podcast/meialuacast_078_donkey_kong.mp3
The image looks like:
image

and should be:
image

Here is the code I'm using

    ID3.loadTags(audioPlayer.src, function() {
        var tags = ID3.getAllTags(audioPlayer.src);

        if( "picture" in tags ) {
            var image = tags.picture;
            var base64String = "";
            for (var i = 0; i < image.data.length; i++) {
                    base64String += String.fromCharCode(image.data[i]);
            }

            tags.imageDataUrl = "data:" + image.format + ";base64," + window.btoa(base64String);

            callback(tags);
        }
    }, {
        tags: ["artist", "title", "album", "year", "picture"]
    });

where audioPlayer.src is the MP3 URL.

year "undefined" for mp3s

It seems that the "year" tag is not working for MP3s, and returns "undefined." I have a series of MP3s tagged with the year in both the v1 and v2 tags, but ID3-minimized.js returns "undefined" for them all.

I took a look at the example page you have, just to make sure it is not something specific to my MP3s, and it appears this is happening on your page as well. None of the year tags are displayed when selecting the MP3s, but when you select the sole M4A (02_Viandanze.m4a), the year (2011) is displayed. I downloaded this file locally and it exhibits the same behavior.

Maybe Helpful

Hello!
Thank you for your work and for the example!
Is this for your example.html interesting:

     /* 
     * Amazon MP3 work with the normal tag.picture....
     */
      var image = tags.picture;   
     /* 
     * example for the others....
     */ 
     if (image == undefined) {
    /* 
    * Beatport MP3 have 3 pictures, 
    * Array[0] for the cover
    * Array[1] for the Waveform
    * Array[2] undefined
    */   
    try {       
        var image = tags.APIC[0].data;  
    }   catch (e) {       
        }
    }

or is it "too much" for an example?

loadFromLink() doesn't work

I followed the documentation and example: http://web.ist.utl.pt/antonio.afonso/www.aadsm.net/libraries/id3/

This is my code:

class Mfolio.Views.SongsEdit extends Marionette.ItemView
  template: JST["songs/edit"]

  events:
    "change #song_image": "loadFromFile"

  onRender: ->
    @loadFromLink()

  loadFromFile: ->
    file = $("#song_image")[0].files[0]
    url = file.urn or file.name
    @loadUrl url, FileAPIReader(file)

  loadFromLink: ->
    url = @model.get("asset").asset.url
    @loadUrl url

  loadUrl: (url, reader) ->
    ID3.loadTags url, (->
      tags = ID3.getAllTags(url)
      $("#album").val(tags.album or "")
      if "picture" of tags
        image = tags.picture
        base64String = ""
        i = 0
        console.log(image.data.length)
        while i < image.data.length
          base64String += String.fromCharCode(image.data[i])
          i++
        $("#thumbnail").prop("src", "data:" + image.format + ";base64," + window.btoa(base64String))
        $("#thumbnail")[0].style.display = "block"
      else
        $("#thumbnail")[0].style.display = "none"
    ),
    tags: [
      "album"
      "picture"
    ],
    dataReader: reader

There are almost the same functions like in index.js from previously mentioned example (view-source:http://web.ist.utl.pt/antonio.afonso/www.aadsm.net/libraries/id3/index.js). The difference is my loadFromLink() is fired on render instead on link click.

Problem is:
the loadFromFile() works perfectly, but loadFromLink() shows only broken image icon. Asset url is ok, because album tag shows up correctly, only image doesn't load.

I noticed the content of base64String of mp3 from file is different than of this one from link (even if I choose the same uploaded file to which the link leads) but I have no idea why.

Issue in IE

Thought i'd file this here for you.

Library has an issue in IE with the file " bufferedbinaryajax.js".

SCRIPT58644: Could not complete the operation due to error c00ce514.

Console reports the following code breaks it

var block = {
data: http.responseBody || http.responseText,
offset: range[0]
};

Memory Leak

Hi, i'm using your wonderful library for read a lot of ID3 metadata form a large mp3 library, i'm using chrome, all works good but i receive always memory leaks, how i can flush memory and free RAM ?
For the massive use of cpu i used a delayed calls and all is ok, but for the memory i haven't found a solution.

Thank you.
Tommaso.

please clarify your license

Some of the files in this repo are MIT licensed, some are BSD licensed, and some include a copyright but no grant of license.

Could you clarify by including a LICENSE file at the toplevel of the repo, or at least by specifying the license in each of the source files that lacks one?

Tags charset

Tags with cyrillic symbols in them encoded in windows-1251 charset aren't displaying properly. How to make the plugin work along with some charset detection library?

No picture returned

I have an mp3 file ->https://puu.sh/xk1we/e62d34886e.mp3
i try to load tags, and get it
and this is my result


{
"version": "2.3.0",
"major": 3,
"revision": 0,
"flags": {
"unsynchronisation": false,
"extended_header": false,
"experimental_indicator": false
},
"size": 23460,
"title": "AiAe",
"artist": "ゆよゆっぺ",
"album": "YUYOYU EP",
"track": "04/07",
"TALB": {
"id": "TALB",
"size": 21,
"description": "Album/Movie/Show title",
"data": "YUYOYU EP"
},
"TIT2": {
"id": "TIT2",
"size": 11,
"description": "Title/songname/content description",
"data": "AiAe"
},
"TPE1": {
"id": "TPE1",
"size": 13,
"description": "Lead performer(s)/Soloist(s)",
"data": "ゆよゆっぺ"
},
"TRCK": {
"id": "TRCK",
"size": 13,
"description": "Track number/Position in set",
"data": "04/07"
}
}

ther is no picture, can you help me
*sorry for my bad english

Ideas about a rewrite

Hey, so I was thinking of doing a rewrite.
My biggest issues were:

  • Global variables all over the place
  • Cannot be used in web workers
  • Code is not easy to read
  • IEBinary_getByteAt
  • Data is stored in memory (I think this should be handled by the user)

I would like to rewrite this using es6 modules/syntax, es6 classes and typed arrays (I don't know much about this though). The es6 classes I would use for the binaryFile, so it's easy to extend and understand.

Now, like I said, I don't know much about this whole thing, but I do want to learn. I wrote down a rough idea about how I think this library works: https://gist.github.com/icidasset/c6d972c90a2d2f0565b1 Please let me know if I'm on the right track with this thing.

Unable to read local file

The 'readFileDataFromFileSystem' function (id3.js, ligne 30) call an undefined function 'ReadFile'
And the condition to guess if a file is local or not is strange: 'mountpoint://' is not very common.... 'file://' is more obvious!

Showing cross origin error in access of another domain mp3 files tags

I am trying to fetch all tags data like album name, artist, song image etc from amazon server. Here is one URL of song that I am passing https://s3.amazonaws.com/clueradiomedia/music/%24uicideBoy%24/Either%20Hated%20Or%20Ignored%20-%20Single/Either%20Hated%20Or%20Ignored.mp3

var customurl = 'https://s3.amazonaws.com/clueradiomedia/music/%24uicideBoy%24/Either%20Hated%20Or%20Ignored%20-%20Single/Either%20Hated%20Or%20Ignored.mp3';

ID3.loadTags(customurl, function() {

    var getfile = customurl;
	var tags = ID3.getAllTags(getfile);
	
	console.log(tags);
	
	alert(tags.artist + " - " + tags.title + ", " + tags.album);

	var image = tags.picture;
	if (image) {
		var base64String = "";
		for (var i = 0; i < image.data.length; i++) {
			base64String += String.fromCharCode(image.data[i]);
		}
		var base64 = "data:" + image.format + ";base64," +
				window.btoa(base64String);
		document.getElementById('picture').setAttribute('src',base64);
	  } else {
		document.getElementById('picture').style.display = "none";
	  }
},{
    tags: ["title","artist","album","picture", "year", "comment", "track", "genre", "lyrics"],
  });

But, when I am hitting above function then its showing me this error "Access to XMLHttpRequest at 'http://s3.amazonaws.com/clueradiomedia/music/%24uicideBoy%24/Either%20Hated%20Or%20Ignored%20-%20Single/Either%20Hated%20Or%20Ignored.mp3' from origin 'http://----' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource."

I am checking the main file but its minified so I can't deduct how to pass request headers for XML request.

Can please suggest me how to pass allow origin headers here?

Thanks!

tags.picture return undefined

On of my file return undefined when i try to access its tags.picture. When i use your demo, it display the artwork

This is the object your demo output:

Object {
version: "2.3.0",
major: 3,
revision: 0,
flags: Object,
size: 84152…
}
APIC: ObjectCOMM: Objectdata: Objectdescription: "Comments"
id: "COMM"
size: 5 proto: ObjectTALB: ObjectTCON: Objectdata: "Progressive House"
description: "Content type"
id: "TCON"
size: 18 proto: ObjectTIT2: ObjectTPE1: ObjectTYER: Objectartist: "Tobu"
comment: Objectflags: Objectgenre: "Progressive House"
major: 3
picture: Objectdata: Array[81886][0… 9999][10000… 19999][20000… 29999][30000… 39999][40000… 49999][50000… 59999][60000… 69999][70000… 79999][80000… 81885] length: 81886 proto: Array[0] description: ""
format: "image/jpeg"
type: "Cover (back)"
proto: Objectrevision: 0 size: 84152 title: "Seven"
version: "2.3.0"
year: "2014"
proto: Object

This is the one mine produced:

Object {
version: "2.3.0",
major: 3,
revision: 0,
flags: Object,
size: 84152…
}
TALB: ObjectTIT2: ObjectTPE1: Objectartist: "Tobu"
flags: Objectmajor: 3 revision: 0 size: 84152 title: "Seven"
version: "2.3.0"
proto: Object

I'm developing in chrome packaged app. does it effect anything at all?

Sporadically large load time for tags

Hey there,

I've been researching into methods of getting the id3 tag for a track as I'm going to be making a web based music player. I've been toying with the idea of doing it in javascript and found your library, which, albeit with a huge load time, does work.

Here's an example that I've got functioning (at the moment it only logs the tags and how long it took to get them): http://codepen.io/zephyr/pen/e4c432ef9a35ff4df839ca7b2bd01618?editors=001 (this pen is loading the minified js file for the id3 reader from another private pen that I made to have a place to host the code temporarily)

Sometimes (on the first load) I've gotten stupidly high load times :( it's ranged from two minutes to 8 minutes which is completely not in the right ballpark for this.

As an alternative I did find that there are some functions in php that can do it, and could simply send a json response for all the tracks I had, but wanted to try with javascript (with a faster solution than what it is currently).

Would you have any ideas as to why this is so slow compared to your examples?

Kind Regards,
Tony

[Firefox] ID3.loadtags never returns for cached files

I am using this plugin on my personal website (www.luigipulcini.com) in combination with jPlayer.
The script I created reads the ID3 tags every time a new track is selected to be played.
After loadTags succeeds (callback), the div displaying the information gets populated with the tags and the audio track itself starts playing.

This works perfectly in every browser, including Firefox.

The problem comes when a user goes back to a track that has already been played back (cached). In that case, ONLY IN FIREFOX, loadTags never calls the callback function and the whole player gets stuck.

I tried several browser in several devices, including mobile devices.
This only happens in Firefox.

How to reproduce the issue in Firefox:

  1. Go to www.luigipulcini.com
  2. Let the first track be cached (white line in the circular player)
  3. Skip to the next track
  4. Skip back to the previous track: the player won't play anymore and the div displaying the information of the track gets stuck with the "loading... please wait..." warning

All the cached tracks won't play anymore, even if I reload the page, until I empty Firefox cache folder.

Here is the code I am using.

ID3.loadTags(file, function() {
    var tags = ID3.getAllTags(file);
    if (tags) {
        [... populate the <div> with the info...]
    } else {
        [...no tags warning message...]
    }
    [...playback...]
}, {tags: ["artist", "title", "album", "year", "comment", "track", "genre"]});

The reason why I am putting the playback inside the loadTags callback function is that I don't want the track to start playing back without the tags being showed.

I don't know whether I am doing something wrong, but if this is the case, it only happens in Firefox.

Page is loading forever

I tried you script to extract some ID3 data out of a mp3 file but it does not work for me.
I run my script on localhost and used your script form the documentation.
When I upload the mp3 file to your demo page it works fine.
Here is my setup of the project:

File Stucture

.
|-- index.html
|-- js
|   |-- id3-minimized.js
|   `-- script.js
`-- song.mp3

index.html

<script src="js/id3-minimized.js"></script>
<script src="js/script.js"></script>

script.js

var file = 'song.mp3';

ID3.loadTags(file, function() {
  var tags = ID3.getAllTags(file);
  console.log(tags.artist + " - " + tags.title + ", " + tags.album);
});

Screenshot form most recent version of Chrome Version 40.0.2214.91 (64-bit) on Mac OS X 10.10.1
id3-loading

Any idea? Thank you very much :)

ID3 Bitrate

How to extract the bitrate of the mp3 file ?

ID3 Reader and ASP.NET

I am having difficulty implementing your js library in an IIS/ASP.NET environment. Currently, I am doing prototyping on a local instance of IIS Express and when I try to pull the ID3 tags, I get the generic HTTP 400 'Bad Request' error. The sub code returned is 0.

I have tried referencing the source files so that I could debug further (Firefox), and found that it dies on the getHead function:oHTTP.open() call in bufferedbinaryajax.js, line 129. This is when the 400 error occurs.

Could this perhaps be a web.config error of some kind that I'm missing? Or is there a discrepancy in how the ID3 library requests are interpreted between Apache (your demo site) and IIS/ASP.NET?

I've also tried this in another project of mine that uses Ajax for webmethod and WCF service calls and had experienced the same behavior.

Library looks great. I have been looking forward to implementing this for a while, as it should let me make a playlist without any kind of manifest storing the ID3 information.

Thanks.

TagLib for nodejs

Hi Antonio,

I found out by accident TagLib as module for nodejs: https://github.com/nikhilm/node-taglib

Strangely it doesn't appear as result if you google "nodejs mp3".

With your ID3 Reader lib that matches browser and the nodejs module mentioned above I think we have everything we could need :)

IE 10

On your demo site the code seems to run correctly using the links. When I try to replicate this locally, I get an error saying that the readasbinarystring is not supported.

Weird issue with multiple file upload/ File Reader? tags is always null and all types of scoping/callback hell

I was hoping you might be able to shed some insight on whats happening here. I realize this library is very complex and javascript scoping is brutal, but i can't for the life of me figure out why this doesn't work as i expect that it should? could you perhaps help me?

var $files = [];

$( 'input[name="audio_files"]' ).on( 'change' , function(e) {
    if ( this.files && this.files.length > 0 ) {
        for( var i=0,file; file = this.files[i]; i++ ){
            var $fileObj = {};
            $fileObj.blob = file;
            ID3.loadTags( $fileObj.blob.name , function() {
                console.log( $fileObj.blob.name ); //its there as expected
                var tags = ID3.getAllTags( $fileObj.blob.name );
                console.log(tags); //its always null
                if(tags != null){
                    $fileObj.title     = tags.title;
                    $fileObj.artist    = tags.artist;
                    $fileObj.featuring = '';
                }else{
                    $fileObj.title    =  '';
                    $fileObj.artist   =  '';
                    $fileObj.featuring = '';
                }
                $files.push($fileObj);
            }($fileObj), {
                dataReader: FileAPIReader($fileObj.blob)
            });
        }
    }
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.