-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocal_page.js
More file actions
94 lines (83 loc) · 2.69 KB
/
local_page.js
File metadata and controls
94 lines (83 loc) · 2.69 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
86
87
88
89
90
91
92
93
94
window.VideoTogetherDownload = 'disabled'
function GetDownloadStatusStr(status) {
switch (status) {
case 0:
return "{$DownloadStatusLabel0$}"
case 1:
return "{$DownloadStatusLabel1$}"
case 2:
return "{$DownloadStatusLabel2$}"
default:
return "{$DownloadStatusLabelError$}"
}
}
function extractM3u8IdFromKey(key) {
try {
const arr = key.split('-m3u8Id-')[0].split('-end-')[0]
return arr[arr.length - 1]
} catch {
return undefined
}
}
function hide(e) {
if (e) e.style.display = 'none';
}
function show(e) {
if (e) e.style.display = null;
}
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/local_page_sw.js');
setTimeout(async () => {
reg = await navigator.serviceWorker.ready
reg.update()
}, 1);
}
function updateM3U8KeyPaths(m3u8Content, m3u8Url, m3u8Id, urlTrans) {
// Use a regular expression to find all #EXT-X-KEY, #EXT-X-MAP lines with URI="<some_url>"
const updatedContent = m3u8Content.replace(
/(#EXT-X-.*:[^\n]*URI=)"(.*?)"/g,
function (match, prefix, uri) {
// Skip data: URIs, as they don't need to be modified.
if (uri.startsWith('data:')) {
return match;
}
// Add the /rootfolder/ prefix to the URI
const m3u8IdHead = `-m3u8Id-${m3u8Id}-end-`
try {
uri = (new URL(uri, m3u8Url)).href
} catch { }
let newURI = new URL('/fetch-indexeddb-future/' + m3u8IdHead + uri, window.location).href
if (urlTrans) {
newURI = urlTrans(newURI);
}
// Replace the URI in the original line
return `${prefix}"${newURI}"`;
}
);
return updatedContent;
}
function transferToSwM3u8(m3u8Content, m3u8Url, m3u8Id, urlTrans) {
const lines = m3u8Content.split('\n');
const modifiedLines = lines.map(line => {
line = line.trim()
if (line.startsWith('#')) {
return line;
} else {
if (line == "") {
return line;
}
try {
line = (new URL(line, m3u8Url)).href
} catch { }
const m3u8IdHead = `-m3u8Id-${m3u8Id}-end-`
line = new URL("/fetch-indexeddb-videos/" + m3u8IdHead + line, window.location).href
if (urlTrans) {
line = urlTrans(line);
}
return line
}
});
// Join the modified lines back into a single string
const modifiedText = modifiedLines.join('\n');
return updateM3U8KeyPaths(modifiedText, m3u8Url, m3u8Id, urlTrans);
}