이지선다 조회수 자동: 유튜브 뮤직 응답에 링크한 영상이 아예 없으면(빈 응답·형식 변경) 짝을 모르는 것이므로 '토픽 없음'으로 확정하지 않고 실패로 둠 — 그 영상 조회수만 done으로 저장하던 것. 회귀 테스트

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-11-03 21:10:13 +09:00
parent aacc4133b5
commit cee550f063
2 changed files with 7 additions and 1 deletions

View File

@@ -68,6 +68,10 @@ test('fetchDuelViews: either half may be linked; a song with one half keeps that
expect(mvOnly).toMatchObject({ topicId: null, mvId: 'onlyMV00001', mvViews: 20 });
// any other upload without a 토픽 pair: that video's views
expect(await fetchDuelViews('fanUpload01', src, 1)).toMatchObject({ topicId: null, mvId: 'fanUpload01', mvViews: 7 });
// signed in but the video is not in the answer (empty or changed response): unknown, not "토픽 없음"
const empty = { ...src, songPair: async () => parseSongPair(watch([]), 'lilacMV0001') };
await expect(fetchDuelViews('lilacMV0001', empty, 1)).rejects.toThrow('곡 정보를 찾지 못했어요');
expect(src.calls.filter((c) => c === 'views lilacMV0001')).toHaveLength(2);
// 비고
const it = (viewsAuto: DuelViews | null, views: number | null = 1, fromFile = true) => duelViewsNote({ views, viewsAuto, fromFile });
expect(it(both as DuelViews)).toBeNull();
@@ -84,7 +88,7 @@ test('youtubeViewCount: the player count, else the watch page count, else an err
expect(await youtubeViewCount('v7bnOxV4jAc', fake({ videoDetails: { videoId: 'v7bnOxV4jAc', viewCount: '120456684' } }, ''))).toBe(120456684);
const page = '{"videoViewCountRenderer":{"viewCount":{"simpleText":"조회수 120,456,684회"}}}';
expect(await youtubeViewCount('v7bnOxV4jAc', fake({ playabilityStatus: { status: 'LOGIN_REQUIRED' } }, page))).toBe(120456684);
expect(youtubeViewCount('v7bnOxV4jAc', fake({}, '{}'))).rejects.toThrow('조회수를 찾지 못했어요');
await expect(youtubeViewCount('v7bnOxV4jAc', fake({}, '{}'))).rejects.toThrow('조회수를 찾지 못했어요');
});
// ------------------------------------------------------------------ upload → fetch → editor

View File

@@ -20,6 +20,8 @@ const UA = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Geck
/** The linked video may be either half: a 토픽 pairs with its MV, anything else (MV, other upload) with its 토픽. */
export async function fetchDuelViews(videoId: string, src: ViewsSource, now = Date.now()): Promise<DuelViews> {
const pair = await src.songPair(videoId);
// the video is not in the answer at all: nothing is known about its pair, so this is no "토픽 없음"
if (!pair.type) throw new Error('유튜브 뮤직에서 이 영상의 곡 정보를 찾지 못했어요');
const selfTopic = pair.type === TOPIC;
const topicId = selfTopic ? videoId : pair.other?.type === TOPIC ? pair.other.videoId : null;
const mvId = !selfTopic ? videoId : pair.other && pair.other.type !== TOPIC ? pair.other.videoId : null;