Probe Suno CDN WAV before enqueue

This commit is contained in:
DESKTOP-KSVGT20\shkim
2026-05-02 00:24:27 +09:00
parent fa2c9e8b2d
commit 73cd8cea8f
+28 -3
View File
@@ -1,7 +1,7 @@
// ==UserScript==
// @name ChatGPT to Suno Prompt Copier
// @namespace local.suno-helper
// @version 0.7.5
// @version 0.7.6
// @description Copy structured ChatGPT song prompt versions into Suno fields.
// @author local
// @match https://chatgpt.com/*
@@ -27,7 +27,7 @@
(function () {
"use strict";
const SCRIPT_VERSION = "0.7.5";
const SCRIPT_VERSION = "0.7.6";
const STORAGE_KEY = "chatgptSunoPromptSlots";
const SLOT_COUNT = 2;
const isChatGPT = location.hostname.includes("chatgpt.com") || location.hostname.includes("chat.openai.com");
@@ -882,9 +882,32 @@
return "";
}
async function canReadUrl(url) {
if (!url) return false;
const page = typeof unsafeWindow !== "undefined" ? unsafeWindow : window;
const methods = [
{ method: "HEAD" },
{ method: "GET", headers: { range: "bytes=0-0" } },
];
for (const options of methods) {
try {
const response = await page.fetch(url, {
credentials: "include",
cache: "no-store",
...options,
});
if (response.ok) return true;
} catch (error) {
console.warn("[ChatGPT to Suno] URL probe failed", url, error);
}
}
return false;
}
async function requestSunoWavUrl(track) {
if (!track.id) return extractWavUrl(track.wavUrl);
const base = `https://studio-api-prod.suno.com/api/gen/${encodeURIComponent(track.id)}`;
const cdnWavUrl = `https://cdn1.suno.ai/${encodeURIComponent(track.id)}.wav`;
try {
await callSunoJson(`${base}/convert_wav/`, { method: "POST" });
} catch (error) {
@@ -896,13 +919,15 @@
const data = await callSunoJson(`${base}/wav_file/`, { method: "GET" });
const direct = extractWavUrl(data);
if (direct) return direct;
if (await canReadUrl(cdnWavUrl)) return cdnWavUrl;
} catch (error) {
console.warn("[ChatGPT to Suno] wav_file failed", error);
if (await canReadUrl(cdnWavUrl)) return cdnWavUrl;
}
await new Promise((resolve) => setTimeout(resolve, 1500));
}
return extractWavUrl(track.wavUrl);
return extractWavUrl(track.wavUrl) || ((await canReadUrl(cdnWavUrl)) ? cdnWavUrl : "");
}
function downloadTextFile(text, name) {