mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-17 22:00:00 +00:00
processing: pass URL object instead of string
This commit is contained in:
parent
30c9652b6e
commit
81e68c37f5
4 changed files with 12 additions and 7 deletions
|
@ -27,7 +27,7 @@ export async function getJSON(originalURL, lang, obj) {
|
||||||
return apiJSON(0, { t: errorUnsupported(lang) });
|
return apiJSON(0, { t: errorUnsupported(lang) });
|
||||||
}
|
}
|
||||||
|
|
||||||
return await match(host, patternMatch, url.toString(), lang, obj)
|
return await match(host, patternMatch, url, lang, obj)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return apiJSON(0, { t: loc(lang, 'ErrorSomethingWentWrong') })
|
return apiJSON(0, { t: loc(lang, 'ErrorSomethingWentWrong') })
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { strict as assert } from "node:assert";
|
||||||
|
|
||||||
import { apiJSON } from "../sub/utils.js";
|
import { apiJSON } from "../sub/utils.js";
|
||||||
import { errorUnsupported, genericError, brokenLink } from "../sub/errors.js";
|
import { errorUnsupported, genericError, brokenLink } from "../sub/errors.js";
|
||||||
|
|
||||||
|
@ -23,6 +25,8 @@ import twitch from "./services/twitch.js";
|
||||||
import rutube from "./services/rutube.js";
|
import rutube from "./services/rutube.js";
|
||||||
|
|
||||||
export default async function(host, patternMatch, url, lang, obj) {
|
export default async function(host, patternMatch, url, lang, obj) {
|
||||||
|
assert(url instanceof URL);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let r, isAudioOnly = !!obj.isAudioOnly, disableMetadata = !!obj.disableMetadata;
|
let r, isAudioOnly = !!obj.isAudioOnly, disableMetadata = !!obj.disableMetadata;
|
||||||
|
|
||||||
|
@ -57,7 +61,7 @@ export default async function(host, patternMatch, url, lang, obj) {
|
||||||
dubLang: obj.dubLang
|
dubLang: obj.dubLang
|
||||||
}
|
}
|
||||||
|
|
||||||
if (new URL(url).hostname === 'music.youtube.com' || isAudioOnly === true) {
|
if (url.hostname === 'music.youtube.com' || isAudioOnly === true) {
|
||||||
fetchInfo.quality = "max";
|
fetchInfo.quality = "max";
|
||||||
fetchInfo.format = "vp9";
|
fetchInfo.format = "vp9";
|
||||||
fetchInfo.isAudioOnly = true
|
fetchInfo.isAudioOnly = true
|
||||||
|
@ -100,7 +104,7 @@ export default async function(host, patternMatch, url, lang, obj) {
|
||||||
case "soundcloud":
|
case "soundcloud":
|
||||||
isAudioOnly = true;
|
isAudioOnly = true;
|
||||||
r = await soundcloud({
|
r = await soundcloud({
|
||||||
url: url,
|
url,
|
||||||
author: patternMatch["author"],
|
author: patternMatch["author"],
|
||||||
song: patternMatch["song"],
|
song: patternMatch["song"],
|
||||||
shortLink: patternMatch["shortLink"] || false,
|
shortLink: patternMatch["shortLink"] || false,
|
||||||
|
|
|
@ -39,17 +39,18 @@ export default async function(obj) {
|
||||||
if (!clientId) return { error: 'ErrorSoundCloudNoClientId' };
|
if (!clientId) return { error: 'ErrorSoundCloudNoClientId' };
|
||||||
|
|
||||||
let link;
|
let link;
|
||||||
if (obj.shortLink && !obj.author && !obj.song) {
|
if (obj.url.hostname === 'on.soundcloud.com' && obj.shortLink) {
|
||||||
link = await fetch(`https://on.soundcloud.com/${obj.shortLink}/`, { redirect: "manual" }).then((r) => {
|
link = await fetch(`https://on.soundcloud.com/${obj.shortLink}/`, { redirect: "manual" }).then((r) => {
|
||||||
if (r.status === 302 && r.headers.get("location").startsWith("https://soundcloud.com/")) {
|
if (r.status === 302 && r.headers.get("location").startsWith("https://soundcloud.com/")) {
|
||||||
return r.headers.get("location").split('?', 1)[0]
|
return r.headers.get("location").split('?', 1)[0]
|
||||||
}
|
}
|
||||||
return false
|
}).catch(() => {});
|
||||||
}).catch(() => { return false });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!link && obj.author && obj.song) {
|
if (!link && obj.author && obj.song) {
|
||||||
link = `https://soundcloud.com/${obj.author}/${obj.song}${obj.accessKey ? `/s-${obj.accessKey}` : ''}`
|
link = `https://soundcloud.com/${obj.author}/${obj.song}${obj.accessKey ? `/s-${obj.accessKey}` : ''}`
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!link) return { error: 'ErrorCouldntFetch' };
|
if (!link) return { error: 'ErrorCouldntFetch' };
|
||||||
|
|
||||||
let json = await fetch(`https://api-v2.soundcloud.com/resolve?url=${link}&client_id=${clientId}`).then((r) => {
|
let json = await fetch(`https://api-v2.soundcloud.com/resolve?url=${link}&client_id=${clientId}`).then((r) => {
|
||||||
|
|
|
@ -2,7 +2,7 @@ import psl from "psl";
|
||||||
import { genericUserAgent } from "../../config.js";
|
import { genericUserAgent } from "../../config.js";
|
||||||
|
|
||||||
export default async function(obj) {
|
export default async function(obj) {
|
||||||
const { subdomain } = psl.parse(obj.url);
|
const { subdomain } = psl.parse(obj.url.hostname);
|
||||||
if (subdomain?.includes('.'))
|
if (subdomain?.includes('.'))
|
||||||
return { error: 'ErrorBrokenLink' }
|
return { error: 'ErrorBrokenLink' }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue