api/match-action: clean up audio action

This commit is contained in:
wukko 2024-08-22 22:45:26 +06:00
parent b3d846a1e3
commit 102dec4a84
No known key found for this signature in database
GPG key ID: 3E30B3F26C7B4AA2
6 changed files with 31 additions and 42 deletions

View file

@ -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,
} }

View file

@ -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 = {

View file

@ -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",
} }
} }

View file

@ -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;

View file

@ -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",
} }
} }

View file

@ -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",
} }
} }