-- 检查歌曲库中的音频文件 URL
-- 查找可能有问题的歌曲记录

-- 1. 查看所有歌曲的音频 URL
SELECT 
    id,
    title,
    audio_url,
    status,
    gender,
    duration_sec,
    createtime
FROM nf_song_library
WHERE deletetime IS NULL
ORDER BY id DESC
LIMIT 20;

-- 2. 查找最近失败的任务相关的歌曲
SELECT 
    gt.id as task_id,
    gt.status as task_status,
    gt.payload,
    gt.error_message,
    sl.id as song_id,
    sl.title as song_title,
    sl.audio_url,
    gt.created_at
FROM nf_generation_task gt
LEFT JOIN nf_song_library sl ON JSON_EXTRACT(gt.payload, '$.song_id') = sl.id
WHERE gt.task_type = 'sing'
  AND gt.status = 'failed'
ORDER BY gt.created_at DESC
LIMIT 10;

-- 3. 统计有问题的 URL 模式
SELECT 
    SUBSTRING_INDEX(audio_url, '/', 5) as url_prefix,
    COUNT(*) as count
FROM nf_song_library
WHERE deletetime IS NULL
  AND status = 1
GROUP BY url_prefix;
