This repository has been archived by the owner on Oct 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdl_streams.tum.js
66 lines (58 loc) · 2.22 KB
/
dl_streams.tum.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
const API_ENDPOINT = 'https://streams.tum.de/Mediasite/PlayerService/PlayerService.svc/json/GetPlayerOptions';
const firstWhere = (array, predicate) => {
for (let element of array) {
if (predicate(element) === true) return element;
}
}
export function script_tum(currentTabUrl, callback) {
const cookieWithName = (cookies, name) => firstWhere(cookies, cookie => cookie.name === name);
chrome.cookies.getAll({domain: 'streams.tum.de'}, cookies => {
let mediasiteAuth = cookieWithName(cookies, 'MediasiteAuth');
let aspNet_SessionId = cookieWithName(cookies, 'ASP.NET_SessionId');
const body = {
'getPlayerOptionsRequest': {
'ResourceId': currentTabUrl.pathname.split('/')[3],
'QueryString': currentTabUrl.search,
'UseScreenReader': false,
'UrlReferrer': ''
}
};
fetch(API_ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
"Cookies": `${aspNet_SessionId.name}=${aspNet_SessionId.value}; ${mediasiteAuth.name}=${mediasiteAuth.value}`
},
body: JSON.stringify(body)
})
.then(response => response.json())
.then(json => {
const videoUrls = json['d']['Presentation']['Streams'].flatMap(stream => {
if (Array.isArray(stream['VideoUrls']) && stream['VideoUrls'].length > 0) {
return firstWhere(stream['VideoUrls'], ({Location}) => Location.includes('.mp4')).Location;
} else {
return [];
}
});
const slideData = [];
for (const stream of json['d']['Presentation']['Streams']) {
if (stream['HasSlideContent']) {
const slides_base_url = stream['SlideBaseUrl'];
for (const slide of stream['Slides']) {
const id = slide['Number'].toString().padStart(4, '0');
slideData.push({
index: id,
timestamp: slide['Time'],
url: `${slides_base_url}slide_${id}_1920_1080.jpg`
});
}
}
}
callback({
title: null, // provided by the main extension script
urls: videoUrls,
slides: slideData
});
}).catch(err => console.log(err));
});
}