@infinito/id3
Version:
ID3 Tag Reader/Writer
217 lines (198 loc) • 5.8 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _gen = _interopRequireDefault(require("../gen.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
var id3Tag =
/*#__PURE__*/
function () {
function id3Tag(path) {
_classCallCheck(this, id3Tag);
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 get() {
return this._album;
},
set: function set(val) {
this._album = val;
}
},
album_artist: {
get: function get() {
return this._album_artist;
},
set: function set(val) {
this._album_artist = val;
}
},
artist: {
get: function get() {
return this._artist;
},
set: function set(val) {
this._artist = val;
}
},
composer: {
get: function get() {
return this._composer;
},
set: function set(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 get() {
return this._genre;
},
set: function set(val) {
this._genre = val;
}
},
length: {
get: function get() {
return this._length;
},
set: function set(val) {
this._length = Number(val);
}
},
path: {
value: path
},
publisher: {
get: function get() {
return this._publisher;
},
set: function set(val) {
this._publisher = val;
}
},
set: {
get: function get() {
if (typeof this._num_sets == "undefined") {
return this._set;
} else {
return this._set + "/" + this._num_sets;
}
},
set: function set(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 get() {
return this._title;
},
set: function set(val) {
this._title = val;
}
},
track_num: {
get: function get() {
return this._track;
}
},
track: {
get: function get() {
if (typeof this._num_tracks == "undefined") {
return this._track;
} else {
return this._track + "/" + this._num_tracks;
}
},
set: function set(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 get() {
return this._year;
},
set: function set(val) {
this._year = isNaN(val) ? 0 : Number(val);
}
}
});
if (typeof data != "undefined") {
for (var i in data) {
if (i != "path") {
this[i] = data[i];
}
}
}
}
_createClass(id3Tag, [{
key: "export",
value: function _export() {
return (0, _gen.default)(this);
}
}]);
return id3Tag;
}();
exports.default = id3Tag;