-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMMM-TvheadendDVR.js
118 lines (99 loc) · 2.53 KB
/
MMM-TvheadendDVR.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
Module.register("MMM-TvheadendDVR", {
defaults: {
server: null,
username: null,
password: null,
basicAuth: false,
// Update interval
updateInterval: 5 * 60 * 1000, // 5 minutes
loadDelay: 0,
templateName: "default",
// Use in templates to limit size of list
maxRecordings: 5,
// Time formats used by Moment.js
timeFormats: {
now: "[Finishes at] LT",
today: "[Today at] LT",
tomorrow: "[Tomorrow at] LT",
thisWeek: "dddd [at] LT",
nextWeekOn: "MMM DD [at] LT"
},
},
// DVR entry storage
recordings: null,
// Load stylesheets
getStyles: function () {
return ["font-awesome.css", this.file("templates/" + this.config.templateName + ".css")];
},
// Load scripts
getScripts: function () {
return ["moment.js"];
},
start: function () {
// Add template filters
this.addFilters();
// Schedule first update (after loadDelay)
setTimeout(() => {
this.getRecordings();
}, this.config.loadDelay);
},
getRecordings() {
// Send notification and config to node helper
this.sendSocketNotification("MMM-TVHEADENDDVR_GET_RECORDINGS",
{
url: this.getUrl(),
username: this.config.username,
password: this.config.password,
basicAuth: this.config.basicAuth,
}
);
// Schedule next update
setTimeout(() => {
this.getRecordings();
}, this.config.updateInterval);
},
socketNotificationReceived: function (notification, data) {
// Update display on receiving list of recordings
if (notification === "MMM-TVHEADENDDVR_RECORDINGS") {
this.recordings = data;
// Refresh module display
this.updateDom();
};
},
getUrl() {
let url = "http://" +
this.config.server +
// Use 'grid_upcoming' to exclude past/completed recordings
"/api/dvr/entry/grid_upcoming";
return url;
},
getTemplate: function () {
return `templates/${this.config.templateName}.njk`;
},
getTemplateData: function () {
return {
config: this.config,
recordings: this.recordings.slice(0, Math.min(this.recordings.length, this.config.maxRecordings))
};
},
addFilters() {
this.nunjucksEnvironment().addFilter(
"getTime",
function (time, currentlyRecording) {
if (currentlyRecording) {
return moment.unix(time)
.format(this.config.timeFormats.now);
}
else {
return moment.unix(time)
.calendar(null, {
sameDay: this.config.timeFormats.today,
nextDay: this.config.timeFormats.tomorrow,
nextWeek: this.config.timeFormats.thisWeek,
sameElse: this.config.timeFormats.nextWeekOn
});
}
}.bind(this)
);
},
});