연령제한 곡 재생: 유튜브가 퍼가기 플레이어에서 막는(오류 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:
EJClaw
2026-10-20 08:11:55 +09:00
parent 37c1440892
commit 4f888711b1
26 changed files with 705 additions and 45 deletions

View File

@@ -58,6 +58,8 @@ export class Game {
total: number;
song: QuizSong | null = null;
private clip: { startSec: number; endSec: number | null } = { startSec: 0, endSec: null };
/** 연령제한 곡: this question's address of our audio file (songs/audio.ts), null = the YouTube player. */
private audioSrc: string | null = null;
participants = new Set<string>();
excluded = new Set<string>();
private ready = new Set<string>();
@@ -157,7 +159,7 @@ export class Game {
let song: QuizSong | null = null;
while (this.n <= this.total) {
song = quizSong(this.room.deps.db, this.list[this.n - 1]!);
if (song && (this.listening ? song.videoId : song.lyrics)) break;
if (song && (this.listening ? song.videoId && (!song.ageRestricted || (song.audio && this.room.deps.audio)) : song.lyrics)) break;
this.list.splice(this.n - 1, 1);
this.total = c.count ? Math.min(c.count, this.list.length) : this.list.length;
song = null;
@@ -165,6 +167,7 @@ export class Game {
if (!song) return this.finish();
const now = this.now();
this.song = song;
this.audioSrc = this.listening && song.ageRestricted ? this.room.deps.audio!.link(song.videoId!) : null;
this.clip = this.listening ? clipOf(song, c) : { startSec: 0, endSec: null };
this.participants = new Set(this.room.online());
this.excluded.clear();
@@ -206,7 +209,14 @@ export class Game {
this.ready.clear();
this.waitingSince.clear();
for (const id of this.active()) this.waitingSince.set(id, now);
this.toActive({ t: 'prepare', code: this.room.code, n: this.n, videoId: this.song!.videoId!, startSec: atSec, endSec: this.clip.endSec, gain: loudnessGain(this.song!.loudness) });
this.toActive({ t: 'prepare', code: this.room.code, n: this.n, ...this.source(), startSec: atSec, endSec: this.clip.endSec });
}
/** What the players load: the YouTube video, or our file for a 연령제한 곡 (never the video id then). */
private source(): { videoId: string | null; audio: string | null; gain: number } {
const s = this.song!;
if (this.audioSrc) return { videoId: null, audio: this.audioSrc, gain: loudnessGain(s.loudness, true) };
return { videoId: s.videoId!, audio: null, gain: loudnessGain(s.loudness) };
}
private checkReady(): void {
@@ -414,7 +424,9 @@ export class Game {
}
if (ev === 'error' && (code === 100 || code === 101 || code === 150) && (this.phase === 'prepare' || this.phase === 'play') && this.song) {
// The video is gone or may not be embedded: swap the song for everyone, same question number (docs/12 Q1).
// 연령제한 곡 also land here (150): the collector checks it and brings the song back with downloaded audio.
markUnplayable(this.room.deps.db, this.song.id, code);
this.room.deps.onUnplayable?.(this.song.id);
this.room.say(null, '이 곡은 재생할 수 없어서 다른 곡으로 바꿨어요');
this.toActive({ t: 'pause', code: this.room.code, n: this.n });
this.list.splice(this.n - 1, 1);
@@ -515,10 +527,10 @@ export class Game {
if (this.awaitingReady) {
this.ready.delete(userId);
if (!this.waitingSince.has(userId)) this.waitingSince.set(userId, this.now());
send({ t: 'prepare', code: this.room.code, n: this.n, videoId: this.song.videoId, startSec: this.resumeAt, endSec: this.clip.endSec, gain: loudnessGain(this.song.loudness) });
send({ t: 'prepare', code: this.room.code, n: this.n, ...this.source(), startSec: this.resumeAt, endSec: this.clip.endSec });
this.broadcast();
} else if (this.playing && !this.clipOver) {
send({ t: 'catchup', code: this.room.code, n: this.n, videoId: this.song.videoId, clipStart: this.clip.startSec, startAt: this.audioStartAt, atSec: this.audioAtSec, endSec: this.clip.endSec, gain: loudnessGain(this.song.loudness) });
send({ t: 'catchup', code: this.room.code, n: this.n, ...this.source(), clipStart: this.clip.startSec, startAt: this.audioStartAt, atSec: this.audioAtSec, endSec: this.clip.endSec });
}
}