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 supportedAudio = ["mp3", "ogg", "wav", "opus"];
const env = {
apiURL: process.env.API_URL || '',
@ -32,7 +31,5 @@ const env = {
export {
env,
genericUserAgent,
supportedAudio,
}

View file

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

View file

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

View file

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

View file

@ -58,7 +58,8 @@ export default async function(input) {
title: fileMetadata.title,
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}`,
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",
}
}