sync/src/media.js

85 lines
2.2 KiB
JavaScript
Raw Normal View History

2014-05-20 19:30:14 -07:00
var util = require("./utilities");
2014-05-20 19:30:14 -07:00
function Media(id, title, seconds, type, meta) {
if (!meta) {
meta = {};
}
2013-02-15 23:02:42 -06:00
this.id = id;
2014-06-03 21:21:00 -07:00
this.setTitle(title);
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 () {
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: {
restricted: this.meta.restricted,
codec: this.meta.codec,
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,
gdrive_subtitles: this.meta.gdrive_subtitles,
textTracks: this.meta.textTracks
2014-05-20 19:30:14 -07: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
*/
2020-01-26 20:17:55 -08:00
if (this.type !== "gd" && this.type !== "tc") {
result.meta.direct = this.meta.direct;
}
2022-01-26 20:33:59 -08:00
// Only save thumbnails for items which can be audio track only
if (['bn','cm'].includes(this.type)) {
result.meta.thumbnail = this.meta.thumbnail;
}
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-05-20 19:30:14 -07:00
module.exports = Media;