From 83f7310d53a6d44f5ff1ebd0895b3998508ab2a7 Mon Sep 17 00:00:00 2001 From: tkrmagid Date: Fri, 11 Sep 2026 15:33:28 +0900 Subject: [PATCH] =?UTF-8?q?fix(YoutubeMusic):=20=EA=B2=80=EC=83=89=200?= =?UTF-8?q?=EA=B1=B4=20=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95=20-=20?= =?UTF-8?q?=EB=A7=8C=EB=A3=8C=EB=90=9C=20=EA=B3=A0=EC=A0=95=20params=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0=20+=20itemSectionRenderer=20=EA=B2=B0?= =?UTF-8?q?=EA=B3=BC=20=ED=8C=8C=EC=8B=B1=20+=20=EC=BB=A4=EB=B2=84/MR/?= =?UTF-8?q?=EB=85=B8=EB=9E=98=EB=B0=A9=20=ED=9B=84=EC=88=9C=EC=9C=84=20?= =?UTF-8?q?=EC=A0=95=EB=A0=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot/src/utils/api/YoutubeMusic.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/bot/src/utils/api/YoutubeMusic.ts b/bot/src/utils/api/YoutubeMusic.ts index f21cd7d..54e52a3 100644 --- a/bot/src/utils/api/YoutubeMusic.ts +++ b/bot/src/utils/api/YoutubeMusic.ts @@ -107,8 +107,9 @@ export const YoutubeMusic = { gl: "KR" } }, - query: query, - params: "EgWKAQIIAWoOEAMQBBAQEAkQFRAKEBE=" + query: query + // NOTE: 과거의 고정 params("EgW...")는 YTM에서 "검색결과 없음"을 유발하므로 제거. + // 필터 없이 요청하면 상단 Top Result(musicCardShelfRenderer) + 곡 목록이 함께 온다. }), ...(proxy ? { dispatcher: proxy } : {}) }); @@ -157,9 +158,9 @@ export const YoutubeMusic = { } } - // 2. 일반 검색 결과 목록 파싱 - if (section.musicShelfRenderer) { - const items = section.musicShelfRenderer.contents || []; + // 2. 일반 검색 결과 목록 파싱 (곡은 musicShelfRenderer 또는 itemSectionRenderer 하위에 위치) + { + const items = section.musicShelfRenderer?.contents ?? section.itemSectionRenderer?.contents ?? []; for (const item of items) { const track = item.musicResponsiveListItemRenderer; @@ -201,7 +202,12 @@ export const YoutubeMusic = { } } - return results; + // YTM이 필터 없는 검색에서 커버/MR/노래방/라이브를 상위로 올리는 경우가 있어, + // 명백한 2차 창작물은 뒤로 보낸다(원곡 우선). 동점이면 원래 순서 유지(안정 정렬). + const junk = /(\bMR\b|inst(?:rumental)?|instrumental|karaoke|노래방|\bcover\b|커버|nightcore|sped ?up|slowed|8d audio|리믹스|remix|male version|남자\s?버전|여자\s?버전|가사|lyrics?)/i; + const scored = results.map((r, i) => ({ r, i, junk: junk.test(r.title) ? 1 : 0 })); + scored.sort((a, b) => a.junk - b.junk || a.i - b.i); + return scored.map((s) => s.r); } catch (error) { Logger.error(`❌ getSearchFull 실행 중 에러: ${String(error)}`); return [];