5.0-dev1
- rewrote and/or optimized all service modules - rewrote matching and processing modules to optimize readability and performance - added support for reddit gifs - fixed various issues with twitter error explanations - code optimizations and enhancements (such as finally getting rid of ==, prettier and more readable formatting, etc) - added branch information - all functions in currentCommit submodule run only once and cache received data - added a test script. only twitter and soundcloud are 100% covered and tested atm, will add tests (and probably fixes) for the rest of services in next commits - changed some localization strings for russian - added more clarity to rate limit message - moved services folder into processing folder
This commit is contained in:
@@ -5,23 +5,24 @@ import loc from "../../localization/manager.js";
|
||||
|
||||
import { testers } from "./servicesPatternTesters.js";
|
||||
|
||||
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";
|
||||
import tiktok from "../services/tiktok.js";
|
||||
import tumblr from "../services/tumblr.js";
|
||||
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";
|
||||
import tiktok from "./services/tiktok.js";
|
||||
import tumblr from "./services/tumblr.js";
|
||||
import matchActionDecider from "./matchActionDecider.js";
|
||||
import vimeo from "../services/vimeo.js";
|
||||
import soundcloud from "../services/soundcloud.js";
|
||||
import vimeo from "./services/vimeo.js";
|
||||
import soundcloud from "./services/soundcloud.js";
|
||||
|
||||
export default async function (host, patternMatch, url, lang, obj) {
|
||||
try {
|
||||
if (!testers[host]) return apiJSON(0, { t: errorUnsupported(lang) });
|
||||
if (!(testers[host](patternMatch))) throw Error();
|
||||
let r, isAudioOnly = !!obj.isAudioOnly;
|
||||
|
||||
if (!testers[host]) return apiJSON(0, { t: errorUnsupported(lang) });
|
||||
if (!(testers[host](patternMatch))) return apiJSON(0, { t: brokenLink(lang) });
|
||||
|
||||
let r;
|
||||
switch (host) {
|
||||
case "twitter":
|
||||
r = await twitter({
|
||||
@@ -29,14 +30,14 @@ export default async function (host, patternMatch, url, lang, obj) {
|
||||
spaceId: patternMatch["spaceId"] ? patternMatch["spaceId"] : false,
|
||||
lang: lang
|
||||
});
|
||||
if (r.isAudioOnly) obj.isAudioOnly = true
|
||||
break;
|
||||
case "vk":
|
||||
r = await vk({
|
||||
url: url,
|
||||
userId: patternMatch["userId"],
|
||||
videoId: patternMatch["videoId"],
|
||||
lang: lang, quality: obj.vQuality
|
||||
lang: lang,
|
||||
quality: obj.vQuality
|
||||
});
|
||||
break;
|
||||
case "bilibili":
|
||||
@@ -48,10 +49,11 @@ export default async function (host, patternMatch, url, lang, obj) {
|
||||
case "youtube":
|
||||
let fetchInfo = {
|
||||
id: patternMatch["id"].slice(0, 11),
|
||||
lang: lang, quality: obj.vQuality,
|
||||
lang: lang,
|
||||
quality: obj.vQuality,
|
||||
format: "webm"
|
||||
};
|
||||
if (url.match('music.youtube.com') || obj.isAudioOnly == true) obj.vFormat = "audio";
|
||||
if (url.match('music.youtube.com') || isAudioOnly === true) obj.vFormat = "audio";
|
||||
switch (obj.vFormat) {
|
||||
case "mp4":
|
||||
fetchInfo["format"] = "mp4";
|
||||
@@ -60,7 +62,7 @@ export default async function (host, patternMatch, url, lang, obj) {
|
||||
fetchInfo["format"] = "webm";
|
||||
fetchInfo["isAudioOnly"] = true;
|
||||
fetchInfo["quality"] = "max";
|
||||
obj.isAudioOnly = true;
|
||||
isAudioOnly = true;
|
||||
break;
|
||||
}
|
||||
r = await youtube(fetchInfo);
|
||||
@@ -69,7 +71,8 @@ export default async function (host, patternMatch, url, lang, obj) {
|
||||
r = await reddit({
|
||||
sub: patternMatch["sub"],
|
||||
id: patternMatch["id"],
|
||||
title: patternMatch["title"], lang: lang,
|
||||
title: patternMatch["title"],
|
||||
lang: lang,
|
||||
});
|
||||
break;
|
||||
case "douyin":
|
||||
@@ -77,28 +80,33 @@ export default async function (host, patternMatch, url, lang, obj) {
|
||||
r = await tiktok({
|
||||
host: host,
|
||||
postId: patternMatch["postId"],
|
||||
id: patternMatch["id"], lang: lang,
|
||||
noWatermark: obj.isNoTTWatermark, fullAudio: obj.isTTFullAudio,
|
||||
isAudioOnly: obj.isAudioOnly
|
||||
id: patternMatch["id"],
|
||||
lang: lang,
|
||||
noWatermark: obj.isNoTTWatermark,
|
||||
fullAudio: obj.isTTFullAudio,
|
||||
isAudioOnly: isAudioOnly
|
||||
});
|
||||
if (r.isAudioOnly) obj.isAudioOnly = true;
|
||||
break;
|
||||
case "tumblr":
|
||||
r = await tumblr({
|
||||
id: patternMatch["id"], url: url, user: patternMatch["user"] ? patternMatch["user"] : false,
|
||||
id: patternMatch["id"],
|
||||
url: url,
|
||||
user: patternMatch["user"] ? patternMatch["user"] : false,
|
||||
lang: lang
|
||||
});
|
||||
break;
|
||||
case "vimeo":
|
||||
r = await vimeo({
|
||||
id: patternMatch["id"].slice(0, 11), quality: obj.vQuality,
|
||||
id: patternMatch["id"].slice(0, 11),
|
||||
quality: obj.vQuality,
|
||||
lang: lang
|
||||
});
|
||||
break;
|
||||
case "soundcloud":
|
||||
obj.isAudioOnly = true;
|
||||
isAudioOnly = true;
|
||||
r = await soundcloud({
|
||||
author: patternMatch["author"], song: patternMatch["song"], url: url,
|
||||
author: patternMatch["author"],
|
||||
song: patternMatch["song"], url: url,
|
||||
shortLink: patternMatch["shortLink"] ? patternMatch["shortLink"] : false,
|
||||
accessKey: patternMatch["accessKey"] ? patternMatch["accessKey"] : false,
|
||||
format: obj.aFormat,
|
||||
@@ -108,10 +116,15 @@ export default async function (host, patternMatch, url, lang, obj) {
|
||||
default:
|
||||
return apiJSON(0, { t: errorUnsupported(lang) });
|
||||
}
|
||||
return !r.error ? matchActionDecider(r, host, obj.ip, obj.aFormat, obj.isAudioOnly, lang, obj.isAudioMuted) : apiJSON(0, {
|
||||
t: Array.isArray(r.error) ? loc(lang, r.error[0], r.error[1]) : loc(lang, r.error)
|
||||
});
|
||||
|
||||
if (r.isAudioOnly) isAudioOnly = true;
|
||||
let isAudioMuted = isAudioOnly ? false : obj.isAudioMuted;
|
||||
|
||||
if (r.error) return apiJSON(0, { t: Array.isArray(r.error) ? loc(lang, r.error[0], r.error[1]) : loc(lang, r.error) });
|
||||
|
||||
return matchActionDecider(r, host, obj.ip, obj.aFormat, isAudioOnly, lang, isAudioMuted);
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
return apiJSON(0, { t: genericError(lang, host) })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user