mirror of
https://github.com/imputnet/cobalt.git
synced 2026-01-01 20:41:18 +00:00
services: clean up functions and improve readability
This commit is contained in:
@@ -17,19 +17,27 @@ export default async function(o) {
|
||||
|
||||
let html = await fetch(`https://ok.ru/video/${o.id}`, {
|
||||
headers: { "user-agent": genericUserAgent }
|
||||
}).then((r) => { return r.text() }).catch(() => { return false });
|
||||
}).then(r => r.text()).catch(() => {});
|
||||
|
||||
if (!html) return { error: 'ErrorCouldntFetch' };
|
||||
if (!html.includes(`<div data-module="OKVideo" data-options="{`)) {
|
||||
return { error: 'ErrorEmptyDownload' };
|
||||
}
|
||||
|
||||
let videoData = html.split(`<div data-module="OKVideo" data-options="`)[1].split('" data-')[0].replaceAll(""", '"');
|
||||
let videoData = html.split(`<div data-module="OKVideo" data-options="`)[1]
|
||||
.split('" data-')[0]
|
||||
.replaceAll(""", '"');
|
||||
|
||||
videoData = JSON.parse(JSON.parse(videoData).flashvars.metadata);
|
||||
|
||||
if (videoData.provider !== "UPLOADED_ODKL") return { error: 'ErrorUnsupported' };
|
||||
if (videoData.movie.is_live) return { error: 'ErrorLiveVideo' };
|
||||
if (videoData.movie.duration > env.durationLimit) return { error: ['ErrorLengthLimit', env.durationLimit / 60] };
|
||||
if (videoData.provider !== "UPLOADED_ODKL")
|
||||
return { error: 'ErrorUnsupported' };
|
||||
|
||||
if (videoData.movie.is_live)
|
||||
return { error: 'ErrorLiveVideo' };
|
||||
|
||||
if (videoData.movie.duration > env.durationLimit)
|
||||
return { error: ['ErrorLengthLimit', env.durationLimit / 60] };
|
||||
|
||||
let videos = videoData.videos.filter(v => !v.disallowed);
|
||||
let bestVideo = videos.find(v => resolutions[v.name] === quality) || videos[videos.length - 1];
|
||||
|
||||
Reference in New Issue
Block a user