@infinito/id3
Version:
ID3 Tag Reader/Writer
143 lines (142 loc) • 3.42 kB
JavaScript
import genID3 from '../gen.js'
export default class id3Tag {
constructor(path) {
if(typeof path!="string") {
if(typeof path!="object") {
throw new TypeError('Invalid path provided to id3Tag');
} else {
var data = path;
path = data.path;
if(typeof path=="undefined") {
throw new Error('Invalid path provided to id3Tag');
}
}
}
Object.defineProperties(this,{
album: {
get: function () { return this._album; },
set: function (val) { this._album = val; },
},
album_artist: {
get: function () { return this._album_artist; },
set: function (val) { this._album_artist = val; },
},
artist: {
get: function () { return this._artist; },
set: function (val) { this._artist = val; },
},
composer: {
get: function () { return this._composer; },
set: function (val) { this._composer = val; },
},
fields: {
value:{
TALB:"album",
TPE2:"album_artist",
TCOM:"composer",
TCON:"genre",
TPE1:"artist",
TLEN:"length",
TPOS:"set",
TPUB:"publisher",
TIT2:"title",
TRCK:"track",
TYER:"year"
}
},
flag: {
value:0
},
genre: {
get: function () { return this._genre; },
set: function (val) { this._genre = val; },
},
length: {
get: function () { return this._length; },
set: function (val) { this._length = Number(val); }
},
path: {
value:path
},
publisher: {
get: function () { return this._publisher; },
set: function (val) { this._publisher = val; },
},
set: {
get: function () {
if(typeof this._num_sets=="undefined") {
return this._set;
} else {
return this._set+"/"+this._num_sets;
}
},
set: function (val) {
var regex = /[0-9]+(\/[0-9]+)?$/;
if(val.match(regex)!==null) {
var temp = val.split("/");
if(temp.length==2) {
if(Number(temp[0])<=Number(temp[1])) {
this._set = Number(temp[0]);
this._num_sets = Number(temp[1]);
}
} else if(!(isNaN(val))) {
this._set = Number(val);
}
} else if(val=="") {
this._set = 0;
}
}
},
subVer: {
value:0
},
title: {
get: function () { return this._title; },
set: function (val) { this._title = val; },
},
track_num: {
get: function () { return this._track; },
},
track: {
get: function () {
if(typeof this._num_tracks=="undefined") {
return this._track;
} else {
return this._track+"/"+this._num_tracks;
}
},
set: function (val) {
var regex = /[0-9]+(\/[0-9]+)?$/;
if(String(val).match(regex)!==null) {
var temp = val.split("/");
if(temp.length==2) {
if(Number(temp[0])<=Number(temp[1])) {
this._track = Number(temp[0]);
this._num_tracks = Number(temp[1]);
}
} else if(!(isNaN(val))) {
this._track = Number(val);
}
}
}
},
ver: {
value:3
},
year: {
get: function () { return this._year; },
set: function (val) { this._year = (isNaN(val))?0:Number(val); }
}
});
if(typeof data!="undefined") {
for(var i in data) {
if(i!="path") {
this[i] = data[i];
}
}
}
}
export() {
return genID3(this);
}
}