JS剖析MP3猎取歌曲信息--ID3 Reader

ID3 Reader 是一款能够在前台或许背景(nodejs)剖析MP3曲目信息(条件是含有这些信息)的东西

官方demo 源码下载 全英文文档

用法示例

1,基础用法

//In its simplest form:
ID3.loadTags("filename.mp3", function() {
    var tags = ID3.getAllTags(filename);
    alert(tags.artist + " - " + tags.title + ", " + tags.album);
});

2,特别用法

//by specifying specific tags:
ID3.loadTags("filename.mp3", function() {
    var tags = ID3.getAllTags(filename);
    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);
    alert(tags.comment + " - " + tags.track + ", " + tags.lyrics);
},
{tags: ["comment", "track", "lyrics"]});

3,文档及API

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.
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
}

and 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
}
Currently supported frames:

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

备注:留待再更新编辑

    原文作者:zone
    原文地址: https://segmentfault.com/a/1190000006098144
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞