mirror of
https://github.com/Kirazul/Verome-API.git
synced 2026-03-08 08:15:20 +00:00
Fix download endpoint field detection for streaming URLs
This commit is contained in:
36
mod.ts
36
mod.ts
@@ -263,32 +263,42 @@ async function handler(req: Request): Promise<Response> {
|
|||||||
const artist = searchParams.get("artist") || "";
|
const artist = searchParams.get("artist") || "";
|
||||||
if (!id) return error("Missing id");
|
if (!id) return error("Missing id");
|
||||||
|
|
||||||
// Get stream URL
|
// Get stream URL - try piped first, then invidious
|
||||||
const piped = await fetchFromPiped(id);
|
|
||||||
let audioUrl = null;
|
let audioUrl = null;
|
||||||
let metadata = null;
|
let contentType = "audio/mp4";
|
||||||
|
|
||||||
|
const piped = await fetchFromPiped(id);
|
||||||
if (piped.success && piped.streamingUrls) {
|
if (piped.success && piped.streamingUrls) {
|
||||||
const audio = piped.streamingUrls.find((s: any) => s.mimeType?.includes("audio") && s.quality === "AUDIO_QUALITY_MEDIUM")
|
// Check for mimeType or type field, and quality or audioQuality
|
||||||
|| piped.streamingUrls.find((s: any) => s.mimeType?.includes("audio"));
|
const audio = piped.streamingUrls.find((s: any) =>
|
||||||
if (audio) audioUrl = audio.url;
|
(s.mimeType?.includes("audio") || s.type?.includes("audio")) &&
|
||||||
metadata = piped.metadata;
|
(s.quality === "AUDIO_QUALITY_MEDIUM" || s.audioQuality === "AUDIO_QUALITY_MEDIUM")
|
||||||
|
) || piped.streamingUrls.find((s: any) => s.mimeType?.includes("audio") || s.type?.includes("audio"));
|
||||||
|
if (audio) {
|
||||||
|
audioUrl = audio.url || audio.directUrl;
|
||||||
|
contentType = audio.mimeType || audio.type || "audio/mp4";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!audioUrl) {
|
if (!audioUrl) {
|
||||||
const invidious = await fetchFromInvidious(id);
|
const invidious = await fetchFromInvidious(id);
|
||||||
if (invidious.success && invidious.streamingUrls) {
|
if (invidious.success && invidious.streamingUrls) {
|
||||||
const audio = invidious.streamingUrls.find((s: any) => s.mimeType?.includes("audio") && s.quality === "AUDIO_QUALITY_MEDIUM")
|
const audio = invidious.streamingUrls.find((s: any) =>
|
||||||
|| invidious.streamingUrls.find((s: any) => s.mimeType?.includes("audio"));
|
(s.mimeType?.includes("audio") || s.type?.includes("audio")) &&
|
||||||
if (audio) audioUrl = audio.url;
|
(s.quality === "AUDIO_QUALITY_MEDIUM" || s.audioQuality === "AUDIO_QUALITY_MEDIUM")
|
||||||
metadata = invidious.metadata;
|
) || invidious.streamingUrls.find((s: any) => s.mimeType?.includes("audio") || s.type?.includes("audio"));
|
||||||
|
if (audio) {
|
||||||
|
audioUrl = audio.url || audio.directUrl;
|
||||||
|
contentType = audio.mimeType || audio.type || "audio/mp4";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!audioUrl) return json({ success: false, error: "No audio stream found" }, 404);
|
if (!audioUrl) return json({ success: false, error: "No audio stream found" }, 404);
|
||||||
|
|
||||||
// Create filename
|
// Create filename - use m4a for mp4 audio, webm for webm
|
||||||
const filename = `${artist ? artist + " - " : ""}${title}`.replace(/[<>:"/\\|?*]/g, "").trim() + ".m4a";
|
const ext = contentType.includes("webm") ? ".webm" : ".m4a";
|
||||||
|
const filename = `${artist ? artist + " - " : ""}${title}`.replace(/[<>:"/\\|?*]/g, "").trim() + ext;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(audioUrl, {
|
const response = await fetch(audioUrl, {
|
||||||
|
|||||||
Reference in New Issue
Block a user