Skip to content

Commit 7707808

Browse files
develon2015root
authored andcommitted
feat: 添加m3u8链接解析支持
1 parent 3a5a219 commit 7707808

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ function main() {
6767
let y2b = url.match(/^https?:\/\/(?:youtu.be\/|(?:www|m).youtube.com\/(?:watch|shorts)(?:\/|\?v=))([\w-]{11})$/);
6868
let bilibili = url.match(/^https?:\/\/(?:www\.|m\.)?bilibili\.com\/video\/([\w\d]{11,14})\/?(?:\?p=(\d+))?$/);
6969
let xcom = url.match(/^https?:\/\/(?:www)?x\.com\/[^\/]+\/status\/(\d+)(?:\/video\/(\d+))?$/);
70+
let m3u8 = url.match(/^https?:\/\/[\w\d\_\/\.\-]+\/(.+)\.m3u8$/);
7071
let website;
7172
switch (true) {
7273
case y2b != null:
@@ -78,6 +79,8 @@ function main() {
7879
case xcom != null:
7980
website = 'xcom';
8081
break;
82+
case m3u8 != null:
83+
website = url;
8184
}
8285
if (!!! website) {
8386
console.log('reject');
@@ -94,7 +97,7 @@ function main() {
9497
// console.log(JSON.stringify(msg, null, 1));
9598
res.send(msg);
9699
});
97-
thread.postMessage({ op: 'parse', website, url, videoID: (y2b || bilibili || xcom)[1], p: (bilibili || xcom)?.[2] });
100+
thread.postMessage({ op: 'parse', website, url, videoID: (y2b || bilibili || xcom || m3u8)[1], p: (bilibili || xcom)?.[2] });
98101
});
99102

100103
let queue = [];

static/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
window.sub_type = 'native'; // 字幕类型
8787
$(() => {
8888
let query = new URL(document.location.href).searchParams.get('url');
89-
query = decodeURIComponent(query.replace('y2b', 'youtube').replace('y2', 'youtu')); // 还原y2b视频地址
89+
query = query && decodeURIComponent(query.replace('y2b', 'youtube').replace('y2', 'youtu')); // 还原y2b视频地址
9090
url.value = query;
9191
query && document.querySelector('form').submit();
9292
})
@@ -127,10 +127,10 @@
127127

128128
/** 代理封面图片 */
129129
function getProxyImg(src) {
130-
if (src.startsWith('https://i.ytimg.com/') || src.match(/^https?:\/\/i\d\.hdslb\.com\//)) {
130+
if (src?.startsWith('https://i.ytimg.com/') || src?.match(/^https?:\/\/i\d\.hdslb\.com\//)) {
131131
return '/pxy?url=' + src;
132132
}
133-
return src;
133+
return src ?? '';
134134
}
135135

136136
// AJAX完成, 填充表单

utils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ function getWebsiteUrl(website, id, p) {
1212
if (p)
1313
return `https://x.com/i/status/${id}/video/${p ? p : 1}`;
1414
return `https://x.com/i/status/${id}`;
15+
default:
16+
return website;
1517
}
1618
}
1719

0 commit comments

Comments
 (0)