Batch upload Suno MP3s with metadata
This commit is contained in:
+34
-14
@@ -402,7 +402,17 @@ foreach ($track in $tracks) {
|
||||
$style = Get-DeepValue $track @("gpt_description_prompt", "style", "tags", "description")
|
||||
$model = Get-DeepValue $track @("model_name", "model", "major_model_version")
|
||||
$createdAt = Get-DeepValue $track @("created_at", "createdAt")
|
||||
$localAudioPath = Get-DeepValue $track @("localAudioPath", "local_audio_path", "uploadedAudioPath")
|
||||
$localAudioExt = Get-DeepValue $track @("localAudioExt", "local_audio_ext", "audioExt")
|
||||
$localWavPath = Get-DeepValue $track @("localWavPath", "local_wav_path", "uploadedWavPath")
|
||||
if (-not $localAudioPath -and $localWavPath) {
|
||||
$localAudioPath = $localWavPath
|
||||
$localAudioExt = "wav"
|
||||
}
|
||||
if (-not $localAudioExt -and $localAudioPath) {
|
||||
$localAudioExt = [IO.Path]::GetExtension($localAudioPath).TrimStart(".").ToLowerInvariant()
|
||||
}
|
||||
$outputExt = if ($localAudioExt -eq "mp3") { "mp3" } else { "flac" }
|
||||
|
||||
$wavUrl = Resolve-SunoMediaUrl $(if ($track.wavUrl) { "$($track.wavUrl)" } else { Get-DeepValue $track @("wav_url", "wavUrl", "download_url", "downloadUrl") })
|
||||
$wavCandidates = @()
|
||||
@@ -410,26 +420,27 @@ foreach ($track in $tracks) {
|
||||
$wavCandidates = $wavCandidates | Where-Object { $_ } | Select-Object -Unique
|
||||
$imageUrl = if ($track.imageUrl) { "$($track.imageUrl)" } else { Get-DeepValue $track @("image_url", "imageUrl", "image_large_url", "cover_url") }
|
||||
|
||||
$inputAudio = Join-Path $workRoot "$prefix.input.wav"
|
||||
$inputExt = if ($localAudioExt) { $localAudioExt } else { "wav" }
|
||||
$inputAudio = Join-Path $workRoot "$prefix.input.$inputExt"
|
||||
$rawCoverFile = Join-Path $workRoot "$prefix.cover.$(Get-UrlExtension $imageUrl 'jpg')"
|
||||
$trackCoverFile = Join-Path $workRoot "$prefix.embed-cover.jpg"
|
||||
$coverFile = Join-Path $trackFolder "cover.jpg"
|
||||
$metadataFile = Join-Path $trackFolder ("metadata.{0}.json" -f $shortId)
|
||||
$lyricsFile = Join-Path $trackFolder ("{0}.lrc" -f $prefix)
|
||||
$flacFile = Join-Path $trackFolder ("{0}.flac" -f $prefix)
|
||||
$outputFile = Join-Path $trackFolder ("{0}.{1}" -f $prefix, $outputExt)
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "[$index/$($tracks.Count)] $title"
|
||||
|
||||
if (-not $localWavPath -and -not $wavCandidates.Count) {
|
||||
Write-Warning "WAV URL이 없어서 건너뜀: $title"
|
||||
if (-not $localAudioPath -and -not $wavCandidates.Count) {
|
||||
Write-Warning "오디오 입력이 없어서 건너뜀: $title"
|
||||
continue
|
||||
}
|
||||
|
||||
$audioOk = $false
|
||||
if ($localWavPath -and (Test-Path -LiteralPath $localWavPath)) {
|
||||
Write-Host "업로드된 WAV 사용: $localWavPath"
|
||||
Copy-Item -LiteralPath $localWavPath -Destination $inputAudio -Force
|
||||
if ($localAudioPath -and (Test-Path -LiteralPath $localAudioPath)) {
|
||||
Write-Host "업로드된 오디오 사용: $localAudioPath"
|
||||
Copy-Item -LiteralPath $localAudioPath -Destination $inputAudio -Force
|
||||
$audioOk = (Test-Path -LiteralPath $inputAudio) -and ((Get-Item -LiteralPath $inputAudio).Length -gt 0)
|
||||
} else {
|
||||
$audioOk = Invoke-DownloadWithRetry $wavCandidates $inputAudio $WavRetrySeconds $WavRetryIntervalSeconds
|
||||
@@ -481,10 +492,19 @@ foreach ($track in $tracks) {
|
||||
$argsList.Add("-metadata:s:v")
|
||||
$argsList.Add("comment=Cover (front)")
|
||||
}
|
||||
$argsList.Add("-c:a")
|
||||
$argsList.Add("flac")
|
||||
$argsList.Add("-compression_level")
|
||||
$argsList.Add("8")
|
||||
if ($outputExt -eq "mp3") {
|
||||
$argsList.Add("-c:a")
|
||||
$argsList.Add("copy")
|
||||
$argsList.Add("-id3v2_version")
|
||||
$argsList.Add("3")
|
||||
$argsList.Add("-write_id3v1")
|
||||
$argsList.Add("1")
|
||||
} else {
|
||||
$argsList.Add("-c:a")
|
||||
$argsList.Add("flac")
|
||||
$argsList.Add("-compression_level")
|
||||
$argsList.Add("8")
|
||||
}
|
||||
Add-MetadataArg $argsList "TITLE" $title
|
||||
Add-MetadataArg $argsList "ARTIST" $ArtistName
|
||||
Add-MetadataArg $argsList "ALBUM" $albumTitle
|
||||
@@ -501,15 +521,15 @@ foreach ($track in $tracks) {
|
||||
Add-MetadataArg $argsList "SUNO_MODEL" $model
|
||||
Add-MetadataArg $argsList "SUNO_CLIP_ID" $id
|
||||
Add-MetadataArg $argsList "TMED" "Digital Media"
|
||||
$argsList.Add($flacFile)
|
||||
$argsList.Add($outputFile)
|
||||
|
||||
& $ffmpeg @argsList
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Warning "FLAC 변환 실패: $title"
|
||||
Write-Warning "오디오 후처리 실패: $title"
|
||||
continue
|
||||
}
|
||||
|
||||
Write-Host "완료: $flacFile"
|
||||
Write-Host "완료: $outputFile"
|
||||
Write-AlbumNfo $trackFolder $albumTitle $ArtistName $style $ffprobe
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user