-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
334 lines (295 loc) · 14.9 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JSON Payload Viewer</title>
</head>
<body>
<center><label margin: auto><H2>SMARTBOX STREAM INSPECTOR</label></body><H2></label></H2></center>
<hr>
<!-- UI : epg-api input & fetch-button. -->
<label for="urlInput">SMARTBOX-EPG-URL:</label>
<input type="text" size="65" value="https://streaming0.watchdishtv.com/serviceepginterface/serviceepgdata" id="urlInput" placeholder="Enter URL">
<button onclick="fetchAndDisplay()">Fetch and Display</button>
<br>
<label for="channelDetailsLabel">CHANNELS_INFO:</label>
<br>
<textarea id="channelDetailsTextArea" rows="5" cols="150" readonly></textarea>
<hr>
<label for="urlInput">CONTINIOUS-CHECK:</label>
<button onclick="startCS()">START</button>
<button onclick="stopCS()">STOP</button>
<button onclick="downloadLogs()">DOWNLOAD</button>
<hr>
<!-- UI : OUTPUT (COLLECTIVE) -->
<textarea id="outputTextArea" rows="25" cols="150" readonly></textarea>
<hr>
<!-- UI : OUTPUT (NOW) -->
<label>OUTPUT (NOW)</label>
<br>
<table border="1" id="resultTable">
<thead>
<tr>
<th>Service Name</th> <!--0-->
<th>service Key</th> <!--1-->
<th>MPD-AST</th> <!--2-->
<th>MPD-PubT</th> <!--3-->
<th>relative PubT(PubT - AST)</th> <!--4-->
<th>first-segment Segment-T</th> <!--5-->
<th>Segment-Late-By-seconds: (first-segment Segment-T) - (rel PubT)</th> <!--6-->
</tr>
</thead>
<tbody id="resultBody">
<!-- Table body will be populated dynamically -->
</tbody>
</table>
<hr>
<!-- SCRIPT -->
<script>
//Global config param
//
intervalForContiniousRunsMS = (1 * 30 * 1000) //MM*SS*MILS
continiousRunCounter = 0
//Methdods to write into channel-details text box.
//
//
function clearChannelDetailsLog() {
const channelDetailsTextArea = document.getElementById('channelDetailsTextArea');
channelDetailsTextArea.value = ""
}
function logChannelDetails(detailStringIn) {
const channelDetailsTextArea = document.getElementById('channelDetailsTextArea');
channelDetailsTextArea.value += detailStringIn + "\n"
}
//Methods to write into collective-output text box.
//
//
function clearOutputTextArea() {
const outputTextArea = document.getElementById('outputTextArea');
outputTextArea.value = ""
clearLocalLog()
}
function LogOutput(outputStringIn) {
const outputTextArea = document.getElementById('outputTextArea');
outputTextArea.value += outputStringIn
writeToLocal(outputStringIn)
}
//Methods : fetchAndDisplay() : that fetches an parses the EPG data.
//
//
function fetchAndDisplay() {
// Get the input URL
const urlInput = document.getElementById('urlInput');
const url = urlInput.value;
clearChannelDetailsLog()
// Make a fetch request to the URL
fetch(url)
.then(response => response.json())
.then(data => {
// Get the services array from the JSON payload
const services = data.services;
// Get the table body element
const resultBody = document.getElementById('resultBody');
// Clear existing rows in the table
resultBody.innerHTML = "";
// Iterate through each service and add a row to the table
services.forEach(service => {
const row = resultBody.insertRow();
// Display serviceName in the first column
const serviceNameCell = row.insertCell(0);
serviceNameCell.textContent = service.serviceName;
// Display serviceName in the first column
const serviceKeyCell = row.insertCell(1);
serviceKeyCell.textContent = service.serviceKey;
// Display the serviceUrlDASH in the textarea
logChannelDetails(service.serviceName + " /" + service.serviceKey + " /" + service.serviceUrlDASH)
// Fetch the DASH-MPD payload from serviceUrlDASH
const dashUrl = service.serviceUrlDASH;
fetch(dashUrl)
.then(response => {
if (!response.ok) {
throw new Error(`Error fetching DASH-MPD from ${dashUrl}: ${response.status} ${response.statusText}`);
}
return response.text(); // Use text() for XML content
})
.then(dashData => {
// Process the DASH-MPD XML data as needed
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(dashData, "text/xml");
// Example: Get availabilityStartTime attribute from the MPD element
const mpdElement = xmlDoc.querySelector('MPD');
const availabilityStartTime = mpdElement.getAttribute('availabilityStartTime');
const publishTime = mpdElement.getAttribute('publishTime');
const astDateTS = Date.parse(availabilityStartTime)
const astSeconds = astDateTS/1000
const pubTDateTS = Date.parse(publishTime)
const pubTSeconds = pubTDateTS/1000
relPubTSeconds = 0
// Display availabilityStartTime in the second column
const availabilityStartTimeCell = row.insertCell(2);
availabilityStartTimeCell.textContent = availabilityStartTime ? availabilityStartTime : "N/A";
availabilityStartTimeCell.textContent += " or "+String(astSeconds)+"s"
// Display availabilityStartTime in the second column
const publishTimeCell = row.insertCell(3);
publishTimeCell.textContent = publishTime ? publishTime : "N/A";
publishTimeCell.textContent += " or "+String(pubTSeconds)+"s"
// Display availabilityStartTime in the second column
const relativePubTimeCell = row.insertCell(4);
relPubTSeconds = (pubTSeconds - astSeconds)
relativePubTimeCell.textContent = String(relPubTSeconds)+ "s"
// Find the smallest 't' value across all segment-timelines, representations, and adaptation-sets
const earliestSegmentTime = findSmallestTValue(xmlDoc);
earliestSegmentTimeSeconds = 0
// Display smallest 't' value in the third column
const smallestTValueCell = row.insertCell(5);
if(earliestSegmentTime === Infinity) {
earliestSegmentTime = "N/A";
} else{
smallestTValueCell.textContent = earliestSegmentTime
smallestTValueCell.textContent += " or "
smallestTValueCell.textContent += Math.round((earliestSegmentTime/90000))
smallestTValueCell.textContent += "s"
earliestSegmentTimeSeconds = Math.round((earliestSegmentTime/90000))
}
const segmentLateBySeconds = row.insertCell(6);
lateBySecondsInt = earliestSegmentTimeSeconds - relPubTSeconds
//SIM-BEGIN
//if(service.serviceName == "AMC") {
// lateBySecondsInt = 4500 + lateBySecondsInt
//}
//SIM-END
segmentLateBySeconds.textContent = String(lateBySecondsInt)+ "s"
if(lateBySecondsInt > 300) {
segmentLateBySeconds.style.backgroundColor = "red"
LogOutput("ERR!-SegmentLate-"+lateBySecondsInt+"s@"+service.serviceName+",")
} else if(lateBySecondsInt > 0) {
LogOutput("WARN-SegmentLate-"+lateBySecondsInt+"s@"+service.serviceName+",")
segmentLateBySeconds.style.backgroundColor = "yellow"
}
})
.catch(error => {
console.error(`Error processing ${dashUrl}: ${error.message}`);
// Display an error message in the third column if fetching fails
const smallestTValueCell = row.insertCell(6);
smallestTValueCell.textContent = "Error fetching or processing DASH-MPD";
});
});
})
.catch(error => {
console.error(`Error fetching JSON from ${url}: ${error.message}`);
});
}
function findSmallestTValue(xmlDoc) {
console.log('findSmallestTValue() +++++ +++++ +++++ +++++ +++++ ')
let smallestTValue = Infinity;
const periods = xmlDoc.querySelectorAll('Period');
periods.forEach(period => {
console.log('PER|')
// Iterate through each representation
const adaptationSets = period.parentElement.querySelectorAll('AdaptationSet');
adaptationSets.forEach(adaptationSet => {
console.log('ADS>')
// Iterate through each adaptation-set
const representations = adaptationSet.parentElement.querySelectorAll('Representation');
representations.forEach(representation => {
console.log('REP>>')
// Iterate through each segment-timeline
const segmentTimelines = representation.querySelectorAll('SegmentTimeline');
segmentTimelines.forEach(segmentTimeline => {
console.log('SET>>')
// Iterate through each segment
const segments = segmentTimeline.querySelectorAll('S');
segments.forEach(segment => {
const TSTP = segment.getAttribute('t')
console.log('SEG>>> T='+ TSTP)
// Get the 't' attribute value
const tValue = parseInt(TSTP);
if (!isNaN(tValue) && tValue < smallestTValue) {
smallestTValue = tValue;
}
});
});
});
});
});
console.log('findSmallestTValue() ----- ----- ----- ----- ----- :'+String(smallestTValue))
return smallestTValue;
}
//Methods : Continious inspect
//
//
var continousEPGTimer = null
function startCS() {
//Deinit.
clearOutputTextArea()
stopCS()
//Start.
LogOutput("continious inspection: BEGIN."+"\n");
continousEPGTimer = setInterval(onContiniousEPGTimer, intervalForContiniousRunsMS);
onContiniousEPGTimer()
}
function stopCS() {
continiousRunCounter = 0
if(null != continousEPGTimer) {
clearInterval(continousEPGTimer)
continousEPGTimer = null
}
LogOutput("\n")
LogOutput("continious inspection: END."+"\n");
}
function downloadLogs() {
}
function onContiniousEPGTimer() {
var dateNow = new Date();
dateStr = dateNow.toLocaleString();
fetchAndDisplay();
LogOutput("\n")
LogOutput("run#"+continiousRunCounter+" : "+dateStr + " : ");
continiousRunCounter++;
}
//Data Management.
//
//
function writeToLocal(stringToWrite) {
// Retrieve existing content from local storage
let existingContent = localStorage.getItem('SBXInspectorLocalData') || '';
// Append new content
existingContent += stringToWrite;
// Save updated content to local storage
localStorage.setItem('SBXInspectorLocalData', existingContent);
}
function clearLocalLog() {
localStorage.setItem('SBXInspectorLocalData', "");
}
//Collect log.
//
//
function downloadLogs() {
let existingContent = localStorage.getItem('SBXInspectorLocalData') || '';
writeToFile(existingContent)
}
function writeToFile(content) {
// Check if there's data in local storage
if (!content) {
alert('No data in local storage. Write to local storage first.');
return;
}
// Create a Blob containing the text
const blob = new Blob([content], { type: 'text/plain' });
// Create a link element
const link = document.createElement('a');
// Set the download attribute with the file name
link.download = 'sbxStrmInspContiniousLog.txt';
// Create a URL for the Blob and set it as the href attribute of the link
link.href = window.URL.createObjectURL(blob);
// Append the link to the document
document.body.appendChild(link);
// Trigger a click event on the link to prompt the download
link.click();
// Remove the link from the document
document.body.removeChild(link);
}
</script>
</body>
</html>