mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 12:50:01 +00:00
api/match-action: clean up audio action
This commit is contained in:
parent
b3d846a1e3
commit
102dec4a84
6 changed files with 31 additions and 42 deletions
|
@ -1,5 +1,4 @@
|
||||||
const genericUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36";
|
const genericUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36";
|
||||||
const supportedAudio = ["mp3", "ogg", "wav", "opus"];
|
|
||||||
|
|
||||||
const env = {
|
const env = {
|
||||||
apiURL: process.env.API_URL || '',
|
apiURL: process.env.API_URL || '',
|
||||||
|
@ -32,7 +31,5 @@ const env = {
|
||||||
|
|
||||||
export {
|
export {
|
||||||
env,
|
env,
|
||||||
|
|
||||||
genericUserAgent,
|
genericUserAgent,
|
||||||
supportedAudio,
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
import createFilename from "./create-filename.js";
|
import createFilename from "./create-filename.js";
|
||||||
|
|
||||||
import { supportedAudio } from "../config.js";
|
|
||||||
import { createResponse } from "./request.js";
|
import { createResponse } from "./request.js";
|
||||||
|
import { audioIgnore } from "./service-config.js";
|
||||||
import { createStream } from "../stream/manage.js";
|
import { createStream } from "../stream/manage.js";
|
||||||
import { audioIgnore, services } from "./service-config.js";
|
|
||||||
|
|
||||||
export default function({ r, host, audioFormat, isAudioOnly, isAudioMuted, disableMetadata, filenameStyle, twitterGif, requestIP, audioBitrate }) {
|
export default function({ r, host, audioFormat, isAudioOnly, isAudioMuted, disableMetadata, filenameStyle, twitterGif, requestIP, audioBitrate }) {
|
||||||
let action,
|
let action,
|
||||||
|
@ -65,8 +64,9 @@ export default function({ r, host, audioFormat, isAudioOnly, isAudioMuted, disab
|
||||||
type: muteType,
|
type: muteType,
|
||||||
u: Array.isArray(r.urls) ? r.urls[0] : r.urls
|
u: Array.isArray(r.urls) ? r.urls[0] : r.urls
|
||||||
}
|
}
|
||||||
if (host === "reddit" && r.typeId === "redirect")
|
if (host === "reddit" && r.typeId === "redirect") {
|
||||||
responseType = "redirect";
|
responseType = "redirect";
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "picker":
|
case "picker":
|
||||||
|
@ -77,9 +77,10 @@ export default function({ r, host, audioFormat, isAudioOnly, isAudioMuted, disab
|
||||||
case "snapchat":
|
case "snapchat":
|
||||||
params = { picker: r.picker };
|
params = { picker: r.picker };
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "tiktok":
|
case "tiktok":
|
||||||
let audioStreamType = "audio";
|
let audioStreamType = "audio";
|
||||||
if (r.bestAudio === "mp3" && (audioFormat === "mp3" || audioFormat === "best")) {
|
if (r.bestAudio === "mp3" && audioFormat === "best") {
|
||||||
audioFormat = "mp3";
|
audioFormat = "mp3";
|
||||||
audioStreamType = "proxy"
|
audioStreamType = "proxy"
|
||||||
}
|
}
|
||||||
|
@ -95,6 +96,7 @@ export default function({ r, host, audioFormat, isAudioOnly, isAudioMuted, disab
|
||||||
audioFormat,
|
audioFormat,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -103,13 +105,16 @@ export default function({ r, host, audioFormat, isAudioOnly, isAudioMuted, disab
|
||||||
case "bilibili":
|
case "bilibili":
|
||||||
params = { type: "merge" };
|
params = { type: "merge" };
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "youtube":
|
case "youtube":
|
||||||
params = { type: r.type };
|
params = { type: r.type };
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "reddit":
|
case "reddit":
|
||||||
responseType = r.typeId;
|
responseType = r.typeId;
|
||||||
params = { type: r.type };
|
params = { type: r.type };
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "vimeo":
|
case "vimeo":
|
||||||
if (Array.isArray(r.urls)) {
|
if (Array.isArray(r.urls)) {
|
||||||
params = { type: "merge" }
|
params = { type: "merge" }
|
||||||
|
@ -151,43 +156,29 @@ export default function({ r, host, audioFormat, isAudioOnly, isAudioMuted, disab
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
let processType = "audio",
|
let processType = "audio";
|
||||||
copy = false;
|
let copy = false;
|
||||||
|
|
||||||
if (!supportedAudio.includes(audioFormat)) {
|
if (audioFormat === "best") {
|
||||||
audioFormat = "best"
|
const serviceBestAudio = r.bestAudio;
|
||||||
}
|
|
||||||
|
|
||||||
const serviceBestAudio = r.bestAudio || services[host]["bestAudio"];
|
if (serviceBestAudio) {
|
||||||
const isBestAudio = audioFormat === "best";
|
|
||||||
const isBestOrMp3 = isBestAudio || audioFormat === "mp3";
|
|
||||||
const isBestAudioDefined = isBestAudio && serviceBestAudio;
|
|
||||||
const isBestHostAudio = serviceBestAudio && (audioFormat === serviceBestAudio);
|
|
||||||
|
|
||||||
const isTumblrAudio = host === "tumblr" && !r.filename;
|
|
||||||
const isSoundCloud = host === "soundcloud";
|
|
||||||
const isTiktok = host === "tiktok";
|
|
||||||
|
|
||||||
if (isBestAudioDefined || isBestHostAudio) {
|
|
||||||
audioFormat = serviceBestAudio;
|
audioFormat = serviceBestAudio;
|
||||||
processType = "proxy";
|
processType = "proxy";
|
||||||
if (isSoundCloud || (isTiktok && audioFormat === "m4a")) {
|
|
||||||
processType = "audio"
|
|
||||||
copy = true
|
|
||||||
}
|
|
||||||
} else if (isBestAudio && !isSoundCloud) {
|
|
||||||
audioFormat = "m4a";
|
|
||||||
copy = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isTumblrAudio && isBestOrMp3) {
|
if (host === "soundcloud") {
|
||||||
audioFormat = "mp3";
|
processType = "audio";
|
||||||
processType = "proxy"
|
copy = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
audioFormat = "m4a";
|
||||||
|
copy = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r.isM3U8 || host === "vimeo") {
|
if (r.isM3U8 || host === "vimeo") {
|
||||||
copy = false;
|
copy = false;
|
||||||
processType = "audio"
|
processType = "audio";
|
||||||
}
|
}
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
|
|
|
@ -166,7 +166,6 @@ export const services = {
|
||||||
"/channels/:user/:id"
|
"/channels/:user/:id"
|
||||||
],
|
],
|
||||||
subdomains: ["player"],
|
subdomains: ["player"],
|
||||||
bestAudio: "mp3",
|
|
||||||
},
|
},
|
||||||
vk: {
|
vk: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
@ -185,7 +184,6 @@ export const services = {
|
||||||
"watch/:id"
|
"watch/:id"
|
||||||
],
|
],
|
||||||
subdomains: ["music", "m"],
|
subdomains: ["music", "m"],
|
||||||
bestAudio: "opus",
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ export default async function(obj) {
|
||||||
|
|
||||||
let video, videoFilename, audioFilename, audio, images,
|
let video, videoFilename, audioFilename, audio, images,
|
||||||
filenameBase = `tiktok_${detail.author.uniqueId}_${postId}`,
|
filenameBase = `tiktok_${detail.author.uniqueId}_${postId}`,
|
||||||
bestAudio = 'm4a';
|
bestAudio; // will get defaulted to m4a later on in match-action
|
||||||
|
|
||||||
images = detail.imagePost?.images;
|
images = detail.imagePost?.images;
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,8 @@ export default async function(input) {
|
||||||
title: fileMetadata.title,
|
title: fileMetadata.title,
|
||||||
author: fileMetadata.artist
|
author: fileMetadata.artist
|
||||||
},
|
},
|
||||||
isAudioOnly: true
|
isAudioOnly: true,
|
||||||
|
bestAudio: "mp3",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,8 @@ const getDirectLink = (data, quality) => {
|
||||||
resolution: `${match.width}x${match.height}`,
|
resolution: `${match.width}x${match.height}`,
|
||||||
qualityLabel: match.rendition,
|
qualityLabel: match.rendition,
|
||||||
extension: "mp4"
|
extension: "mp4"
|
||||||
}
|
},
|
||||||
|
bestAudio: "mp3",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +132,8 @@ const getHLS = async (configURL, obj) => {
|
||||||
resolution: `${bestQuality.resolution.width}x${bestQuality.resolution.height}`,
|
resolution: `${bestQuality.resolution.width}x${bestQuality.resolution.height}`,
|
||||||
qualityLabel: `${resolutionMatch[bestQuality.resolution.width]}p`,
|
qualityLabel: `${resolutionMatch[bestQuality.resolution.width]}p`,
|
||||||
extension: "mp4"
|
extension: "mp4"
|
||||||
}
|
},
|
||||||
|
bestAudio: "mp3",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue