probably the biggest update in history of cobalt
This commit is contained in:
wukko
2022-08-12 19:36:19 +06:00
parent 2fae43d890
commit 54c14232d5
42 changed files with 896 additions and 385 deletions

View File

@@ -11,8 +11,9 @@ import vk from "./services/vk.js";
import tiktok from "./services/tiktok.js";
import douyin from "./services/douyin.js";
import tumblr from "./services/tumblr.js";
import matchActionDecider from "./sub/matchActionDecider.js";
export default async function (host, patternMatch, url, ip, lang, format, quality) {
export default async function (host, patternMatch, url, ip, lang, format, quality, audioFormat, isAudioOnly) {
try {
if (!testers[host]) return apiJSON(0, { t: errorUnsupported(lang) });
if (!(testers[host](patternMatch))) throw Error();
@@ -24,99 +25,69 @@ export default async function (host, patternMatch, url, ip, lang, format, qualit
id: patternMatch["id"],
lang: lang
});
return (!r.error) ? apiJSON(1, { u: r }) : apiJSON(0, { t: r.error });
break;
case "vk":
r = await vk({
userId: patternMatch["userId"],
videoId: patternMatch["videoId"],
lang: lang, quality: quality
});
return (!r.error) ? apiJSON(2, { type: "bridge", lang: lang, u: r.url, filename: r.filename,
service: host, ip: ip, salt: process.env.streamSalt }) : apiJSON(0, { t: r.error });
break;
case "bilibili":
r = await bilibili({
id: patternMatch["id"].slice(0, 12),
lang: lang
});
return (!r.error) ? apiJSON(2, {
type: "render", u: r.urls, lang: lang,
service: host, ip: ip,
filename: r.filename,
salt: process.env.streamSalt, time: r.time
}) : apiJSON(0, { t: r.error });
break;
case "youtube":
let fetchInfo = {
id: patternMatch["id"].slice(0,11),
lang: lang, quality: quality,
format: "mp4"
format: "webm"
};
if (url.match('music.youtube.com')) {
format = "audio"
}
if (url.match('music.youtube.com') || isAudioOnly == true) format = "audio";
switch (format) {
case "webm":
fetchInfo["format"] = "webm";
case "mp4":
fetchInfo["format"] = "mp4";
break;
case "audio":
fetchInfo["format"] = "webm";
fetchInfo["isAudioOnly"] = true;
fetchInfo["quality"] = "max";
isAudioOnly = true;
break;
}
r = await youtube(fetchInfo);
return (!r.error) ? apiJSON(2, {
type: r.type, u: r.urls, lang: lang, service: host, ip: ip,
filename: r.filename, salt: process.env.streamSalt,
isAudioOnly: fetchInfo["isAudioOnly"] ? fetchInfo["isAudioOnly"] : false,
time: r.time,
}) : apiJSON(0, { t: r.error });
break;
case "reddit":
r = await reddit({
sub: patternMatch["sub"],
id: patternMatch["id"],
title: patternMatch["title"], lang: lang,
});
return (!r.error) ? apiJSON(r.typeId, {
type: r.type, u: r.urls, lang: lang,
service: host, ip: ip,
filename: r.filename, salt: process.env.streamSalt
}) : apiJSON(0, { t: r.error });
break;
case "tiktok":
r = await tiktok({
postId: patternMatch["postId"],
id: patternMatch["id"], lang: lang,
});
return (!r.error) ? apiJSON(2, {
type: "bridge", u: r.urls, lang: lang,
service: host, ip: ip,
filename: r.filename, salt: process.env.streamSalt
}) : apiJSON(0, { t: r.error });
break;
case "douyin":
r = await douyin({
postId: patternMatch["postId"],
id: patternMatch["id"], lang: lang,
});
return (!r.error) ? apiJSON(2, {
type: "bridge", u: r.urls, lang: lang,
service: host, ip: ip,
filename: r.filename, salt: process.env.streamSalt
}) : apiJSON(0, { t: r.error });
break;
case "tumblr":
r = await tumblr({
id: patternMatch["id"], url: url, user: patternMatch["user"] ? patternMatch["user"] : false,
lang: lang
});
return (!r.error) ? apiJSON(1, { u: r.split('?')[0] }) : apiJSON(0, { t: r.error });
break;
default:
return apiJSON(0, { t: errorUnsupported(lang) });
}
return matchActionDecider(r, host, ip, audioFormat, isAudioOnly)
} catch (e) {
return apiJSON(0, { t: genericError(lang, host) })
}