forked from calzoneman/sync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmedia.js
67 lines (58 loc) · 1.6 KB
/
media.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var util = require("./utilities");
function Media(id, title, seconds, type, meta) {
if (!meta) {
meta = {};
}
this.id = id;
this.setTitle(title);
this.seconds = seconds === "--:--" ? 0 : parseInt(seconds);
this.duration = util.formatTime(seconds);
this.type = type;
this.meta = meta;
this.currentTime = 0;
this.paused = false;
}
Media.prototype = {
setTitle: function (title) {
this.title = title;
if (this.title.length > 100) {
this.title = this.title.substring(0, 97) + "...";
}
},
pack: function () {
return {
id: this.id,
title: this.title,
seconds: this.seconds,
duration: this.duration,
type: this.type,
meta: {
direct: this.meta.direct,
restricted: this.meta.restricted,
codec: this.meta.codec,
bitrate: this.meta.bitrate,
scuri: this.meta.scuri,
embed: this.meta.embed,
gdrive_subtitles: this.meta.gdrive_subtitles,
html5hack: this.meta.html5hack
}
};
},
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;
}
};
module.exports = Media;