From 3ab569c63724b4efe264b1fe47ff8344e5d85fbe Mon Sep 17 00:00:00 2001 From: Luan Date: Thu, 24 Oct 2024 09:12:18 -0300 Subject: [PATCH] fix(sabr): Video-only playback is no longer supported What a bummer... At least they can't remove audio-only, since it's still needed for YouTube Music. :) --- examples/downloader/ffmpeg-example.ts | 6 +++--- examples/downloader/main.ts | 11 +++-------- src/core/ServerAbrStream.ts | 8 ++++---- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/examples/downloader/ffmpeg-example.ts b/examples/downloader/ffmpeg-example.ts index d9aa250..79240a5 100644 --- a/examples/downloader/ffmpeg-example.ts +++ b/examples/downloader/ffmpeg-example.ts @@ -3,7 +3,7 @@ import cliProgress from 'cli-progress'; import type { WriteStream } from 'node:fs'; import { createWriteStream, unlink } from 'node:fs'; import { Innertube, UniversalCache } from 'youtubei.js'; -import GoogleVideo, { type Format, Protos } from '../../dist/src/index.js'; +import GoogleVideo, { type Format } from '../../dist/src/index.js'; const progressBars = new cliProgress.MultiBar({ stopOnComplete: true, @@ -121,8 +121,8 @@ await serverAbrStream.init({ audioFormats: [ selectedAudioFormat ], videoFormats: [ selectedVideoFormat ], clientAbrState: { - mediaType: Protos.MediaType.MEDIA_TYPE_DEFAULT, - startTimeMs: 0 + startTimeMs: 0, + mediaType: 0 // 0 = BOTH, 1 = AUDIO (video-only is no longer supported by YouTube) } }); diff --git a/examples/downloader/main.ts b/examples/downloader/main.ts index f6564ec..75030f9 100644 --- a/examples/downloader/main.ts +++ b/examples/downloader/main.ts @@ -2,7 +2,7 @@ import cliProgress from 'cli-progress'; import type { WriteStream } from 'node:fs'; import { createWriteStream } from 'node:fs'; import { Innertube, UniversalCache } from 'youtubei.js'; -import GoogleVideo, { type Format, Protos } from '../../dist/src/index.js'; +import GoogleVideo, { type Format } from '../../dist/src/index.js'; const progressBars = new cliProgress.MultiBar({ stopOnComplete: true, @@ -130,13 +130,8 @@ await serverAbrStream.init({ audioFormats: [ selectedAudioFormat ], videoFormats: [ selectedVideoFormat ], clientAbrState: { - /** - * MEDIA_TYPE_DEFAULT = 0, - * MEDIA_TYPE_AUDIO = 1, - * MEDIA_TYPE_VIDEO = 2, - */ - mediaType: Protos.MediaType.MEDIA_TYPE_DEFAULT, - startTimeMs: 0 + startTimeMs: 0, + mediaType: 0 // 0 = BOTH, 1 = AUDIO (video-only is no longer supported by YouTube) } }); diff --git a/src/core/ServerAbrStream.ts b/src/core/ServerAbrStream.ts index 269e125..3aae649 100644 --- a/src/core/ServerAbrStream.ts +++ b/src/core/ServerAbrStream.ts @@ -97,12 +97,12 @@ export class ServerAbrStream extends EventEmitterLike { if (data.sabrError) break; const mainFormat = - clientAbrState.mediaType === ClientAbrState_MediaType.MEDIA_TYPE_DEFAULT - ? data.initializedFormats.find((fmt) => fmt.mimeType?.includes('video')) - : data.initializedFormats[0]; + clientAbrState.mediaType === ClientAbrState_MediaType.MEDIA_TYPE_DEFAULT + ? data.initializedFormats.find((fmt) => fmt.mimeType?.includes('video')) + : data.initializedFormats[0]; for (const fmt of data.initializedFormats) { - this.previousSequences.set(`${fmt.formatId.itag};${fmt.formatId.lastModified};`, fmt.sequenceList.map((seq) => seq.sequenceNumber || 0)); + this.previousSequences.set(fmt.formatKey, fmt.sequenceList.map((seq) => seq.sequenceNumber || 0)); } if (