diff --git a/api/src/config.js b/api/src/config.js index a989148e..2f9b9f34 100644 --- a/api/src/config.js +++ b/api/src/config.js @@ -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 supportedAudio = ["mp3", "ogg", "wav", "opus"]; const env = { apiURL: process.env.API_URL || '', @@ -32,7 +31,5 @@ const env = { export { env, - genericUserAgent, - supportedAudio, } diff --git a/api/src/processing/match-action.js b/api/src/processing/match-action.js index 91a46af9..4cc533c4 100644 --- a/api/src/processing/match-action.js +++ b/api/src/processing/match-action.js @@ -1,9 +1,8 @@ import createFilename from "./create-filename.js"; -import { supportedAudio } from "../config.js"; import { createResponse } from "./request.js"; +import { audioIgnore } from "./service-config.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 }) { let action, @@ -65,8 +64,9 @@ export default function({ r, host, audioFormat, isAudioOnly, isAudioMuted, disab type: muteType, u: Array.isArray(r.urls) ? r.urls[0] : r.urls } - if (host === "reddit" && r.typeId === "redirect") + if (host === "reddit" && r.typeId === "redirect") { responseType = "redirect"; + } break; case "picker": @@ -77,9 +77,10 @@ export default function({ r, host, audioFormat, isAudioOnly, isAudioMuted, disab case "snapchat": params = { picker: r.picker }; break; + case "tiktok": let audioStreamType = "audio"; - if (r.bestAudio === "mp3" && (audioFormat === "mp3" || audioFormat === "best")) { + if (r.bestAudio === "mp3" && audioFormat === "best") { audioFormat = "mp3"; audioStreamType = "proxy" } @@ -95,6 +96,7 @@ export default function({ r, host, audioFormat, isAudioOnly, isAudioMuted, disab audioFormat, }) } + break; } break; @@ -103,13 +105,16 @@ export default function({ r, host, audioFormat, isAudioOnly, isAudioMuted, disab case "bilibili": params = { type: "merge" }; break; + case "youtube": params = { type: r.type }; break; + case "reddit": responseType = r.typeId; params = { type: r.type }; break; + case "vimeo": if (Array.isArray(r.urls)) { params = { type: "merge" } @@ -151,43 +156,29 @@ export default function({ r, host, audioFormat, isAudioOnly, isAudioMuted, disab }) } - let processType = "audio", - copy = false; + let processType = "audio"; + let copy = false; - if (!supportedAudio.includes(audioFormat)) { - audioFormat = "best" - } + if (audioFormat === "best") { + const serviceBestAudio = r.bestAudio; - const serviceBestAudio = r.bestAudio || services[host]["bestAudio"]; - const isBestAudio = audioFormat === "best"; - const isBestOrMp3 = isBestAudio || audioFormat === "mp3"; - const isBestAudioDefined = isBestAudio && serviceBestAudio; - const isBestHostAudio = serviceBestAudio && (audioFormat === serviceBestAudio); + if (serviceBestAudio) { + audioFormat = serviceBestAudio; + processType = "proxy"; - const isTumblrAudio = host === "tumblr" && !r.filename; - const isSoundCloud = host === "soundcloud"; - const isTiktok = host === "tiktok"; - - if (isBestAudioDefined || isBestHostAudio) { - audioFormat = serviceBestAudio; - processType = "proxy"; - if (isSoundCloud || (isTiktok && audioFormat === "m4a")) { - processType = "audio" - copy = true + if (host === "soundcloud") { + processType = "audio"; + copy = true; + } + } else { + audioFormat = "m4a"; + copy = true; } - } else if (isBestAudio && !isSoundCloud) { - audioFormat = "m4a"; - copy = true - } - - if (isTumblrAudio && isBestOrMp3) { - audioFormat = "mp3"; - processType = "proxy" } if (r.isM3U8 || host === "vimeo") { copy = false; - processType = "audio" + processType = "audio"; } params = { diff --git a/api/src/processing/service-config.js b/api/src/processing/service-config.js index 192e59fe..eba7a6a9 100644 --- a/api/src/processing/service-config.js +++ b/api/src/processing/service-config.js @@ -166,7 +166,6 @@ export const services = { "/channels/:user/:id" ], subdomains: ["player"], - bestAudio: "mp3", }, vk: { enabled: true, @@ -185,7 +184,6 @@ export const services = { "watch/:id" ], subdomains: ["music", "m"], - bestAudio: "opus", } } diff --git a/api/src/processing/services/tiktok.js b/api/src/processing/services/tiktok.js index edf9db88..bc77c1c1 100644 --- a/api/src/processing/services/tiktok.js +++ b/api/src/processing/services/tiktok.js @@ -52,7 +52,7 @@ export default async function(obj) { let video, videoFilename, audioFilename, audio, images, filenameBase = `tiktok_${detail.author.uniqueId}_${postId}`, - bestAudio = 'm4a'; + bestAudio; // will get defaulted to m4a later on in match-action images = detail.imagePost?.images; diff --git a/api/src/processing/services/tumblr.js b/api/src/processing/services/tumblr.js index b661dc8b..b25d17f4 100644 --- a/api/src/processing/services/tumblr.js +++ b/api/src/processing/services/tumblr.js @@ -58,7 +58,8 @@ export default async function(input) { title: fileMetadata.title, author: fileMetadata.artist }, - isAudioOnly: true + isAudioOnly: true, + bestAudio: "mp3", } } diff --git a/api/src/processing/services/vimeo.js b/api/src/processing/services/vimeo.js index ec495ffb..657d1e02 100644 --- a/api/src/processing/services/vimeo.js +++ b/api/src/processing/services/vimeo.js @@ -63,7 +63,8 @@ const getDirectLink = (data, quality) => { resolution: `${match.width}x${match.height}`, qualityLabel: match.rendition, extension: "mp4" - } + }, + bestAudio: "mp3", } } @@ -131,7 +132,8 @@ const getHLS = async (configURL, obj) => { resolution: `${bestQuality.resolution.width}x${bestQuality.resolution.height}`, qualityLabel: `${resolutionMatch[bestQuality.resolution.width]}p`, extension: "mp4" - } + }, + bestAudio: "mp3", } }