Show Suno queue progress and fix track numbering
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.8
|
// @version 0.7.9
|
||||||
// @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/*
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
(function () {
|
(function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const SCRIPT_VERSION = "0.7.8";
|
const SCRIPT_VERSION = "0.7.9";
|
||||||
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");
|
||||||
@@ -995,6 +995,7 @@
|
|||||||
async function prepareSunoWavCandidate(track) {
|
async function prepareSunoWavCandidate(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 billingDownloadUrl = `https://studio-api-prod.suno.com/api/billing/clips/${encodeURIComponent(track.id)}/download/`;
|
||||||
const cdnWavUrl = `https://cdn1.suno.ai/${encodeURIComponent(track.id)}.wav`;
|
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" });
|
||||||
@@ -1008,6 +1009,13 @@
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn("[ChatGPT to Suno] wav_file probe failed; local retry will continue", error);
|
console.warn("[ChatGPT to Suno] wav_file probe failed; local retry will continue", error);
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
const data = await callSunoJson(billingDownloadUrl, { method: "GET" });
|
||||||
|
const direct = extractWavUrl(data);
|
||||||
|
if (direct) return direct;
|
||||||
|
} catch (error) {
|
||||||
|
console.warn("[ChatGPT to Suno] billing download probe failed; local retry will continue", error);
|
||||||
|
}
|
||||||
return extractWavUrl(track.wavUrl) || cdnWavUrl;
|
return extractWavUrl(track.wavUrl) || cdnWavUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -395,7 +395,7 @@ foreach ($track in $tracks) {
|
|||||||
$trackFolder = Get-TrackFolder $libraryRoot $title $id
|
$trackFolder = Get-TrackFolder $libraryRoot $title $id
|
||||||
$safeTitle = ConvertTo-SafeName $title $id
|
$safeTitle = ConvertTo-SafeName $title $id
|
||||||
$shortId = Get-ShortId $id
|
$shortId = Get-ShortId $id
|
||||||
$trackNo = Get-NextTrackNumber $trackFolder
|
$trackNo = [int](Get-NextTrackNumber $trackFolder)
|
||||||
$prefix = "{0:D2} {1}" -f $trackNo, $safeTitle
|
$prefix = "{0:D2} {1}" -f $trackNo, $safeTitle
|
||||||
|
|
||||||
$lyrics = Get-DeepValue $track @("prompt", "lyrics", "lyric", "text")
|
$lyrics = Get-DeepValue $track @("prompt", "lyrics", "lyric", "text")
|
||||||
|
|||||||
+35
-1
@@ -15,6 +15,8 @@ New-Item -ItemType Directory -Force -Path $inbox, $logs | Out-Null
|
|||||||
$queue = [System.Collections.Queue]::new()
|
$queue = [System.Collections.Queue]::new()
|
||||||
$queueIds = [System.Collections.Generic.HashSet[string]]::new()
|
$queueIds = [System.Collections.Generic.HashSet[string]]::new()
|
||||||
$activeJob = $null
|
$activeJob = $null
|
||||||
|
$lastProgressAt = [DateTime]::MinValue
|
||||||
|
$lastProgressText = ""
|
||||||
|
|
||||||
function Resolve-LibraryRoot {
|
function Resolve-LibraryRoot {
|
||||||
param(
|
param(
|
||||||
@@ -135,6 +137,7 @@ function Start-SunoProcess {
|
|||||||
return [pscustomobject]@{
|
return [pscustomobject]@{
|
||||||
jobId = $jobId
|
jobId = $jobId
|
||||||
pid = $process.Id
|
pid = $process.Id
|
||||||
|
process = $process
|
||||||
log = $stdout
|
log = $stdout
|
||||||
errorLog = $stderr
|
errorLog = $stderr
|
||||||
}
|
}
|
||||||
@@ -153,10 +156,12 @@ function Save-Manifest {
|
|||||||
|
|
||||||
function Update-Queue {
|
function Update-Queue {
|
||||||
if ($script:activeJob -and -not $script:activeJob.Process.HasExited) {
|
if ($script:activeJob -and -not $script:activeJob.Process.HasExited) {
|
||||||
|
Publish-ActiveJobProgress
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($script:activeJob -and $script:activeJob.Process.HasExited) {
|
if ($script:activeJob -and $script:activeJob.Process.HasExited) {
|
||||||
|
Publish-ActiveJobProgress -Force
|
||||||
Write-Host "Finished job $($script:activeJob.JobId) exit=$($script:activeJob.Process.ExitCode)"
|
Write-Host "Finished job $($script:activeJob.JobId) exit=$($script:activeJob.Process.ExitCode)"
|
||||||
$script:activeJob = $null
|
$script:activeJob = $null
|
||||||
}
|
}
|
||||||
@@ -174,7 +179,7 @@ function Update-Queue {
|
|||||||
$job = Start-SunoProcess $manifestPath
|
$job = Start-SunoProcess $manifestPath
|
||||||
$script:activeJob = [pscustomobject]@{
|
$script:activeJob = [pscustomobject]@{
|
||||||
JobId = $job.jobId
|
JobId = $job.jobId
|
||||||
Process = Get-Process -Id $job.pid
|
Process = $job.process
|
||||||
TrackId = $item.Id
|
TrackId = $item.Id
|
||||||
Title = $item.Title
|
Title = $item.Title
|
||||||
Log = $job.log
|
Log = $job.log
|
||||||
@@ -184,6 +189,35 @@ function Update-Queue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Get-LastLogLine {
|
||||||
|
param([string[]]$Paths)
|
||||||
|
|
||||||
|
foreach ($path in $Paths) {
|
||||||
|
if (-not (Test-Path -LiteralPath $path)) { continue }
|
||||||
|
$line = Get-Content -LiteralPath $path -Tail 20 -ErrorAction SilentlyContinue |
|
||||||
|
Where-Object { "$_".Trim() } |
|
||||||
|
Select-Object -Last 1
|
||||||
|
if ($line) { return "$line" }
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
function Publish-ActiveJobProgress {
|
||||||
|
param([switch]$Force)
|
||||||
|
|
||||||
|
if (-not $script:activeJob) { return }
|
||||||
|
$now = Get-Date
|
||||||
|
if (-not $Force -and ($now - $script:lastProgressAt).TotalSeconds -lt 10) { return }
|
||||||
|
|
||||||
|
$line = Get-LastLogLine @($script:activeJob.ErrorLog, $script:activeJob.Log)
|
||||||
|
if (-not $line) { return }
|
||||||
|
if (-not $Force -and $line -eq $script:lastProgressText) { return }
|
||||||
|
|
||||||
|
$script:lastProgressAt = $now
|
||||||
|
$script:lastProgressText = $line
|
||||||
|
Write-Host "[$($script:activeJob.JobId)] $($script:activeJob.Title): $line"
|
||||||
|
}
|
||||||
|
|
||||||
function Add-TracksToQueue {
|
function Add-TracksToQueue {
|
||||||
param($Tracks, [string]$PageUrl)
|
param($Tracks, [string]$PageUrl)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user