오늘의 응원가 자동 생성 파이프라인 (Suno)

- 경기 맥락(전날 결과·순위·연전 차수·선발투수) 조립 → LLM 작사
  (콜앤리스폰스·섹션 태그 형식) → Suno(sunoapi.org) 생성 → songs 테이블
- 워커: 킥오프 150분 전 윈도우 진입 시 생성 시작 + 2분 주기 폴링
- API: GET /api/songs/today · POST /api/songs/callback(싱크대)
  · POST /api/songs/generate(관리자 강제 생성)
- 프론트: MusicBar 가 경기 상세·메인에서 오늘의 응원가를 동적 로드
  (정적 플레이리스트는 폴백 유지)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
JinwooKimandClaude Fable 5 committed 2026-08-25 09:33:34 +09:00
1 parent 2a8f2bc1fa
commit 277378477a
11 files changed
+706 -7

No files matched your search

+14 -7
View File
@@ -1,9 +1,9 @@
import { useEffect } from "react";
import { useEffect, useState } from "react";
import { useLocation } from "react-router-dom";
import { usePlayer } from "@/lib/usePlayer";
import { useLang } from "@/lib/useLang";
import { dict } from "@/lib/i18n";
import { getTracksForPath } from "@/lib/playlist";
import { getTracksForPathAsync, type Track } from "@/lib/playlist";
// ---------------------------------------------------------------------------
// 시간 포맷
@@ -145,14 +145,21 @@ export default function MusicBar() {
loadPlaylist,
} = usePlayer();
// 경로가 바뀌면 해당 경로의 플레이리스트 로드, 없으면 초기화
// 경로가 바뀌면 해당 경로의 플레이리스트 로드 (오늘의 응원가 API 포함), 없으면 초기화
const [tracks, setTracks] = useState<Track[]>([]);
useEffect(() => {
loadPlaylist(getTracksForPath(pathname));
let alive = true;
getTracksForPathAsync(pathname).then((ts) => {
if (!alive) return;
setTracks(ts);
loadPlaylist(ts);
});
return () => {
alive = false;
};
}, [pathname, loadPlaylist]);
if (!hasTrack) return null;
if (getTracksForPath(pathname).length === 0) return null;
if (!hasTrack || tracks.length === 0) return null;
const handleProgressClick = (e: React.MouseEvent<HTMLDivElement>) => {
const rect = e.currentTarget.getBoundingClientRect();
+21
View File
@@ -43,6 +43,27 @@ export class ApiError extends Error {
}
}
// ── 오늘의 응원가 ────────────────────────────────────────────
export interface SongTrackOut {
title: string;
audioUrl: string;
imageUrl?: string;
duration?: number;
}
export interface SongOut {
matchId: string;
league: string;
teamCode: string;
teamName: string;
title: string;
lyrics?: string;
tracks: SongTrackOut[];
}
export function getTodaySongs(league = "kbo"): Promise<SongOut[]> {
return http<SongOut[]>(`/songs/today?league=${league}`);
}
export function listMatches(lang: Lang, league = ""): Promise<Match[]> {
return http<Match[]>(`/matches?lang=${lang}${league ? `&league=${league}` : ""}`);
}
+44
View File
@@ -43,3 +43,47 @@ export function getTracksForPath(pathname: string): Track[] {
if (/^\/match\/KBO_(OB_[A-Z]+|[A-Z]+_OB)_\d{8}$/.test(pathname)) return DOOSAN_TRACKS;
return [];
}
// ── 오늘의 응원가 (백엔드 Suno 자동 생성) ─────────────────────
// 하루 단위 캐시 — 같은 세션에서 경로 이동마다 재요청하지 않는다.
import { getTodaySongs, type SongOut } from "./api";
let songsPromise: Promise<SongOut[]> | null = null;
let songsDay = "";
function todayKstKey(): string {
return new Date(Date.now() + 9 * 3600_000).toISOString().slice(0, 10);
}
function fetchSongsCached(): Promise<SongOut[]> {
const day = todayKstKey();
if (!songsPromise || songsDay !== day) {
songsDay = day;
songsPromise = getTodaySongs("kbo").catch(() => []);
}
return songsPromise;
}
function songToTracks(s: SongOut): Track[] {
const base = s.title || `${s.teamName} 응원가`;
return (s.tracks || [])
.filter((t) => t.audioUrl)
.map((t, i) => ({
title: s.tracks.length > 1 ? `${base} #${i + 1}` : base,
artist: `오늘의 ${s.teamName} 응원가`,
src: t.audioUrl,
cover: t.imageUrl,
}));
}
// 경로 → 트랙 목록 (동적 응원가 포함). 경기 상세는 그 경기 두 팀의 곡,
// 메인("/")은 오늘 전 경기 곡. 동적 곡이 없으면 기존 정적 목록 그대로.
export async function getTracksForPathAsync(pathname: string): Promise<Track[]> {
const staticTracks = getTracksForPath(pathname);
const m = pathname.match(/^\/match\/(KBO_.+)$/);
if (!m && pathname !== "/") return staticTracks;
const songs = await fetchSongsCached();
const picked = m ? songs.filter((s) => s.matchId === m[1]) : songs;
const dyn = picked.flatMap(songToTracks);
return dyn.length ? [...dyn, ...staticTracks] : staticTracks;
}