Skip to content

Commit

Permalink
fix(sabr): Video-only playback is no longer supported
Browse files Browse the repository at this point in the history
What a bummer...

At least they can't remove audio-only, since it's still needed for YouTube Music. :)
  • Loading branch information
LuanRT committed Oct 24, 2024
1 parent 5cec3e9 commit 3ab569c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
6 changes: 3 additions & 3 deletions examples/downloader/ffmpeg-example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
});

Expand Down
11 changes: 3 additions & 8 deletions examples/downloader/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
});

Expand Down
8 changes: 4 additions & 4 deletions src/core/ServerAbrStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 3ab569c

Please sign in to comment.