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 supportedAudio = ["mp3", "ogg", "wav", "opus"];
|
||||
|
||||
const env = {
|
||||
apiURL: process.env.API_URL || '',
|
||||
|
@ -32,7 +31,5 @@ const env = {
|
|||
|
||||
export {
|
||||
env,
|
||||
|
||||
genericUserAgent,
|
||||
supportedAudio,
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
const isTumblrAudio = host === "tumblr" && !r.filename;
|
||||
const isSoundCloud = host === "soundcloud";
|
||||
const isTiktok = host === "tiktok";
|
||||
|
||||
if (isBestAudioDefined || isBestHostAudio) {
|
||||
if (serviceBestAudio) {
|
||||
audioFormat = serviceBestAudio;
|
||||
processType = "proxy";
|
||||
if (isSoundCloud || (isTiktok && audioFormat === "m4a")) {
|
||||
processType = "audio"
|
||||
copy = true
|
||||
}
|
||||
} else if (isBestAudio && !isSoundCloud) {
|
||||
audioFormat = "m4a";
|
||||
copy = true
|
||||
}
|
||||
|
||||
if (isTumblrAudio && isBestOrMp3) {
|
||||
audioFormat = "mp3";
|
||||
processType = "proxy"
|
||||
if (host === "soundcloud") {
|
||||
processType = "audio";
|
||||
copy = true;
|
||||
}
|
||||
} else {
|
||||
audioFormat = "m4a";
|
||||
copy = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (r.isM3U8 || host === "vimeo") {
|
||||
copy = false;
|
||||
processType = "audio"
|
||||
processType = "audio";
|
||||
}
|
||||
|
||||
params = {
|
||||
|
|
|
@ -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",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -58,7 +58,8 @@ export default async function(input) {
|
|||
title: fileMetadata.title,
|
||||
author: fileMetadata.artist
|
||||
},
|
||||
isAudioOnly: true
|
||||
isAudioOnly: true,
|
||||
bestAudio: "mp3",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue