mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 12:50:01 +00:00
api: update post parameters
they're now way easier to read
This commit is contained in:
parent
d419fd35b0
commit
5ea71ee58e
4 changed files with 88 additions and 63 deletions
|
@ -137,7 +137,10 @@ export function runAPI(express, app, __dirname) {
|
||||||
return fail('ErrorNoLink');
|
return fail('ErrorNoLink');
|
||||||
}
|
}
|
||||||
|
|
||||||
request.dubLang = request.dubLang ? lang : false;
|
if (request.youtubeDubBrowserLang) {
|
||||||
|
request.youtubeDubLang = lang;
|
||||||
|
}
|
||||||
|
|
||||||
const normalizedRequest = normalizeRequest(request);
|
const normalizedRequest = normalizeRequest(request);
|
||||||
if (!normalizedRequest) {
|
if (!normalizedRequest) {
|
||||||
return fail('ErrorCantProcess');
|
return fail('ErrorCantProcess');
|
||||||
|
@ -150,7 +153,7 @@ export function runAPI(express, app, __dirname) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await match(
|
const result = await match(
|
||||||
parsed.host, parsed.patternMatch, lang, normalizedRequest
|
parsed.host, parsed.patternMatch, normalizedRequest
|
||||||
);
|
);
|
||||||
|
|
||||||
res.status(result.status).json(result.body);
|
res.status(result.status).json(result.body);
|
||||||
|
@ -171,19 +174,16 @@ export function runAPI(express, app, __dirname) {
|
||||||
const checkSafeLength = sig.length === 43 && sec.length === 43 && iv.length === 22;
|
const checkSafeLength = sig.length === 43 && sec.length === 43 && iv.length === 22;
|
||||||
|
|
||||||
if (!checkQueries || !checkBaseLength || !checkSafeLength) {
|
if (!checkQueries || !checkBaseLength || !checkSafeLength) {
|
||||||
return res.sendStatus(400);
|
return res.status(400).end();
|
||||||
}
|
}
|
||||||
|
|
||||||
// rate limit probe, will not return json after 8.0
|
|
||||||
if (req.query.p) {
|
if (req.query.p) {
|
||||||
return res.status(200).json({
|
return res.status(200).end();
|
||||||
status: "continue"
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const streamInfo = verifyStream(id, sig, exp, sec, iv);
|
const streamInfo = verifyStream(id, sig, exp, sec, iv);
|
||||||
if (!streamInfo?.service) {
|
if (!streamInfo?.service) {
|
||||||
return res.sendStatus(streamInfo.status);
|
return res.status(streamInfo.status).end();
|
||||||
}
|
}
|
||||||
return stream(res, streamInfo);
|
return stream(res, streamInfo);
|
||||||
})
|
})
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { createResponse } from "./request.js";
|
||||||
import createFilename from "./create-filename.js";
|
import createFilename from "./create-filename.js";
|
||||||
import { createStream } from "../stream/manage.js";
|
import { createStream } from "../stream/manage.js";
|
||||||
|
|
||||||
export default function({ r, host, audioFormat, isAudioOnly, isAudioMuted, disableMetadata, filenameStyle, toGif, requestIP }) {
|
export default function({ r, host, audioFormat, isAudioOnly, isAudioMuted, disableMetadata, filenameStyle, twitterGif, requestIP }) {
|
||||||
let action,
|
let action,
|
||||||
responseType = "stream",
|
responseType = "stream",
|
||||||
defaultParams = {
|
defaultParams = {
|
||||||
|
@ -21,9 +21,9 @@ export default function({ r, host, audioFormat, isAudioOnly, isAudioMuted, disab
|
||||||
|
|
||||||
if (r.isPhoto) action = "photo";
|
if (r.isPhoto) action = "photo";
|
||||||
else if (r.picker) action = "picker"
|
else if (r.picker) action = "picker"
|
||||||
else if (r.isGif && toGif) action = "gif";
|
else if (r.isGif && twitterGif) action = "gif";
|
||||||
else if (isAudioMuted) action = "muteVideo";
|
|
||||||
else if (isAudioOnly) action = "audio";
|
else if (isAudioOnly) action = "audio";
|
||||||
|
else if (isAudioMuted) action = "muteVideo";
|
||||||
else if (r.isM3U8) action = "m3u8";
|
else if (r.isM3U8) action = "m3u8";
|
||||||
else action = "video";
|
else action = "video";
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ import facebook from "./services/facebook.js";
|
||||||
|
|
||||||
let freebind;
|
let freebind;
|
||||||
|
|
||||||
export default async function(host, patternMatch, lang, obj) {
|
export default async function(host, patternMatch, obj) {
|
||||||
const { url } = obj;
|
const { url } = obj;
|
||||||
assert(url instanceof URL);
|
assert(url instanceof URL);
|
||||||
let dispatcher, requestIP;
|
let dispatcher, requestIP;
|
||||||
|
@ -45,7 +45,8 @@ export default async function(host, patternMatch, lang, obj) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let r,
|
let r,
|
||||||
isAudioOnly = !!obj.isAudioOnly,
|
isAudioOnly = obj.downloadMode === "audio",
|
||||||
|
isAudioMuted = obj.downloadMode === "mute",
|
||||||
disableMetadata = !!obj.disableMetadata;
|
disableMetadata = !!obj.disableMetadata;
|
||||||
|
|
||||||
if (!testers[host]) {
|
if (!testers[host]) {
|
||||||
|
@ -71,41 +72,47 @@ export default async function(host, patternMatch, lang, obj) {
|
||||||
dispatcher
|
dispatcher
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "vk":
|
case "vk":
|
||||||
r = await vk({
|
r = await vk({
|
||||||
userId: patternMatch.userId,
|
userId: patternMatch.userId,
|
||||||
videoId: patternMatch.videoId,
|
videoId: patternMatch.videoId,
|
||||||
quality: obj.vQuality
|
quality: obj.videoQuality
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "ok":
|
case "ok":
|
||||||
r = await ok({
|
r = await ok({
|
||||||
id: patternMatch.id,
|
id: patternMatch.id,
|
||||||
quality: obj.vQuality
|
quality: obj.videoQuality
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "bilibili":
|
case "bilibili":
|
||||||
r = await bilibili(patternMatch);
|
r = await bilibili(patternMatch);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "youtube":
|
case "youtube":
|
||||||
let fetchInfo = {
|
let fetchInfo = {
|
||||||
id: patternMatch.id.slice(0, 11),
|
id: patternMatch.id.slice(0, 11),
|
||||||
quality: obj.vQuality,
|
quality: obj.videoQuality,
|
||||||
format: obj.vCodec,
|
format: obj.youtubeVideoCodec,
|
||||||
isAudioOnly: isAudioOnly,
|
isAudioOnly,
|
||||||
isAudioMuted: obj.isAudioMuted,
|
isAudioMuted,
|
||||||
dubLang: obj.dubLang,
|
dubLang: obj.youtubeDubLang,
|
||||||
dispatcher
|
dispatcher
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url.hostname === 'music.youtube.com' || isAudioOnly === true) {
|
if (url.hostname === "music.youtube.com" || isAudioOnly) {
|
||||||
fetchInfo.quality = "max";
|
fetchInfo.quality = "max";
|
||||||
fetchInfo.format = "vp9";
|
fetchInfo.format = "vp9";
|
||||||
fetchInfo.isAudioOnly = true
|
fetchInfo.isAudioOnly = true;
|
||||||
|
fetchInfo.isAudioMuted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = await youtube(fetchInfo);
|
r = await youtube(fetchInfo);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "reddit":
|
case "reddit":
|
||||||
r = await reddit({
|
r = await reddit({
|
||||||
sub: patternMatch.sub,
|
sub: patternMatch.sub,
|
||||||
|
@ -113,15 +120,17 @@ export default async function(host, patternMatch, lang, obj) {
|
||||||
user: patternMatch.user
|
user: patternMatch.user
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "tiktok":
|
case "tiktok":
|
||||||
r = await tiktok({
|
r = await tiktok({
|
||||||
postId: patternMatch.postId,
|
postId: patternMatch.postId,
|
||||||
id: patternMatch.id,
|
id: patternMatch.id,
|
||||||
fullAudio: obj.isTTFullAudio,
|
fullAudio: obj.tiktokFullAudio,
|
||||||
isAudioOnly: isAudioOnly,
|
isAudioOnly,
|
||||||
h265: obj.tiktokH265
|
h265: obj.tiktokH265
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "tumblr":
|
case "tumblr":
|
||||||
r = await tumblr({
|
r = await tumblr({
|
||||||
id: patternMatch.id,
|
id: patternMatch.id,
|
||||||
|
@ -129,90 +138,106 @@ export default async function(host, patternMatch, lang, obj) {
|
||||||
url
|
url
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "vimeo":
|
case "vimeo":
|
||||||
r = await vimeo({
|
r = await vimeo({
|
||||||
id: patternMatch.id.slice(0, 11),
|
id: patternMatch.id.slice(0, 11),
|
||||||
password: patternMatch.password,
|
password: patternMatch.password,
|
||||||
quality: obj.vQuality,
|
quality: obj.videoQuality,
|
||||||
isAudioOnly: isAudioOnly
|
isAudioOnly,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "soundcloud":
|
case "soundcloud":
|
||||||
isAudioOnly = true;
|
isAudioOnly = true;
|
||||||
|
isAudioMuted = false;
|
||||||
r = await soundcloud({
|
r = await soundcloud({
|
||||||
url,
|
url,
|
||||||
author: patternMatch.author,
|
author: patternMatch.author,
|
||||||
song: patternMatch.song,
|
song: patternMatch.song,
|
||||||
format: obj.aFormat,
|
format: obj.audioFormat,
|
||||||
shortLink: patternMatch.shortLink || false,
|
shortLink: patternMatch.shortLink || false,
|
||||||
accessKey: patternMatch.accessKey || false
|
accessKey: patternMatch.accessKey || false
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "instagram":
|
case "instagram":
|
||||||
r = await instagram({
|
r = await instagram({
|
||||||
...patternMatch,
|
...patternMatch,
|
||||||
quality: obj.vQuality,
|
quality: obj.videoQuality,
|
||||||
dispatcher
|
dispatcher
|
||||||
})
|
})
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "vine":
|
case "vine":
|
||||||
r = await vine({
|
r = await vine({
|
||||||
id: patternMatch.id
|
id: patternMatch.id
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "pinterest":
|
case "pinterest":
|
||||||
r = await pinterest({
|
r = await pinterest({
|
||||||
id: patternMatch.id,
|
id: patternMatch.id,
|
||||||
shortLink: patternMatch.shortLink || false
|
shortLink: patternMatch.shortLink || false
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "streamable":
|
case "streamable":
|
||||||
r = await streamable({
|
r = await streamable({
|
||||||
id: patternMatch.id,
|
id: patternMatch.id,
|
||||||
quality: obj.vQuality,
|
quality: obj.videoQuality,
|
||||||
isAudioOnly: isAudioOnly,
|
isAudioOnly,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "twitch":
|
case "twitch":
|
||||||
r = await twitch({
|
r = await twitch({
|
||||||
clipId: patternMatch.clip || false,
|
clipId: patternMatch.clip || false,
|
||||||
quality: obj.vQuality,
|
quality: obj.videoQuality,
|
||||||
isAudioOnly: obj.isAudioOnly
|
isAudioOnly,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "rutube":
|
case "rutube":
|
||||||
r = await rutube({
|
r = await rutube({
|
||||||
id: patternMatch.id,
|
id: patternMatch.id,
|
||||||
yappyId: patternMatch.yappyId,
|
yappyId: patternMatch.yappyId,
|
||||||
key: patternMatch.key,
|
key: patternMatch.key,
|
||||||
quality: obj.vQuality,
|
quality: obj.videoQuality,
|
||||||
isAudioOnly: isAudioOnly
|
isAudioOnly,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "dailymotion":
|
case "dailymotion":
|
||||||
r = await dailymotion(patternMatch);
|
r = await dailymotion(patternMatch);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "snapchat":
|
case "snapchat":
|
||||||
r = await snapchat(patternMatch);
|
r = await snapchat(patternMatch);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "loom":
|
case "loom":
|
||||||
r = await loom({
|
r = await loom({
|
||||||
id: patternMatch.id
|
id: patternMatch.id
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "facebook":
|
case "facebook":
|
||||||
r = await facebook({
|
r = await facebook({
|
||||||
...patternMatch
|
...patternMatch
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return createResponse("error", {
|
return createResponse("error", {
|
||||||
code: "ErrorUnsupported"
|
code: "ErrorUnsupported"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r.isAudioOnly) isAudioOnly = true;
|
if (r.isAudioOnly) {
|
||||||
let isAudioMuted = isAudioOnly ? false : obj.isAudioMuted;
|
isAudioOnly = true;
|
||||||
|
isAudioMuted = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (r.error && r.critical) {
|
if (r.error && r.critical) {
|
||||||
return createResponse("critical", {
|
return createResponse("critical", {
|
||||||
|
@ -230,12 +255,12 @@ export default async function(host, patternMatch, lang, obj) {
|
||||||
return matchAction({
|
return matchAction({
|
||||||
r,
|
r,
|
||||||
host,
|
host,
|
||||||
audioFormat: obj.aFormat,
|
audioFormat: obj.audioFormat,
|
||||||
isAudioOnly,
|
isAudioOnly,
|
||||||
isAudioMuted,
|
isAudioMuted,
|
||||||
disableMetadata,
|
disableMetadata,
|
||||||
filenameStyle: obj.filenamePattern,
|
filenameStyle: obj.filenameStyle,
|
||||||
toGif: obj.twitterGif,
|
twitterGif: obj.twitterGif,
|
||||||
requestIP
|
requestIP
|
||||||
})
|
})
|
||||||
} catch {
|
} catch {
|
||||||
|
|
|
@ -4,21 +4,21 @@ import { normalizeURL } from "./url.js";
|
||||||
import { createStream } from "../stream/manage.js";
|
import { createStream } from "../stream/manage.js";
|
||||||
import { verifyLanguageCode } from "../misc/utils.js";
|
import { verifyLanguageCode } from "../misc/utils.js";
|
||||||
|
|
||||||
const apiVar = {
|
const apiRequest = {
|
||||||
allowed: {
|
option: {
|
||||||
vCodec: ["h264", "av1", "vp9"],
|
audioFormat: ["best", "mp3", "ogg", "wav", "opus"],
|
||||||
vQuality: ["max", "4320", "2160", "1440", "1080", "720", "480", "360", "240", "144"],
|
downloadMode: ["auto", "audio", "mute"],
|
||||||
aFormat: ["best", "mp3", "ogg", "wav", "opus"],
|
filenameStyle: ["classic", "pretty", "basic", "nerdy"],
|
||||||
filenamePattern: ["classic", "pretty", "basic", "nerdy"]
|
videoQuality: ["max", "4320", "2160", "1440", "1080", "720", "480", "360", "240", "144"],
|
||||||
|
youtubeVideoCodec: ["h264", "av1", "vp9"],
|
||||||
},
|
},
|
||||||
booleanOnly: [
|
boolean: [
|
||||||
"isAudioOnly",
|
|
||||||
"isTTFullAudio",
|
|
||||||
"isAudioMuted",
|
|
||||||
"dubLang",
|
|
||||||
"disableMetadata",
|
"disableMetadata",
|
||||||
|
"tiktokFullAudio",
|
||||||
|
"tiktokH265",
|
||||||
"twitterGif",
|
"twitterGif",
|
||||||
"tiktokH265"
|
"youtubeDubBrowserLang",
|
||||||
|
"youtubeDubLang"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,16 +116,16 @@ export function createResponse(responseType, responseData) {
|
||||||
export function normalizeRequest(request) {
|
export function normalizeRequest(request) {
|
||||||
try {
|
try {
|
||||||
let template = {
|
let template = {
|
||||||
|
audioFormat: "mp3",
|
||||||
url: normalizeURL(decodeURIComponent(request.url)),
|
url: normalizeURL(decodeURIComponent(request.url)),
|
||||||
vCodec: "h264",
|
youtubeVideoCodec: "h264",
|
||||||
vQuality: "720",
|
videoQuality: "720",
|
||||||
aFormat: "mp3",
|
filenameStyle: "classic",
|
||||||
filenamePattern: "classic",
|
downloadMode: "auto",
|
||||||
isAudioOnly: false,
|
tiktokFullAudio: false,
|
||||||
isTTFullAudio: false,
|
|
||||||
isAudioMuted: false,
|
|
||||||
disableMetadata: false,
|
disableMetadata: false,
|
||||||
dubLang: false,
|
youtubeDubBrowserLang: false,
|
||||||
|
youtubeDubLang: false,
|
||||||
twitterGif: false,
|
twitterGif: false,
|
||||||
tiktokH265: false
|
tiktokH265: false
|
||||||
}
|
}
|
||||||
|
@ -142,16 +142,16 @@ export function normalizeRequest(request) {
|
||||||
const item = request[key];
|
const item = request[key];
|
||||||
|
|
||||||
if (String(key) !== "url" && templateKeys.includes(key)) {
|
if (String(key) !== "url" && templateKeys.includes(key)) {
|
||||||
if (apiVar.booleanOnly.includes(key)) {
|
if (apiRequest.boolean.includes(key)) {
|
||||||
template[key] = !!item;
|
template[key] = !!item;
|
||||||
} else if (apiVar.allowed[key] && apiVar.allowed[key].includes(item)) {
|
} else if (apiRequest.option[key] && apiRequest.option[key].includes(item)) {
|
||||||
template[key] = String(item)
|
template[key] = String(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (template.dubLang)
|
if (template.youtubeDubBrowserLang)
|
||||||
template.dubLang = verifyLanguageCode(request.dubLang);
|
template.youtubeDubLang = verifyLanguageCode(request.youtubeDubLang);
|
||||||
|
|
||||||
return template
|
return template
|
||||||
} catch {
|
} catch {
|
||||||
|
|
Loading…
Reference in a new issue