연령제한 곡 재생: 유튜브가 퍼가기 플레이어에서 막는(오류 150) 연령제한 영상은 서버가 성인 인증된 계정 쿠키로 소리만 받아 두고(/data/audio, yt-dlp) 게임은 그 파일을 숨긴 <audio>로 재생. 찾기는 소리 크기·하이라이트 수집(로그인 없는 페이지의 성인 인증 화면) + 게임 중 오류 시 age-audio 작업이 다시 확인해 되돌림. 받기 전에는 출제 안 함. prepare·catchup에 videoId 대신 문제마다 새 무작위 주소(/api/audio/<토큰>, Range 지원)라 영상 id가 안 보임. 같은 시각 시작·위치 정지·새로고침 이어 듣기·소리 크기(유튜브 -14 보정 없이) 그대로. 관리자 수집 화면·cli age-audio, Dockerfile에 yt-dlp(버전·체크섬 고정), 수집 CLI가 서버 DB 경로를 물려받게(테스트가 기본 DB를 건드리던 것). 실제 크롬 e2e로 받은 음원+유튜브 곡 섞어 재생 확인
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,10 +5,13 @@
|
||||
* everyone, skip / hint / replay votes with Ctrl+K / Ctrl+I / Ctrl+R, a broken video swapped, typing indicator,
|
||||
* reconnect mid-game, refresh while the music runs (catch up in sync), results with YouTube links, 이어풀기, 다시 하기, phone / dark screens, the last one out closes the room.
|
||||
* Part B plays real YouTube Topic videos in two browsers: sound on after the entry click, same start, 3s clip stop.
|
||||
* Its 연령제한 step plays a downloaded age-restricted song (our <audio>) next to a YouTube one, when E2E_AGE_AUDIO points
|
||||
* to that m4a (yt-dlp with the adult cookie: 6kLq3WMV1nU, docs/08 §2-1).
|
||||
* Run: bun run build && bun e2e/game.e2e.ts (needs /usr/bin/google-chrome; Part B needs internet, skip with E2E_NO_YT=1)
|
||||
*/
|
||||
import { chromium, type Browser, type Page } from 'playwright-core';
|
||||
import { mkdirSync, mkdtempSync } from 'node:fs';
|
||||
import { copyFileSync, existsSync, mkdirSync, mkdtempSync } from 'node:fs';
|
||||
import { audioDir, audioFile } from '../apps/server/src/songs/audio';
|
||||
import { join } from 'node:path';
|
||||
import { loadConfig } from '../apps/server/src/config';
|
||||
import { startServer } from '../apps/server/src/server';
|
||||
@@ -56,6 +59,23 @@ const db = app.db;
|
||||
db.query("UPDATE songs SET youtube_status = 'matched', embeddable = 1, youtube_id = ?, duration_sec = ?, loudness_lufs = ?, loudness_video = ? WHERE id = ?").run(vid, dur, lufs, lufs === null ? null : vid, id!);
|
||||
}
|
||||
}
|
||||
// 연령제한: a real age-restricted video whose audio was downloaded, next to a YouTube one (level 8)
|
||||
const AGE_AUDIO = process.env.E2E_AGE_AUDIO ?? '';
|
||||
if (AGE_AUDIO && existsSync(AGE_AUDIO)) {
|
||||
const c = new Catalog(db);
|
||||
const songs: [string, string, string, number, boolean][] = [
|
||||
['연령제한노래', '어른가수', '6kLq3WMV1nU', 246, true],
|
||||
['Love wins all', '아이유', 'Wu5FY8J6P8Q', 272, false],
|
||||
];
|
||||
for (const [title, artist, vid, dur, age] of songs) {
|
||||
const [id] = c.upsert({ title, artists: [{ name: artist }], year: 2000, genres: ['kpop'], source: 'e2e', ref: vid });
|
||||
c.autoLevel(id!, 'all', 8);
|
||||
db.query("UPDATE songs SET youtube_status = 'matched', embeddable = 1, youtube_id = ?, duration_sec = ?, loudness_lufs = -14.17, loudness_video = youtube_id WHERE id = ?").run(vid, dur, id!);
|
||||
if (age) db.query('UPDATE songs SET age_video = youtube_id, audio_video = youtube_id WHERE id = ?').run(id!);
|
||||
}
|
||||
mkdirSync(audioDir(config.dbPath), { recursive: true });
|
||||
copyFileSync(AGE_AUDIO, audioFile(audioDir(config.dbPath), '6kLq3WMV1nU'));
|
||||
}
|
||||
const titleOf = (vid: string) => db.query<{ title: string; artist: string }, [string]>('SELECT title, artist FROM songs WHERE youtube_id = ?').get(vid)!;
|
||||
|
||||
const browser: Browser = await chromium.launch({
|
||||
@@ -439,6 +459,52 @@ try {
|
||||
await x.context().close();
|
||||
await y.context().close();
|
||||
});
|
||||
|
||||
if (AGE_AUDIO) await step('B: 연령제한 곡 — 받아 둔 음원(<audio>)과 유튜브 곡이 섞여도 같은 순간 재생·클립 정지, 음원 중 새로고침해도 같은 위치', async () => {
|
||||
const x = await guestPage('어른방장', { fake: false });
|
||||
const y = await guestPage('어른손님', { fake: false });
|
||||
const rc = await makeRoom(x, { count: 10, level: 8, listenSec: 10, startAt: 'start' });
|
||||
await y.goto(`${ORIGIN}/r/${rc}`);
|
||||
await y.locator('.pool-banner').waitFor();
|
||||
for (const p of [x, y]) await p.getByRole('button', { name: '참가 (소리 켜기)' }).click();
|
||||
await x.getByText('조건에 맞는 곡 2곡').waitFor({ timeout: 5000 });
|
||||
await x.getByRole('button', { name: '게임 시작' }).click();
|
||||
await x.getByRole('button', { name: '그대로 시작' }).click();
|
||||
const kinds: string[] = [];
|
||||
for (const n of [1, 2]) {
|
||||
await Promise.all([x, y].map((p) => playing(p, n, 40000)));
|
||||
await x.waitForTimeout(1200);
|
||||
const src = (await video(x))!;
|
||||
const file = src.startsWith('/api/audio/');
|
||||
kinds.push(file ? 'file' : 'youtube');
|
||||
expect(file || src === 'Wu5FY8J6P8Q', `소스 ${src}`);
|
||||
if (file) {
|
||||
// the address says nothing about the video
|
||||
expect(!src.includes('6kLq3WMV1nU'), '주소에 영상 id');
|
||||
await y.reload();
|
||||
await y.getByRole('button', { name: '🔊 참가 (소리 켜기)' }).click({ timeout: 30000 });
|
||||
await y.locator('.stage .lp.spin').waitFor({ timeout: 15000 });
|
||||
await y.waitForTimeout(800);
|
||||
}
|
||||
const st = await Promise.all([x, y].map((p) => p.evaluate(() => ({ pos: (window as any).mqPlayer.pos(), muted: (window as any).mqPlayer.muted(), state: (window as any).mqPlayer.state(), v: (window as any).mqPlayer.video() }))));
|
||||
console.log(` ${n}번 ${file ? '받은 음원' : '유튜브'}${file ? '(손님 새로고침 뒤)' : ''} 위치 ${st.map((s) => s.pos.toFixed(3)).join(' / ')}`);
|
||||
expect(st[0]!.v === st[1]!.v, `다른 곡 ${JSON.stringify(st)}`);
|
||||
expect(st.every((s) => s.state === 1 && !s.muted), `재생 상태 ${JSON.stringify(st)}`);
|
||||
expect(Math.abs(st[0]!.pos - st[1]!.pos) < 0.4, `두 사람 위치 차이 ${JSON.stringify(st)}`);
|
||||
await x.locator('.stage .mode', { hasText: '재생이 끝났어요' }).waitFor({ timeout: 10000 });
|
||||
const end = await Promise.all([x, y].map((p) => p.evaluate(() => ({ pos: (window as any).mqPlayer.pos(), state: (window as any).mqPlayer.state() }))));
|
||||
console.log(` 멈춘 위치 ${end.map((s) => s.pos.toFixed(3)).join(' / ')}`);
|
||||
expect(end.every((s) => s.state === 2 && s.pos >= 9.9 && s.pos < 10.5), `클립 뒤 정지 ${JSON.stringify(end)}`);
|
||||
const title = file ? '연령제한노래' : 'Love wins all';
|
||||
await say(x, title);
|
||||
await x.locator('.reveal .big', { hasText: file ? '어른가수' : '아이유' }).waitFor({ timeout: 5000 });
|
||||
if (file) await x.screenshot({ path: join(SHOTS, 'age-audio-reveal.png') });
|
||||
}
|
||||
expect(kinds.sort().join() === 'file,youtube', `곡 종류 ${kinds}`);
|
||||
await x.getByRole('heading', { name: '🏁 게임 결과' }).waitFor({ timeout: 10000 });
|
||||
await x.context().close();
|
||||
await y.context().close();
|
||||
});
|
||||
}
|
||||
|
||||
expect(errors.length === 0, `페이지 오류: ${errors.join(' | ')}`);
|
||||
|
||||
Reference in New Issue
Block a user