2022-07-17 11:21:51 +00:00
|
|
|
import { apiJSON } from "./sub/utils.js";
|
2022-07-10 13:30:42 +00:00
|
|
|
import { errorUnsupported, genericError } from "./sub/errors.js";
|
2022-07-08 18:17:56 +00:00
|
|
|
|
2022-08-04 11:22:40 +00:00
|
|
|
import { testers } from "./servicesPatternTesters.js";
|
|
|
|
|
2022-07-10 13:30:42 +00:00
|
|
|
import bilibili from "./services/bilibili.js";
|
|
|
|
import reddit from "./services/reddit.js";
|
|
|
|
import twitter from "./services/twitter.js";
|
|
|
|
import youtube from "./services/youtube.js";
|
|
|
|
import vk from "./services/vk.js";
|
2022-07-28 16:03:17 +00:00
|
|
|
import tiktok from "./services/tiktok.js";
|
2022-07-30 10:58:14 +00:00
|
|
|
import douyin from "./services/douyin.js";
|
2022-08-01 17:53:44 +00:00
|
|
|
import tumblr from "./services/tumblr.js";
|
2022-07-08 18:17:56 +00:00
|
|
|
|
|
|
|
export default async function (host, patternMatch, url, ip, lang, format, quality) {
|
|
|
|
try {
|
2022-08-04 11:22:40 +00:00
|
|
|
if (!testers[host]) return apiJSON(0, { t: errorUnsupported(lang) });
|
|
|
|
if (!(testers[host](patternMatch))) throw Error();
|
|
|
|
|
|
|
|
let r;
|
2022-07-08 18:17:56 +00:00
|
|
|
switch (host) {
|
|
|
|
case "twitter":
|
2022-08-04 11:22:40 +00:00
|
|
|
r = await twitter({
|
|
|
|
id: patternMatch["id"],
|
|
|
|
lang: lang
|
|
|
|
});
|
2022-08-06 15:21:48 +00:00
|
|
|
return (!r.error) ? apiJSON(1, { u: r }) : apiJSON(0, { t: r.error });
|
2022-08-04 11:22:40 +00:00
|
|
|
|
2022-07-08 18:17:56 +00:00
|
|
|
case "vk":
|
2022-08-04 11:22:40 +00:00
|
|
|
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 });
|
|
|
|
|
2022-07-08 18:17:56 +00:00
|
|
|
case "bilibili":
|
2022-08-04 11:22:40 +00:00
|
|
|
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 });
|
|
|
|
|
2022-07-08 18:17:56 +00:00
|
|
|
case "youtube":
|
2022-08-04 11:22:40 +00:00
|
|
|
let fetchInfo = {
|
|
|
|
id: patternMatch["id"].slice(0,11),
|
|
|
|
lang: lang, quality: quality,
|
|
|
|
format: "mp4"
|
|
|
|
};
|
|
|
|
if (url.match('music.youtube.com')) {
|
|
|
|
format = "audio"
|
|
|
|
}
|
|
|
|
switch (format) {
|
|
|
|
case "webm":
|
|
|
|
fetchInfo["format"] = "webm";
|
|
|
|
break;
|
|
|
|
case "audio":
|
|
|
|
fetchInfo["format"] = "webm";
|
|
|
|
fetchInfo["isAudioOnly"] = true;
|
|
|
|
fetchInfo["quality"] = "max";
|
|
|
|
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 });
|
|
|
|
|
2022-07-08 18:17:56 +00:00
|
|
|
case "reddit":
|
2022-08-04 11:22:40 +00:00
|
|
|
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 });
|
|
|
|
|
2022-07-28 16:03:17 +00:00
|
|
|
case "tiktok":
|
2022-08-04 11:22:40 +00:00
|
|
|
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 });
|
|
|
|
|
2022-07-30 10:58:14 +00:00
|
|
|
case "douyin":
|
2022-08-04 11:22:40 +00:00
|
|
|
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 });
|
|
|
|
|
2022-08-01 17:53:44 +00:00
|
|
|
case "tumblr":
|
2022-08-04 11:22:40 +00:00
|
|
|
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 });
|
2022-07-08 18:17:56 +00:00
|
|
|
default:
|
2022-08-04 11:22:40 +00:00
|
|
|
return apiJSON(0, { t: errorUnsupported(lang) });
|
2022-07-08 18:17:56 +00:00
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
return apiJSON(0, { t: genericError(lang, host) })
|
|
|
|
}
|
2022-08-01 15:48:37 +00:00
|
|
|
}
|