-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (25 loc) · 848 Bytes
/
index.js
File metadata and controls
31 lines (25 loc) · 848 Bytes
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
'use strict';
'use strong';
const jsonic = require('jsonic');
const request = require('request');
function findInfoObject(content) {
let lastOffset = 0;
while (true) {
const scriptStart = content.indexOf('<script type="text/javascript">', lastOffset);
if (scriptStart === -1) return null;
const scriptEnd = content.indexOf('</script>', scriptStart);
const scriptContent = content.slice(scriptStart + 31, scriptEnd);
if (scriptContent.indexOf('window.DR') !== -1) {
return jsonic(scriptContent.slice(12, -1));
}
lastOffset = scriptEnd;
}
}
function videosource(href, callback) {
request(href, function (err, res, content) {
if (err) return callback(err, null);
const info = findInfoObject(content.toString());
callback(null, info.TV.ProgramCard.Urn);
});
}
module.exports = videosource;