forked from MymsMan/vbox_webif
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecordings.html
651 lines (616 loc) · 21.9 KB
/
recordings.html
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<!-- The jQuery library is a prerequisite for all jqSuite products -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<!-- This is the Javascript file of jqGrid -->
<script type="text/ecmascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqgrid/5.5.4/js/jquery.jqGrid.min.js"></script>
<!-- This is the localization file of the grid controlling messages, labels, etc. -->
<script type="text/ecmascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqgrid/5.5.4/js/i18n/grid.locale-en.min.js"></script>
<!-- A link to a jQuery UI ThemeRoller theme, more than 22 built-in and many more custom -->
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<!-- The link to the CSS that the grid needs -->
<link rel="stylesheet" type="text/css" media="screen" href="https://cdnjs.cloudflare.com/ajax/libs/jqgrid/5.5.4/css/ui.jqgrid.min.css" />
<!-- Add icon library -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<title>Vbox recordings</title>
<style>
/* .ui-jqdialog-content .form-view-data { */
#v_programme-desc, #v_programme-title {
white-space: normal;
}
</style>
</head>
<body>
<div id=loadRecordings hidden><i class="fa fa-refresh fa-spin" style="font-size:16px;color:green"></i> Loading Recordings</div>
<div id=loadChannels hidden><i class="fa fa-refresh fa-spin" style="font-size:16px;color:green"></i> Loading Channels</div>
<div id=loadEPG hidden><i class="fa fa-refresh fa-spin" style="font-size:16px;color:green"></i> Loading EPG</div>
<table id="recordingsGrid"></table>
<div id="recordingsMsg" hidden></div>
<div id="recordingsGridPager"></div>
<button id="recordingsExport" hidden>Print</button>
<br><br>
<table id="seriesGrid"></table>
<div id="seriesMsg" hidden></div>
<div id="seriesGridPager"></div>
<button id="seriesExport" hidden>Print</button>
<script type="text/javascript">
$(document).ready(function() {
$("#recordingsExport").hide();
$("#seriesExport").hide();
// Set grid defaults
jQuery.extend(jQuery.jgrid.defaults, {
altRows: true,
responsive: true,
autowidth: true,
sortable: true,
colMenu: true,
cmTemplate: {
colmenu: true,
editable: false,
editrules:{edithidden:true},
viewable: true,
searchoptions: {
clearSearch: false,
searchOperMenu: false,
sopt: ['cn', 'eq', 'ne', 'lt', 'le', 'gt', 'ge', 'bw', 'bn', 'in', 'ni', 'ew', 'en', 'nc']
}
}
});
$("#loadRecordings").show();
// Load the recordings list
$.ajax({
url: "../cgi-bin/HttpControl/HttpControlApp?OPTION=1&Method=GetRecordsList&Externals=YES",
success: function(recordList) {
$("#loadRecordings").hide();
if (checkVboxResponse(recordList,'#loadRecordings',"Load Recordings")) {
initRecordingsTable(recordList);
}
},
error: function(xhr) {
$("#loadRecordings").html(alertIcon+" Error loading recordings: "+ xhr.status + " - " + xhr.statusText );
initRecordingsTable(testRecList);
}
});
//end of doc ready function
});
function initRecordingsTable(recordList) {
// Create unique RowId, use negative for external recordings
var extix = 0;
var rec, recid, recids, i
var records = recordList.getElementsByTagName("record");
for (i = 0; i < records.length; i++) {
rec = records[i];
recids = rec.getElementsByTagName("record-id")
if (recids.length == 1) {
recid = rec.getElementsByTagName("record-id")[0].childNodes[0].nodeValue;
} else {
recid = --extix;
}
// append RowId elemnent to record
rowid = recordList.createElement("rowid");
rowix = recordList.createTextNode(recid);
rec.appendChild(rowid).appendChild(rowix);
//
}
// Recordings Grid
$("#recordingsGrid").jqGrid({
//url: '../cgi-bin/HttpControl/HttpControlApp?OPTION=1&Method=GetRecordsList',
datatype: "xmlstring",
datastr: recordList,
colModel: [{
label: 'Id',
name: 'record-id',
width: 65,
key: false,
sorttype: "number",
formatter: 'integer',
formatoptions: {
thousandsSeparator: "",
defaultValue: ""
},
align: 'right',
xmlmap: 'record-id'
},
{
label: 'RowId',
name: 'rowid',
width: 65,
key: true,
hidden: true,
sorttype: "number",
formatter: 'integer',
formatoptions: {
thousandsSeparator: "",
defaultValue: ""
},
align: 'right',
xmlmap: 'rowid'
},
{
label: 'Channel',
name: 'channel',
width: 90,
xmlmap: 'channel-name'
},
{
label: 'Title',
name: 'programme-title',
width: 180,
xmlmap: 'programme-title'
},
{
label: 'Start',
name: 'start',
width: 110,
formatter: fmtDate,
xmlmap: '[start]'
},
{
label: 'Stop',
name: 'stop',
width: 110,
formatter: fmtDate,
xmlmap: '[stop]'
},
{
label: 'Description',
name: 'programme-desc',
width: 180,
xmlmap: 'programme-desc'
},
{
label: 'State',
name: 'state',
width: 100,
stype: 'select',
searchoptions:
{value: {'':'',
recorded: 'Recorded',
recording: 'Recording',
scheduled: 'Scheduled',
External: 'External',
Error: 'Error'
}},
xmlmap: 'state'
},
{
label: 'Error desc',
name: 'error-description',
hidden: true,
width: 100,
xmlmap: 'error-description'
},
{
label: 'Series Id',
name: 'series-id',
width: 65,
sorttype: "number",
formatter: 'integer',
formatoptions: {
thousandsSeparator: "",
defaultValue: ""
},
align: 'right',
xmlmap: 'series-id'
},
{
label: 'Size',
name: 'filesize',
width: 85,
sorttype: "number",
formatter: fmtSize,
formatoptions: {
defaultValue: ""
},
align: 'right',
xmlmap: 'fileSize'
},
{
label: 'URL',
name: 'url',
hidden: true,
width: 100,
xmlmap: 'url'
},
{
label: 'File',
name: 'LocalTarget',
hidden: true,
width: 100,
xmlmap: 'LocalTarget'
},
{
label: "Actions",
name: "actions",
colmenu: false,
width: 60,
search:false,
formatter: fmtRecActions,
}
],
xmlReader: {
root: "record-list",
row: "record",
repeatitems: false
// id: "record-id"
},
height: 'auto',
loadonce: true,
rowNum: 50,
rowList: [50, 100, 150, 200, 250, 300],
pager: '#recordingsGridPager',
sortname: 'record-id',
viewrecords: true,
sortorder: "desc",
caption: "Recordings"
})
.jqGrid('sortGrid','start', true, 'desc')
.jqGrid('filterToolbar',{searchOperators: true})
.navGrid('#recordingsGridPager', {
edit: false,
add: false,
del: false
});
$("#recordingsExport").on("click", function() {
$("#recordingsGrid").jqGrid("exportToHtml", {
includeLabels: true,
includeGroupHeader: true,
includeFooter: true,
autoPrint: false
});
});
// Series Grid
$("#seriesGrid").jqGrid({
//url: '../cgi-bin/HttpControl/HttpControlApp?OPTION=1&Method=GetRecordsList',
datatype: "xmlstring",
datastr: recordList,
colModel: [{
label: 'Id',
name: 'series-id',
width: 65,
key: true,
sorttype: "number",
formatter: 'integer',
formatoptions: {
thousandsSeparator: "",
defaultValue: ""
},
align: 'right',
xmlmap: function(obj) {
return $(obj).attr('series-id');
}
},
{
label: 'Channel',
name: 'channel',
width: 90,
xmlmap: '[channel]'
},
{
label: 'Next/Last',
name: 'current-start',
width: 110,
formatter: fmtDate,
xmlmap: 'current-start'
},
{
label: 'Days',
name: 'days-in-week',
width: 80,
xmlmap: 'days-in-week'
},
{
label: 'Start',
name: 'start',
width: 60,
formatter: fmtTime,
xmlmap: 'start'
},
{
label: 'Stop',
name: 'stop',
width: 60,
formatter: fmtTime,
xmlmap: 'stop'
},
{
label: 'Series CRID',
name: 'crid',
width: 100,
xmlmap: 'crid'
},
{
label: 'Title',
name: 'programme-title',
width: 180,
xmlmap: 'programme-title'
},
{
label: 'Description',
name: 'programme-desc',
width: 180,
xmlmap: 'programme-desc'
},
{
label: 'Record ID',
name: 'record-id',
width: 65,
sorttype: "number",
formatter: 'integer',
formatoptions: {
thousandsSeparator: "",
defaultValue: ""
},
align: 'right',
xmlmap: 'schedule-record-id'
},
{
label: 'Lang',
name: 'lang',
hidden: true,
viewable: true,
width: 55,
xmlmap: 'lang'
},
{
label: "Actions",
name: "actions",
width: 60,
search:false,
colmenu: false,
formatter: fmtSerActions,
}
],
xmlReader: {
root: "record-list",
row: "record-series",
repeatitems: false
},
height: 'auto',
loadonce: true,
rowNum: 50,
rowList: [50, 100, 150, 200, 250, 300],
pager: '#seriesGridPager',
sortname: 'current-start',
viewrecords: true,
sortorder: "desc",
caption: "Series recording schedule"
})
.jqGrid('sortGrid', 'current-start', true, 'desc')
.jqGrid('filterToolbar',{searchOperators: true})
.navGrid('#seriesGridPager', {
edit: false,
add: false,
del: false
});
$("#seriesExport").on("click", function() {
$("#seriesGrid").jqGrid("exportToHtml", {
includeLabels: true,
includeGroupHeader: true,
includeFooter: true,
autoPrint: false
});
});
// end Init recordings list
}
/* checkVboxResponse
check XML returned by vbox for non zero error ErrCode
if found show in alert div and return false,
return true if no error reported */
function checkVboxResponse(vboxdat, divlabel, ident = "") {
if (vboxdat.getElementsByTagName("ErrorCode").length==0) {return true}
var ErrCode = vboxdat.getElementsByTagName("ErrorCode")[0].childNodes[0].nodeValue;
if (ErrCode==0) {return true}
var ErrDesc = vboxdat.getElementsByTagName("ErrorDescription")[0].childNodes[0].nodeValue;
$(divlabel).html(alertIcon+" "+ident+" Vbox response: "+ ErrCode + " - " + ErrDesc ).show();
alert(ident+" Vbox response: "+ ErrCode + " - " + ErrDesc );
return false;
}
/**
* Format bytes as human-readable text.
*
* @param bytes Number of bytes.
* @param si True to use metric (SI) units, aka powers of 1000. False to use
* binary (IEC), aka powers of 1024.
* @param dp Number of decimal places to display.
*
* @return Formatted string.
*
* From:
* https://stackoverflow.com/questions/10420352/converting-file-size-in-bytes-to-human-readable-string/10420404
*/
function humanFileSize(bytes, si = false, dp = 1) {
const thresh = si ? 1000 : 1024;
if (Math.abs(bytes) < thresh) {
return bytes + ' B';
}
const units = si ?
['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] :
['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
let u = -1;
const r = 10 ** dp;
do {
bytes /= thresh;
++u;
} while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1);
return bytes.toFixed(dp) + ' ' + units[u];
}
function fmtDate(cellvalue, options, rowObject) {
//console.log("fmtDate " + cellvalue);
if (typeof cellvalue == 'undefined') {
return ""
}
if (cellvalue.length < 12) {
return ""
}
var Yr = cellvalue.substr(0, 4);
var Mon = cellvalue.substr(4, 2);
var Day = cellvalue.substr(6, 2);
var Hr = cellvalue.substr(8, 2);
var Min = cellvalue.substr(10, 2);
var Sec = cellvalue.substr(12, 2);
var d = new Date(Yr, Mon - 1, Day, Hr, Min, Sec)
var text = d.toLocaleString({
dateStyle: 'short',
timeStyle: 'short'
});
//console.log("fmtDate " + cellvalue +" "+text+" "+Yr+" "+Mon+" "+Day);
return text;
}
function fmtTime(cellvalue, options, rowObject) {
//console.log("fmtDate " + cellvalue);
if (typeof cellvalue == 'undefined') {
return ""
}
if (cellvalue.length < 12) {
return ""
}
var Yr = cellvalue.substr(0, 4);
var Mon = cellvalue.substr(4, 2);
var Day = cellvalue.substr(6, 2);
var Hr = cellvalue.substr(8, 2);
var Min = cellvalue.substr(10, 2);
var Sec = cellvalue.substr(12, 2);
var d = new Date(Yr, Mon - 1, Day, Hr, Min, Sec)
var text = d.toLocaleTimeString({
dateStyle: 'short',
timeStyle: 'short'
});
//console.log("fmtDate " + cellvalue +" "+text+" "+Yr+" "+Mon+" "+Day);
return text;
}
function fmtSize(cellvalue, options, rowObject) {
//console.log("fmtSize " + cellvalue);
if (isNaN(cellvalue)) {
return "";
}
var text = humanFileSize(cellvalue);
//console.log(cellvalue + " = " + text)
return text;
}
function fmtButton(grid,id,funcName,title,icon,opts = {}){
var text = '<div title="##title##" style="float:left;" class="ui-pg-div" id="##funcName##_##id##" onclick=\'##funcName##(\"##grid##\",##id##,##opts##);\' onmouseover="jQuery(this).addClass(\'ui-state-hover\');" onmouseout="jQuery(this).removeClass(\'ui-state-hover\');"><span class="##icon##"></span></div>';
text=text.replace(/##title##/g,title);
text=text.replace(/##id##/g,id);
text=text.replace(/##funcName##/g,funcName);
text=text.replace(/##icon##/g,icon);
text=text.replace(/##opts##/g,JSON.stringify(opts));
text=text.replace(/##grid##/g,grid);
//console.log("fmtButton = " + text)
return text;
}
function fmtRecActions(cellvalue, options, rowObject) {
//console.log("fmtSize " + cellvalue);
var text = "";
var rowid=$(rowObject).attr('rowid');
text += fmtButton("#recordingsGrid",rowid,'viewRow','View row details','fa fa-eye',{});
var opts ={};
var state=$(rowObject).attr('state');
switch (state) {
case "scheduled":
if (typeof $(rowObject).attr('series-id') != 'undefined') {
// Can't delete series episode, must choose series table
return text;
}
case "recording":
opts.delurl = "OPTION=1&Method=CancelRecord&RecordID="+rowid;
break;
case "recorded":
case "Error":
opts.delurl = "OPTION=1&Method=DeleteRecord&RecordID="+rowid;
break;
case "External":
opts.delurl = "OPTION=1&Method=DeleteRecord&RecordID=External&FileName="+$(rowObject).attr('LocalTarget');
break;
default:
return text;
}
text += fmtButton("#recordingsGrid",rowid,'delRecord','Delete recording','ui-icon ui-icon-trash',opts)
//console.log(cellvalue + " = " + text)
return text;
}
function fmtSerActions(cellvalue, options, rowObject) {
//console.log("fmtSize " + cellvalue);
var id=$(rowObject).attr('series-id')
//var text = "";
var opts = {};
if (typeof $(rowObject).attr('record-id') != 'undefined') {
opts.recordid = $(rowObject).attr('record-id');
}
var text = "<div id='msg"+id+"' hidden width=50></div>";
text += fmtButton("#seriesGrid",id,'viewRow','View row details','fa fa-eye',{});
text += fmtButton("#seriesGrid",id,'delSeries','Cancel series recording','ui-icon ui-icon-trash',opts);
//console.log(cellvalue + " = " + text)
return text;
}
function viewRow(grid, rowid, opts ={}) {
$(grid).jqGrid('viewGridRow',rowid,{modal:true,closeOnEscape:true,viewhidden:true});
};
function delSeries(grid, id, opts ={}) {
console.log("delSeries " + id + ", "+grid +", "+ JSON.stringify(opts));
var ident = "Error deleting";
$.ajax({
url: "../cgi-bin/HttpControl/HttpControlApp?OPTION=1&Method=CancelRecord&RecordID="+id,
success: function(response) {
if (checkVboxResponse(response,"#msg"+id,ident)) {
// Delete grid row;
if (typeof opts.recordid != 'undefined') {
$("#recordingsGrid").jqGrid("delRowData",opts.recordid);
}
$(grid).jqGrid("delRowData",id);
}
},
error: function(xhr) {
$("#msg"+id).html(alertIcon+" "+ident+", code: "+ xhr.status + " - " + xhr.statusText ).show();
alert(ident+", code: "+ xhr.status + " - " + xhr.statusText );
}
});
//console.log("delSeries " + id + grid + opts);
}
function delRecord(grid, id, opts ={}) {
console.log("delRecord " + id + ", "+grid +", "+ JSON.stringify(opts));
var delurl = opts.delurl
var ident = "Error deleting";
$.ajax({
url: "../cgi-bin/HttpControl/HttpControlApp?"+delurl,
success: function(response) {
if (checkVboxResponse(response,"#msg"+id,ident)) {
// Delete grid row;
$(grid).jqGrid("delRowData",id);
}
},
error: function(xhr) {
$("#msg"+id).html(alertIcon+" "+ident+", code: "+ xhr.status + " - " + xhr.statusText ).show();
alert(ident+", code: "+ xhr.status + " - " + xhr.statusText );
}
});
}
var alertIcon = '<i class="ui-icon ui-icon-alert" style="font-size:24px;color:red"></i>';
var parser = new DOMParser();
var testRecList = parser.parseFromString('<?xml version="1.0" encoding="utf-8"?>\
<record-list>\
<record channel="www.Sky%20Arts.co.un" start="20201229190000 +0000" stop="20201229200000 +0000">\
<channel-name>Sky Arts</channel-name>\
<programme-title lang="eng">Queen: Live At Milton Keynes</programme-title>\
<programme-desc lang="eng">A captivating Freddie Mercury leads Queen in this 1982 concert, filmed live at the National Bowl in Milton Keynes. The band perform a rousing set featuring Flash and Under Pressure. [S]</programme-desc>\
<record-id>1323</record-id>\
<state>recorded</state>\
<url>http://127.0.0.1:55555/NetworkMedia/Queen%2D%20Live%20At%20Milton%20Keynes__Sky%20Arts__29%2D12%2D2020_19%2D00.mpg</url>\
<LocalTarget>/usr/local/bin/vboxUpnp/shared/NetworkMedia/Queen- Live At Milton Keynes__Sky Arts__29-12-2020_19-00.mpg</LocalTarget>\
<fileSize>674701544</fileSize>\
</record>\
<record-series channel="www.BBC%20ONE%20South.co.un" series-id="19081">\
<schedule-record-id>33608</schedule-record-id>\
<current-start>20210614010000 +0100</current-start>\
<days-in-week>2</days-in-week>\
<start>20210524010000 +0100</start>\
<stop>20210524022000 +0100</stop>\
<try-To-Match-Program-Title-From-Time>1</try-To-Match-Program-Title-From-Time>\
</record-series>\
</record-list>',"text/xml");
</script>
</body>
</html>