4.5
This commit is contained in:
@@ -1,16 +1,12 @@
|
||||
import got from "got";
|
||||
import loc from "../../localization/manager.js";
|
||||
import { genericUserAgent, maxVideoDuration } from "../config.js";
|
||||
|
||||
export default async function(obj) {
|
||||
try {
|
||||
let html = await got.get(`https://bilibili.com/video/${obj.id}`, {
|
||||
headers: { "user-agent": genericUserAgent }
|
||||
});
|
||||
html.on('error', (err) => {
|
||||
return { error: loc(obj.lang, 'ErrorCantConnectToServiceAPI', 'bilibili') };
|
||||
});
|
||||
html = html.body;
|
||||
let html = await fetch(`https://bilibili.com/video/${obj.id}`, {
|
||||
headers: {"user-agent": genericUserAgent}
|
||||
}).then(async (r) => {return await r.text()}).catch(() => {return false});
|
||||
if (!html) return { error: 'ErrorCouldntFetch' };
|
||||
|
||||
if (html.includes('<script>window.__playinfo__=') && html.includes('"video_codecid"')) {
|
||||
let streamData = JSON.parse(html.split('<script>window.__playinfo__=')[1].split('</script>')[0]);
|
||||
if (streamData.data.timelength <= maxVideoDuration) {
|
||||
@@ -22,12 +18,12 @@ export default async function(obj) {
|
||||
}).sort((a, b) => Number(b.bandwidth) - Number(a.bandwidth));
|
||||
return { urls: [video[0]["baseUrl"], audio[0]["baseUrl"]], time: streamData.data.timelength, audioFilename: `bilibili_${obj.id}_audio`, filename: `bilibili_${obj.id}_${video[0]["width"]}x${video[0]["height"]}.mp4` };
|
||||
} else {
|
||||
return { error: loc(obj.lang, 'ErrorLengthLimit', maxVideoDuration / 60000) };
|
||||
return { error: ['ErrorLengthLimit', maxVideoDuration / 60000] };
|
||||
}
|
||||
} else {
|
||||
return { error: loc(obj.lang, 'ErrorEmptyDownload') };
|
||||
return { error: 'ErrorEmptyDownload' };
|
||||
}
|
||||
} catch (e) {
|
||||
return { error: loc(obj.lang, 'ErrorBadFetch') };
|
||||
return { error: 'ErrorBadFetch' };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user