forked from github-mirror/Verome-API
Fix download: use Piped first with correct mimeType field
This commit is contained in:
34
mod.ts
34
mod.ts
@@ -263,32 +263,31 @@ 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 - try invidious first (better proxy support)
|
// Try Piped first - it has better proxy support
|
||||||
let audioUrl = null;
|
let audioUrl = null;
|
||||||
let contentType = "audio/mp4";
|
let contentType = "audio/mp4";
|
||||||
let instance = "";
|
|
||||||
|
|
||||||
const invidious = await fetchFromInvidious(id);
|
const piped = await fetchFromPiped(id);
|
||||||
if (invidious.success && invidious.streamingUrls) {
|
if (piped.success && piped.streamingUrls) {
|
||||||
const audio = invidious.streamingUrls.find((s: any) =>
|
// Piped uses mimeType field
|
||||||
s.type?.includes("audio/mp4") && s.audioQuality === "AUDIO_QUALITY_MEDIUM"
|
const audio = piped.streamingUrls.find((s: any) =>
|
||||||
) || invidious.streamingUrls.find((s: any) => s.type?.includes("audio"));
|
s.mimeType?.includes("audio/mp4")
|
||||||
if (audio) {
|
) || piped.streamingUrls.find((s: any) => s.mimeType?.includes("audio"));
|
||||||
|
if (audio && audio.url) {
|
||||||
audioUrl = audio.url;
|
audioUrl = audio.url;
|
||||||
instance = invidious.instance || "";
|
contentType = audio.mimeType?.split(";")[0] || "audio/mp4";
|
||||||
contentType = audio.type?.split(";")[0] || "audio/mp4";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!audioUrl) {
|
if (!audioUrl) {
|
||||||
const piped = await fetchFromPiped(id);
|
const invidious = await fetchFromInvidious(id);
|
||||||
if (piped.success && piped.streamingUrls) {
|
if (invidious.success && invidious.streamingUrls) {
|
||||||
const audio = piped.streamingUrls.find((s: any) =>
|
// Invidious uses type field
|
||||||
s.type?.includes("audio/mp4") && s.audioQuality === "AUDIO_QUALITY_MEDIUM"
|
const audio = invidious.streamingUrls.find((s: any) =>
|
||||||
) || piped.streamingUrls.find((s: any) => s.type?.includes("audio"));
|
s.type?.includes("audio/mp4")
|
||||||
if (audio) {
|
) || invidious.streamingUrls.find((s: any) => s.type?.includes("audio"));
|
||||||
|
if (audio && audio.url) {
|
||||||
audioUrl = audio.url;
|
audioUrl = audio.url;
|
||||||
instance = piped.instance || "";
|
|
||||||
contentType = audio.type?.split(";")[0] || "audio/mp4";
|
contentType = audio.type?.split(";")[0] || "audio/mp4";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -305,7 +304,6 @@ async function handler(req: Request): Promise<Response> {
|
|||||||
headers: {
|
headers: {
|
||||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
|
||||||
"Accept": "*/*",
|
"Accept": "*/*",
|
||||||
"Referer": instance || "https://www.youtube.com/",
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user