cobalt/src/modules/api.js
wukko a8b5555a1b added ability to download full audios from tiktok (3.3.5)
- it's now possible to download full audios from tiktok videos, you just have to turn that on in settings.
- tiktok audios are better in quality when it's possible to get exact audio used in video and not the full version of it.
- cleaned up the way user preference stuff is passed over between modules, should be way more flexible now.
- added audio ignore list to services config json instead of hardcoding it.
2022-08-23 20:43:56 +06:00

45 lines
2 KiB
JavaScript

import UrlPattern from "url-pattern";
import { services as patterns } from "./config.js";
import { cleanURL, apiJSON } from "./sub/utils.js";
import { errorUnsupported } from "./sub/errors.js";
import loc from "../localization/manager.js";
import match from "./match.js";
export async function getJSON(originalURL, lang, obj) {
try {
let url = decodeURI(originalURL);
if (!url.includes('http://')) {
let hostname = url.replace("https://", "").replace(' ', '').split('&')[0].split("/")[0].split("."),
host = hostname[hostname.length - 2],
patternMatch;
if (host == "youtu") {
host = "youtube";
url = `https://youtube.com/watch?v=${url.replace("youtu.be/", "").replace("https://", "")}`;
}
if (host == "goo" && url.substring(0, 30) == "https://soundcloud.app.goo.gl/") {
host = "soundcloud"
url = `https://soundcloud.com/${url.replace("https://soundcloud.app.goo.gl/", "").split('/')[0]}`
}
if (host == "tumblr" && !url.includes("blog/view")) {
if (url.slice(-1) == '/') url = url.slice(0, -1);
url = url.replace(url.split('/')[5], '');
}
if (host && host.length < 20 && host in patterns && patterns[host]["enabled"]) {
for (let i in patterns[host]["patterns"]) {
patternMatch = new UrlPattern(patterns[host]["patterns"][i]).match(cleanURL(url, host).split(".com/")[1]);
if (patternMatch) break;
}
if (patternMatch) {
return await match(host, patternMatch, url, lang, obj);
} return apiJSON(0, { t: errorUnsupported(lang) })
} return apiJSON(0, { t: errorUnsupported(lang) })
} else {
return apiJSON(0, { t: errorUnsupported(lang) })
}
} catch (e) {
return apiJSON(0, { t: loc(lang, 'ErrorSomethingWentWrong') });
}
}