-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplaylist.js
More file actions
85 lines (74 loc) · 2.1 KB
/
Copy pathplaylist.js
File metadata and controls
85 lines (74 loc) · 2.1 KB
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
var crypto = require('crypto');
var http = require('http');
var https = require('https');
function sha1(s) {
var shasum = crypto.createHash('sha1');
shasum.update(s);
return shasum.digest('hex');
}
var sharedKey = {
Samsung : 'aeaKuegnnadnau',
Android : 'eKoShKddidoeAn',
DotCom : '',
Mobile : '',
YouView : '',
Freesat : '',
PS3 : ''
}
function generate_hmac_token(productionId, platform) {
console.log(platform);
console.log(productionId);
var prodId = productionId.split('_').join('/').split('.').join('#');
console.log(prodId);
var salt = sharedKey[platform];
if (!salt) salt = '';
console.log('salt:'+salt);
var saltedHash = salt + prodId;
return sha1(saltedHash).toUpperCase();
}
if (process.argv.length > 3) {
var platform = process.argv[2];
var prodId = process.argv[3];
var options = {};
options.headers = {};
options.headers.hmac = generate_hmac_token(prodId, platform);
options.headers['Content-Type'] = 'application/json';
prodId = prodId.split('/').join('_').split('#').join('.');
options.path = '/playlist/itvonline/'+(platform.toLowerCase())+'/'+prodId;
options.host = 'old-origin-api.itv.com';
console.log(options.headers.hmac);
https.get(options,function(res){
var data = '';
res.on('data',function(chunk){
data += chunk;
});
res.on('error',function(err){
});
res.on('end',function(){
console.log(res.statusCode+' '+res.statusMessage);
console.log(JSON.stringify(res.headers,null,2));
if (data) {
try {
var obj = JSON.parse(data);
console.log(JSON.stringify(obj,null,2));
console.log();
if (obj.Playlist) {
console.log(obj.Playlist.Video.Base+obj.Playlist.Video.MediaFiles[0].Href);
console.log();
console.log('ffmpeg -protocol_whitelist crypto -i {infile] {outfile}');
}
}
catch (ex) {
console.log(ex.message);
console.log(data);
}
}
});
});
}
else {
console.log('Usage: playlist {platform} {productionId}');
console.log('e.g. : playlist Samsung 1_9855_0061.001');
console.log('or : playlist Samsung 1/9855/0061#001');
console.log('or : playlist Android {channel}');
}