fix(play): 스포티파이 트랙은 유튜브뮤직 오디오로 재생(뮤비 폴백 방지)

문제: 대시보드에서 스포티파이 곡을 고르면 track.url(open.spotify.com/track/..)을
Lavalink가 그대로 resolve → 유튜브 '영상(뮤비)'으로 폴백 재생됨.

수정: LavalinkManager.search에서 스포티파이 트랙 URL을 감지하면 메타데이터
(제목+아티스트)를 조회해 YoutubeMusic.getSearchUrl ?? `ytsearch:.. Topic` 오디오
검색으로 대체. 직접 입력/대시보드/`-p` 모든 경로에 적용. youtube 등 타 URL은 무영향.

- Spotify.parseTrackId / Spotify.getTrackById 추가.
- 검증: tsc 통과, Spotify /tracks/{id} 메타데이터 조회 정상, 파싱 정상.
This commit is contained in:
2026-09-13 02:21:20 +09:00
parent f5778a7763
commit 1bb1d10b25
2 changed files with 41 additions and 0 deletions

View File

@@ -126,5 +126,35 @@ export const Spotify = {
const track = (await this.getSearchFull(query) ?? [])?.[0];
if (track?.url) searchCache.set(lowerQuery, track.url);
return track?.url ?? null;
},
/** open.spotify.com/track/<id> 또는 spotify:track:<id> 에서 트랙 id를 추출. 아니면 null. */
parseTrackId(text: string): string | null {
const m = text.trim().match(/(?:open\.spotify\.com\/track\/|spotify:track:)([A-Za-z0-9]+)/);
return m ? m[1] : null;
},
/** 트랙 id로 제목/아티스트 메타데이터 조회 (유튜브뮤직 오디오 검색어 생성용). */
async getTrackById(id: string): Promise<{ title: string; artist: string } | null> {
try {
const token = await this.getToken();
if (!token) return null;
const response = await fetch(`${SPOTIFY_API_URL}/tracks/${encodeURIComponent(id)}?market=KR`, {
headers: { Authorization: `Bearer ${token}` },
});
if (!response.ok) {
Logger.error(`스포티파이 트랙 조회 에러 (${response.status})`);
return null;
}
const track = await response.json() as SpotifyApi.TrackObjectFull;
if (!track?.name) return null;
return {
title: track.name,
artist: (track.artists ?? []).map((a) => a.name).join(", "),
};
} catch (err) {
Logger.error(`스포티파이 트랙 조회 실패: ${err}`);
return null;
}
}
}