parent
d70754238e
commit
6e1eddad82
6 changed files with 38 additions and 9 deletions
|
@ -56,9 +56,7 @@ export default async function(host, patternMatch, url, lang, obj) {
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "bilibili":
|
case "bilibili":
|
||||||
r = await bilibili({
|
r = await bilibili(patternMatch);
|
||||||
id: patternMatch.id.slice(0, 12)
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
case "youtube":
|
case "youtube":
|
||||||
let fetchInfo = {
|
let fetchInfo = {
|
||||||
|
|
|
@ -1,8 +1,23 @@
|
||||||
import { genericUserAgent, maxVideoDuration } from "../../config.js";
|
import { genericUserAgent, maxVideoDuration } from "../../config.js";
|
||||||
|
|
||||||
// TO-DO: quality picking, bilibili.tv support, and higher quality downloads (currently requires an account)
|
// TO-DO: quality picking, bilibili.tv support, and higher quality downloads (currently requires an account)
|
||||||
export default async function(obj) {
|
export default async function({ id, shortLink }) {
|
||||||
let html = await fetch(`https://bilibili.com/video/${obj.id}`, {
|
if (shortLink) {
|
||||||
|
id = await fetch(`https://b23.tv/${shortLink}`, { redirect: 'manual' })
|
||||||
|
.then(r => r.status > 300 && r.status < 400 && r.headers.get('location'))
|
||||||
|
.then(url => {
|
||||||
|
const path = new URL(url).pathname;
|
||||||
|
if (path.startsWith('/video/'))
|
||||||
|
return path.split('/')[2];
|
||||||
|
})
|
||||||
|
.catch(() => {})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return { error: 'ErrorCouldntFetch' };
|
||||||
|
}
|
||||||
|
|
||||||
|
let html = await fetch(`https://bilibili.com/video/${id}`, {
|
||||||
headers: { "user-agent": genericUserAgent }
|
headers: { "user-agent": genericUserAgent }
|
||||||
}).then((r) => { return r.text() }).catch(() => { return false });
|
}).then((r) => { return r.text() }).catch(() => { return false });
|
||||||
if (!html) return { error: 'ErrorCouldntFetch' };
|
if (!html) return { error: 'ErrorCouldntFetch' };
|
||||||
|
@ -21,7 +36,7 @@ export default async function(obj) {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
urls: [video[0]["baseUrl"], audio[0]["baseUrl"]],
|
urls: [video[0]["baseUrl"], audio[0]["baseUrl"]],
|
||||||
audioFilename: `bilibili_${obj.id}_audio`,
|
audioFilename: `bilibili_${id}_audio`,
|
||||||
filename: `bilibili_${obj.id}_${video[0]["width"]}x${video[0]["height"]}.mp4`
|
filename: `bilibili_${id}_${video[0]["width"]}x${video[0]["height"]}.mp4`
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"config": {
|
"config": {
|
||||||
"bilibili": {
|
"bilibili": {
|
||||||
"alias": "bilibili.com videos",
|
"alias": "bilibili.com videos",
|
||||||
"patterns": ["video/:id"],
|
"patterns": ["video/:id", "_shortLink/:shortLink"],
|
||||||
"enabled": true
|
"enabled": true
|
||||||
},
|
},
|
||||||
"reddit": {
|
"reddit": {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
export const testers = {
|
export const testers = {
|
||||||
"bilibili": (patternMatch) =>
|
"bilibili": (patternMatch) =>
|
||||||
patternMatch.id?.length <= 12,
|
patternMatch.id?.length <= 12 || patternMatch.shortLink?.length <= 16,
|
||||||
|
|
||||||
"instagram": (patternMatch) =>
|
"instagram": (patternMatch) =>
|
||||||
patternMatch.postId?.length <= 12
|
patternMatch.postId?.length <= 12
|
||||||
|
|
|
@ -16,6 +16,7 @@ export function aliasURL(url) {
|
||||||
url.search = `?v=${encodeURIComponent(parts[2])}`
|
url.search = `?v=${encodeURIComponent(parts[2])}`
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "youtu":
|
case "youtu":
|
||||||
if (url.hostname === 'youtu.be' && parts.length >= 2) {
|
if (url.hostname === 'youtu.be' && parts.length >= 2) {
|
||||||
/* youtu.be urls can be weird, e.g. https://youtu.be/<id>//asdasd// still works
|
/* youtu.be urls can be weird, e.g. https://youtu.be/<id>//asdasd// still works
|
||||||
|
@ -25,6 +26,7 @@ export function aliasURL(url) {
|
||||||
}`)
|
}`)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "pin":
|
case "pin":
|
||||||
if (url.hostname === 'pin.it' && parts.length === 2) {
|
if (url.hostname === 'pin.it' && parts.length === 2) {
|
||||||
url = new URL(`https://pinterest.com/url_shortener/${
|
url = new URL(`https://pinterest.com/url_shortener/${
|
||||||
|
@ -46,6 +48,12 @@ export function aliasURL(url) {
|
||||||
url = new URL(`https://twitch.tv/_/clip/${parts[1]}`);
|
url = new URL(`https://twitch.tv/_/clip/${parts[1]}`);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "b23":
|
||||||
|
if (url.hostname === 'b23.tv' && parts.length === 2) {
|
||||||
|
url = new URL(`https://bilibili.com/_shortLink/${parts[1]}`)
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return url
|
return url
|
||||||
|
|
|
@ -746,6 +746,14 @@
|
||||||
"code": 200,
|
"code": 200,
|
||||||
"status": "stream"
|
"status": "stream"
|
||||||
}
|
}
|
||||||
|
}, {
|
||||||
|
"name": "b23.tv shortlink",
|
||||||
|
"url": "https://b23.tv/lbMyOI9",
|
||||||
|
"params": {},
|
||||||
|
"expected": {
|
||||||
|
"code": 200,
|
||||||
|
"status": "stream"
|
||||||
|
}
|
||||||
}],
|
}],
|
||||||
"tumblr": [{
|
"tumblr": [{
|
||||||
"name": "at.tumblr link",
|
"name": "at.tumblr link",
|
||||||
|
|
Loading…
Reference in a new issue