2022-07-08 18:17:56 +00:00
|
|
|
import UrlPattern from "url-pattern";
|
|
|
|
|
|
|
|
import { services as patterns } from "./config.js";
|
|
|
|
|
2022-07-17 11:21:51 +00:00
|
|
|
import { cleanURL, apiJSON } from "./sub/utils.js";
|
2022-07-08 18:17:56 +00:00
|
|
|
import { errorUnsupported } from "./sub/errors.js";
|
2022-07-24 10:54:05 +00:00
|
|
|
import loc from "../localization/manager.js";
|
2022-07-10 13:30:42 +00:00
|
|
|
import match from "./match.js";
|
2022-07-08 18:17:56 +00:00
|
|
|
|
|
|
|
export async function getJSON(originalURL, ip, lang, format, quality) {
|
|
|
|
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 && 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]);
|
2022-07-28 16:03:17 +00:00
|
|
|
if (patternMatch) break;
|
2022-07-08 18:17:56 +00:00
|
|
|
}
|
|
|
|
if (patternMatch) {
|
|
|
|
return await match(host, patternMatch, url, ip, lang, format, quality);
|
2022-07-28 16:03:17 +00:00
|
|
|
} return apiJSON(0, { t: errorUnsupported(lang) } )
|
|
|
|
} return apiJSON(0, { t: errorUnsupported(lang) } )
|
2022-07-08 18:17:56 +00:00
|
|
|
} else {
|
|
|
|
return apiJSON(0, { t: errorUnsupported(lang) } )
|
|
|
|
}
|
|
|
|
} catch (e) {
|
2022-07-24 10:54:05 +00:00
|
|
|
return apiJSON(0, { t: loc(lang, 'ErrorSomethingWentWrong') });
|
2022-07-08 18:17:56 +00:00
|
|
|
}
|
|
|
|
}
|