Probe Suno CDN WAV before enqueue
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name ChatGPT to Suno Prompt Copier
|
// @name ChatGPT to Suno Prompt Copier
|
||||||
// @namespace local.suno-helper
|
// @namespace local.suno-helper
|
||||||
// @version 0.7.5
|
// @version 0.7.6
|
||||||
// @description Copy structured ChatGPT song prompt versions into Suno fields.
|
// @description Copy structured ChatGPT song prompt versions into Suno fields.
|
||||||
// @author local
|
// @author local
|
||||||
// @match https://chatgpt.com/*
|
// @match https://chatgpt.com/*
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
(function () {
|
(function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const SCRIPT_VERSION = "0.7.5";
|
const SCRIPT_VERSION = "0.7.6";
|
||||||
const STORAGE_KEY = "chatgptSunoPromptSlots";
|
const STORAGE_KEY = "chatgptSunoPromptSlots";
|
||||||
const SLOT_COUNT = 2;
|
const SLOT_COUNT = 2;
|
||||||
const isChatGPT = location.hostname.includes("chatgpt.com") || location.hostname.includes("chat.openai.com");
|
const isChatGPT = location.hostname.includes("chatgpt.com") || location.hostname.includes("chat.openai.com");
|
||||||
@@ -882,9 +882,32 @@
|
|||||||
return "";
|
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) {
|
async function requestSunoWavUrl(track) {
|
||||||
if (!track.id) return extractWavUrl(track.wavUrl);
|
if (!track.id) return extractWavUrl(track.wavUrl);
|
||||||
const base = `https://studio-api-prod.suno.com/api/gen/${encodeURIComponent(track.id)}`;
|
const base = `https://studio-api-prod.suno.com/api/gen/${encodeURIComponent(track.id)}`;
|
||||||
|
const cdnWavUrl = `https://cdn1.suno.ai/${encodeURIComponent(track.id)}.wav`;
|
||||||
try {
|
try {
|
||||||
await callSunoJson(`${base}/convert_wav/`, { method: "POST" });
|
await callSunoJson(`${base}/convert_wav/`, { method: "POST" });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -896,13 +919,15 @@
|
|||||||
const data = await callSunoJson(`${base}/wav_file/`, { method: "GET" });
|
const data = await callSunoJson(`${base}/wav_file/`, { method: "GET" });
|
||||||
const direct = extractWavUrl(data);
|
const direct = extractWavUrl(data);
|
||||||
if (direct) return direct;
|
if (direct) return direct;
|
||||||
|
if (await canReadUrl(cdnWavUrl)) return cdnWavUrl;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn("[ChatGPT to Suno] wav_file failed", error);
|
console.warn("[ChatGPT to Suno] wav_file failed", error);
|
||||||
|
if (await canReadUrl(cdnWavUrl)) return cdnWavUrl;
|
||||||
}
|
}
|
||||||
await new Promise((resolve) => setTimeout(resolve, 1500));
|
await new Promise((resolve) => setTimeout(resolve, 1500));
|
||||||
}
|
}
|
||||||
|
|
||||||
return extractWavUrl(track.wavUrl);
|
return extractWavUrl(track.wavUrl) || ((await canReadUrl(cdnWavUrl)) ? cdnWavUrl : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
function downloadTextFile(text, name) {
|
function downloadTextFile(text, name) {
|
||||||
|
|||||||
Reference in New Issue
Block a user