refactor(music-lab): sync helpers → Windows HTTP forward + cleanup (SP-6)
/api/music/{lyrics, credits, timestamped-lyrics, style-boost}
모두 sync_forward 모듈로 위임 → Windows :18711/api/music-render/sync/*.
SUNO_API_KEY가 NAS에 없으므로 직접 호출 불가.
run_*, generate_*, get_* import 제거 (Windows로 이전됨).
SUNO_MODELS만 잔존 (정적 데이터).
추가 cleanup (T11 reviewer 지적):
- _push_render_job의 datetime import를 모듈 상위로
- 11 endpoint의 unused BackgroundTasks 매개변수 제거
generate_batch: SUNO_API_KEY 체크를 os.getenv()로 전환 + 테스트 monkeypatch 갱신.
Plan-B-Music Phase 3 (cutover 2/4).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
76
music-lab/app/sync_forward.py
Normal file
76
music-lab/app/sync_forward.py
Normal file
@@ -0,0 +1,76 @@
|
||||
"""SP-6 sync helpers forward — NAS → Windows music-render.
|
||||
|
||||
NAS music-lab의 /api/music/lyrics, /api/music/credits,
|
||||
/api/music/timestamped-lyrics, /api/music/style-boost 호출을
|
||||
Windows music-render의 /api/music-render/sync/* 로 forward.
|
||||
|
||||
SUNO_API_KEY는 NAS에 없으므로 NAS에서 직접 호출 불가.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import os
|
||||
from typing import Optional
|
||||
|
||||
import httpx
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
MUSIC_RENDER_URL = os.getenv("MUSIC_RENDER_URL", "http://192.168.45.59:18711")
|
||||
_TIMEOUT = 60.0 # 가사 생성은 폴링 포함 ~45초
|
||||
|
||||
|
||||
def forward_lyrics(prompt: str) -> Optional[dict]:
|
||||
try:
|
||||
r = httpx.post(
|
||||
f"{MUSIC_RENDER_URL}/api/music-render/sync/lyrics",
|
||||
json={"prompt": prompt},
|
||||
timeout=_TIMEOUT,
|
||||
)
|
||||
if r.status_code == 200:
|
||||
return r.json()
|
||||
logger.warning("forward_lyrics returned %d", r.status_code)
|
||||
except Exception:
|
||||
logger.exception("forward_lyrics 실패")
|
||||
return None
|
||||
|
||||
|
||||
def forward_credits() -> Optional[dict]:
|
||||
try:
|
||||
r = httpx.get(
|
||||
f"{MUSIC_RENDER_URL}/api/music-render/sync/credits",
|
||||
timeout=30.0,
|
||||
)
|
||||
if r.status_code == 200:
|
||||
return r.json()
|
||||
except Exception:
|
||||
logger.exception("forward_credits 실패")
|
||||
return None
|
||||
|
||||
|
||||
def forward_timestamped_lyrics(task_id: str, suno_id: str) -> Optional[dict]:
|
||||
try:
|
||||
r = httpx.get(
|
||||
f"{MUSIC_RENDER_URL}/api/music-render/sync/timestamped-lyrics",
|
||||
params={"task_id": task_id, "suno_id": suno_id},
|
||||
timeout=30.0,
|
||||
)
|
||||
if r.status_code == 200:
|
||||
return r.json()
|
||||
except Exception:
|
||||
logger.exception("forward_timestamped_lyrics 실패")
|
||||
return None
|
||||
|
||||
|
||||
def forward_style_boost(content: str) -> Optional[dict]:
|
||||
try:
|
||||
r = httpx.post(
|
||||
f"{MUSIC_RENDER_URL}/api/music-render/sync/style-boost",
|
||||
json={"content": content},
|
||||
timeout=30.0,
|
||||
)
|
||||
if r.status_code == 200:
|
||||
return r.json()
|
||||
except Exception:
|
||||
logger.exception("forward_style_boost 실패")
|
||||
return None
|
||||
Reference in New Issue
Block a user