2014-05-20 19:30:14 -07:00
|
|
|
var util = require("./utilities");
|
2014-02-02 20:04:50 -06:00
|
|
|
|
2014-05-20 19:30:14 -07:00
|
|
|
function Media(id, title, seconds, type, meta) {
|
|
|
|
|
if (!meta) {
|
|
|
|
|
meta = {};
|
|
|
|
|
}
|
2013-04-24 14:28:20 -05:00
|
|
|
|
2013-02-15 23:02:42 -06:00
|
|
|
this.id = id;
|
2014-06-03 21:21:00 -07:00
|
|
|
this.setTitle(title);
|
2014-02-02 20:04:50 -06:00
|
|
|
|
2014-05-20 19:30:14 -07:00
|
|
|
this.seconds = seconds === "--:--" ? 0 : parseInt(seconds);
|
|
|
|
|
this.duration = util.formatTime(seconds);
|
|
|
|
|
this.type = type;
|
|
|
|
|
this.meta = meta;
|
|
|
|
|
this.currentTime = 0;
|
|
|
|
|
this.paused = false;
|
2013-02-15 23:02:42 -06:00
|
|
|
}
|
|
|
|
|
|
2014-05-20 19:30:14 -07:00
|
|
|
Media.prototype = {
|
2014-06-03 21:21:00 -07:00
|
|
|
setTitle: function (title) {
|
|
|
|
|
this.title = title;
|
|
|
|
|
if (this.title.length > 100) {
|
|
|
|
|
this.title = this.title.substring(0, 97) + "...";
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2014-05-20 19:30:14 -07:00
|
|
|
pack: function () {
|
2018-03-05 21:56:08 -08:00
|
|
|
const result = {
|
2014-05-20 19:30:14 -07:00
|
|
|
id: this.id,
|
|
|
|
|
title: this.title,
|
|
|
|
|
seconds: this.seconds,
|
|
|
|
|
duration: this.duration,
|
|
|
|
|
type: this.type,
|
|
|
|
|
meta: {
|
2014-06-01 11:43:18 -07:00
|
|
|
restricted: this.meta.restricted,
|
|
|
|
|
codec: this.meta.codec,
|
2015-01-11 12:10:09 -06:00
|
|
|
bitrate: this.meta.bitrate,
|
2015-06-18 18:46:33 -04:00
|
|
|
scuri: this.meta.scuri,
|
2015-07-25 01:19:32 -07:00
|
|
|
embed: this.meta.embed,
|
2017-08-07 21:44:55 -07:00
|
|
|
gdrive_subtitles: this.meta.gdrive_subtitles,
|
2018-08-26 22:02:36 -07:00
|
|
|
textTracks: this.meta.textTracks,
|
|
|
|
|
mixer: this.meta.mixer
|
2014-05-20 19:30:14 -07:00
|
|
|
}
|
|
|
|
|
};
|
2018-03-05 21:56:08 -08:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 2018-03-05: Remove GDrive metadata from saved playlists to save
|
|
|
|
|
* space since this is no longer used.
|
2020-01-26 20:17:55 -08:00
|
|
|
*
|
|
|
|
|
* 2020-01-26: Remove Twitch clip metadata since their API changed
|
|
|
|
|
* and no longer uses direct links
|
2018-03-05 21:56:08 -08:00
|
|
|
*/
|
2020-01-26 20:17:55 -08:00
|
|
|
if (this.type !== "gd" && this.type !== "tc") {
|
2018-03-05 21:56:08 -08:00
|
|
|
result.meta.direct = this.meta.direct;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
2014-05-20 19:30:14 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getTimeUpdate: function () {
|
|
|
|
|
return {
|
|
|
|
|
currentTime: this.currentTime,
|
|
|
|
|
paused: this.paused
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getFullUpdate: function () {
|
|
|
|
|
var packed = this.pack();
|
|
|
|
|
packed.currentTime = this.currentTime;
|
|
|
|
|
packed.paused = this.paused;
|
|
|
|
|
return packed;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
reset: function () {
|
|
|
|
|
this.currentTime = 0;
|
|
|
|
|
this.paused = false;
|
2014-02-02 20:04:50 -06:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-05-20 19:30:14 -07:00
|
|
|
module.exports = Media;
|