mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-15 02:22:11 +00:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5fe91d6642 | ||
|
|
bff65f8889 | ||
|
|
dac5eb712d | ||
|
|
2068dfb73e | ||
|
|
3e84775fd3 | ||
|
|
89fa3b27a8 | ||
|
|
ab7201f0cc | ||
|
|
b21eb9f33d | ||
|
|
0751793380 | ||
|
|
5c91c2af4a | ||
|
|
47cad4c6e1 | ||
|
|
4fb9dff0f2 | ||
|
|
81dd5d3288 | ||
|
|
c7f42220db | ||
|
|
5204b29e81 | ||
|
|
cbaa838cee |
@@ -14,6 +14,7 @@ overrides:
|
||||
-
|
||||
files:
|
||||
- '**/*.js'
|
||||
- '**/*.mjs'
|
||||
rules:
|
||||
'tsdoc/syntax': 'off'
|
||||
rules:
|
||||
|
||||
27
CHANGELOG.md
27
CHANGELOG.md
@@ -1,5 +1,32 @@
|
||||
# Changelog
|
||||
|
||||
## [9.1.0](https://github.com/LuanRT/YouTube.js/compare/v9.0.2...v9.1.0) (2024-02-23)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **Format:** Support caption tracks in adaptive formats ([#598](https://github.com/LuanRT/YouTube.js/issues/598)) ([bff65f8](https://github.com/LuanRT/YouTube.js/commit/bff65f8889c32813ec05bd187f3a4386fc6127c0))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **Playlist:** `items` getter failing if a playlist contains Shorts ([89fa3b2](https://github.com/LuanRT/YouTube.js/commit/89fa3b27a839d98aaf8bd70dd75220ee309c2bea))
|
||||
* **Session:** Don't try to extract api version from service worker ([2068dfb](https://github.com/LuanRT/YouTube.js/commit/2068dfb73eefc0e40157421d4e5b4096c0c8429c))
|
||||
|
||||
## [9.0.2](https://github.com/LuanRT/YouTube.js/compare/v9.0.1...v9.0.2) (2024-01-31)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **VideoInfo:** Fix error because of typo in getWatchNextContinuation ([#590](https://github.com/LuanRT/YouTube.js/issues/590)) ([b21eb9f](https://github.com/LuanRT/YouTube.js/commit/b21eb9f33d956e130bac98712384125ae04ace47))
|
||||
|
||||
## [9.0.1](https://github.com/LuanRT/YouTube.js/compare/v9.0.0...v9.0.1) (2024-01-26)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **build:** Circular imports causing issues with webpack ([81dd5d3](https://github.com/LuanRT/YouTube.js/commit/81dd5d3288771132e7fb904b620e58277f639ccc))
|
||||
|
||||
## [9.0.0](https://github.com/LuanRT/YouTube.js/compare/v8.2.0...v9.0.0) (2024-01-25)
|
||||
|
||||
|
||||
|
||||
13
package-lock.json
generated
13
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "youtubei.js",
|
||||
"version": "9.0.0",
|
||||
"version": "9.1.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "youtubei.js",
|
||||
"version": "9.0.0",
|
||||
"version": "9.1.0",
|
||||
"funding": [
|
||||
"https://github.com/sponsors/LuanRT"
|
||||
],
|
||||
@@ -5498,8 +5498,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/undici": {
|
||||
"version": "5.27.0",
|
||||
"license": "MIT",
|
||||
"version": "5.28.3",
|
||||
"resolved": "https://registry.npmjs.org/undici/-/undici-5.28.3.tgz",
|
||||
"integrity": "sha512-3ItfzbrhDlINjaP0duwnNsKpDQk3acHI3gVJ1z4fmwMK31k5G9OVIAMLSIaP6w4FaGkaAkN6zaQO9LUvZ1t7VA==",
|
||||
"dependencies": {
|
||||
"@fastify/busboy": "^2.0.0"
|
||||
},
|
||||
@@ -9138,7 +9139,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"undici": {
|
||||
"version": "5.27.0",
|
||||
"version": "5.28.3",
|
||||
"resolved": "https://registry.npmjs.org/undici/-/undici-5.28.3.tgz",
|
||||
"integrity": "sha512-3ItfzbrhDlINjaP0duwnNsKpDQk3acHI3gVJ1z4fmwMK31k5G9OVIAMLSIaP6w4FaGkaAkN6zaQO9LUvZ1t7VA==",
|
||||
"requires": {
|
||||
"@fastify/busboy": "^2.0.0"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "youtubei.js",
|
||||
"version": "9.0.0",
|
||||
"version": "9.1.0",
|
||||
"description": "A wrapper around YouTube's private API. Supports YouTube, YouTube Music, YouTube Kids and YouTube Studio (WIP).",
|
||||
"type": "module",
|
||||
"types": "./dist/src/platform/lib.d.ts",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import glob from "glob";
|
||||
import glob from 'glob';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import url from 'url';
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { Player, OAuth, Actions } from './index.js';
|
||||
import OAuth from './OAuth.js';
|
||||
import { Log, EventEmitter, HTTPClient } from '../utils/index.js';
|
||||
import * as Constants from '../utils/Constants.js';
|
||||
import * as Proto from '../proto/index.js';
|
||||
import Actions from './Actions.js';
|
||||
import Player from './Player.js';
|
||||
|
||||
import {
|
||||
generateRandomString, getRandomUserAgent,
|
||||
@@ -294,7 +296,7 @@ export default class Session extends EventEmitter {
|
||||
|
||||
const ytcfg = data[0][2];
|
||||
|
||||
const api_version = `v${ytcfg[0][0][6]}`;
|
||||
const api_version = Constants.CLIENTS.WEB.API_VERSION;
|
||||
|
||||
const [ [ device_info ], api_key ] = ytcfg;
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import { getStreamingInfo } from '../../utils/StreamingInfo.js';
|
||||
|
||||
import { Parser } from '../../parser/index.js';
|
||||
import { TranscriptInfo } from '../../parser/youtube/index.js';
|
||||
import PlayerStoryboardSpec from '../../parser/classes/PlayerStoryboardSpec.js';
|
||||
import ContinuationItem from '../../parser/classes/ContinuationItem.js';
|
||||
|
||||
import type { ApiResponse, Actions } from '../index.js';
|
||||
|
||||
@@ -45,6 +45,7 @@ export default class Format {
|
||||
target_duration_dec?: number;
|
||||
has_audio: boolean;
|
||||
has_video: boolean;
|
||||
has_text: boolean;
|
||||
language?: string | null;
|
||||
is_dubbed?: boolean;
|
||||
is_descriptive?: boolean;
|
||||
@@ -56,6 +57,14 @@ export default class Format {
|
||||
matrix_coefficients?: string;
|
||||
};
|
||||
|
||||
caption_track?: {
|
||||
display_name: string;
|
||||
vss_id: string;
|
||||
language_code: string;
|
||||
kind?: 'asr' | 'frc';
|
||||
id: string;
|
||||
};
|
||||
|
||||
constructor(data: RawNode, this_response_nsig_cache?: Map<string, string>) {
|
||||
if (this_response_nsig_cache) {
|
||||
this.#this_response_nsig_cache = this_response_nsig_cache;
|
||||
@@ -96,6 +105,7 @@ export default class Format {
|
||||
this.target_duration_dec = data.targetDurationSec;
|
||||
this.has_audio = !!data.audioBitrate || !!data.audioQuality;
|
||||
this.has_video = !!data.qualityLabel;
|
||||
this.has_text = !!data.captionTrack;
|
||||
|
||||
this.color_info = data.colorInfo ? {
|
||||
primaries: data.colorInfo.primaries?.replace('COLOR_PRIMARIES_', ''),
|
||||
@@ -103,25 +113,42 @@ export default class Format {
|
||||
matrix_coefficients: data.colorInfo.matrixCoefficients?.replace('COLOR_MATRIX_COEFFICIENTS_', '')
|
||||
} : undefined;
|
||||
|
||||
if (this.has_audio) {
|
||||
if (Reflect.has(data, 'audioTrack')) {
|
||||
this.audio_track = {
|
||||
audio_is_default: data.audioTrack.audioIsDefault,
|
||||
display_name: data.audioTrack.displayName,
|
||||
id: data.audioTrack.id
|
||||
};
|
||||
}
|
||||
|
||||
if (Reflect.has(data, 'captionTrack')) {
|
||||
this.caption_track = {
|
||||
display_name: data.captionTrack.displayName,
|
||||
vss_id: data.captionTrack.vssId,
|
||||
language_code: data.captionTrack.languageCode,
|
||||
kind: data.captionTrack.kind,
|
||||
id: data.captionTrack.id
|
||||
};
|
||||
}
|
||||
|
||||
if (this.has_audio || this.has_text) {
|
||||
const args = new URLSearchParams(this.cipher || this.signature_cipher);
|
||||
const url_components = new URLSearchParams(args.get('url') || this.url);
|
||||
|
||||
const xtags = url_components.get('xtags')?.split(':');
|
||||
|
||||
const audio_content = xtags?.find((x) => x.startsWith('acont='))?.split('=')[1];
|
||||
|
||||
this.language = xtags?.find((x: string) => x.startsWith('lang='))?.split('=')[1] || null;
|
||||
this.is_dubbed = audio_content === 'dubbed';
|
||||
this.is_descriptive = audio_content === 'descriptive';
|
||||
this.is_original = audio_content === 'original' || (!this.is_dubbed && !this.is_descriptive);
|
||||
|
||||
if (Reflect.has(data, 'audioTrack')) {
|
||||
this.audio_track = {
|
||||
audio_is_default: data.audioTrack.audioIsDefault,
|
||||
display_name: data.audioTrack.displayName,
|
||||
id: data.audioTrack.id
|
||||
};
|
||||
if (this.has_audio) {
|
||||
const audio_content = xtags?.find((x) => x.startsWith('acont='))?.split('=')[1];
|
||||
this.is_dubbed = audio_content === 'dubbed';
|
||||
this.is_descriptive = audio_content === 'descriptive';
|
||||
this.is_original = audio_content === 'original' || (!this.is_dubbed && !this.is_descriptive);
|
||||
}
|
||||
|
||||
// Some text tracks don't have xtags while others do
|
||||
if (this.has_text && !this.language && this.caption_track) {
|
||||
this.language = this.caption_track.language_code;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable no-cond-assign */
|
||||
import { YTNode } from './helpers.js';
|
||||
import { Parser } from './index.js';
|
||||
import * as Parser from './parser.js';
|
||||
import { InnertubeError } from '../utils/Utils.js';
|
||||
|
||||
import Author from './classes/misc/Author.js';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { YTNodes } from './index.js';
|
||||
import * as YTNodes from './nodes.js';
|
||||
import { InnertubeError, ParsingError, Platform } from '../utils/Utils.js';
|
||||
import { Memo, observe, SuperParsedResult } from './helpers.js';
|
||||
import { camelToSnake, generateRuntimeClass, generateTypescriptClass } from './generator.js';
|
||||
|
||||
@@ -8,6 +8,7 @@ import PlaylistMetadata from '../classes/PlaylistMetadata.js';
|
||||
import PlaylistSidebarPrimaryInfo from '../classes/PlaylistSidebarPrimaryInfo.js';
|
||||
import PlaylistSidebarSecondaryInfo from '../classes/PlaylistSidebarSecondaryInfo.js';
|
||||
import PlaylistVideoThumbnail from '../classes/PlaylistVideoThumbnail.js';
|
||||
import ReelItem from '../classes/ReelItem.js';
|
||||
import VideoOwner from '../classes/VideoOwner.js';
|
||||
import Alert from '../classes/Alert.js';
|
||||
import ContinuationItem from '../classes/ContinuationItem.js';
|
||||
@@ -66,8 +67,8 @@ export default class Playlist extends Feed<IBrowseResponse> {
|
||||
return primary_info.stats[index]?.toString() || 'N/A';
|
||||
}
|
||||
|
||||
get items(): ObservedArray<PlaylistVideo> {
|
||||
return observe(this.videos.as(PlaylistVideo).filter((video) => video.style !== 'PLAYLIST_VIDEO_RENDERER_STYLE_RECOMMENDED_VIDEO'));
|
||||
get items(): ObservedArray<PlaylistVideo | ReelItem> {
|
||||
return observe(this.videos.as(PlaylistVideo, ReelItem).filter((video) => (video as PlaylistVideo).style !== 'PLAYLIST_VIDEO_RENDERER_STYLE_RECOMMENDED_VIDEO'));
|
||||
}
|
||||
|
||||
get has_continuation() {
|
||||
|
||||
@@ -231,7 +231,7 @@ class VideoInfo extends MediaInfo {
|
||||
throw new InnertubeError('Watch next feed continuation not found');
|
||||
|
||||
const response = await this.#watch_next_continuation?.endpoint.call(this.actions, { parse: true });
|
||||
const data = response?.on_response_received_endpoints?.get({ type: 'appendContinuationItemsAction' });
|
||||
const data = response?.on_response_received_endpoints?.get({ type: 'AppendContinuationItemsAction' });
|
||||
|
||||
if (!data)
|
||||
throw new InnertubeError('AppendContinuationItemsAction not found');
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Constants } from './index.js';
|
||||
import * as Constants from './Constants.js';
|
||||
import { InnertubeError, Platform, streamToIterable } from './Utils.js';
|
||||
|
||||
import type Player from '../core/Player.js';
|
||||
@@ -169,9 +169,9 @@ export function chooseFormat(options: FormatOptions, streaming_data?: IStreaming
|
||||
if (requires_audio && !requires_video) {
|
||||
const audio_only = candidates.filter((format) => {
|
||||
if (language !== 'original') {
|
||||
return !format.has_video && format.language === language;
|
||||
return !format.has_video && !format.has_text && format.language === language;
|
||||
}
|
||||
return !format.has_video && format.is_original;
|
||||
return !format.has_video && !format.has_text && format.is_original;
|
||||
|
||||
});
|
||||
if (audio_only.length > 0) {
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
import PlayerStoryboardSpec from '../parser/classes/PlayerStoryboardSpec.js';
|
||||
import { InnertubeError, Platform, getStringBetweenStrings } from './Utils.js';
|
||||
import * as Constants from './Constants.js';
|
||||
import Log from './Log.js';
|
||||
|
||||
import type Actions from '../core/Actions.js';
|
||||
import type Player from '../core/Player.js';
|
||||
import type { LiveStoryboardData } from '../parser/classes/PlayerLiveStoryboardSpec.js';
|
||||
@@ -6,9 +11,6 @@ import type { IStreamingData } from '../parser/index.js';
|
||||
import type { Format } from '../parser/misc.js';
|
||||
import type { PlayerLiveStoryboardSpec } from '../parser/nodes.js';
|
||||
import type { FormatFilter, URLTransformer } from '../types/FormatUtils.js';
|
||||
import PlayerStoryboardSpec from '../parser/classes/PlayerStoryboardSpec.js';
|
||||
import { InnertubeError, Platform, getStringBetweenStrings } from './Utils.js';
|
||||
import { Constants, Log } from './index.js';
|
||||
|
||||
const TAG_ = 'StreamingInfo';
|
||||
|
||||
|
||||
@@ -106,7 +106,8 @@
|
||||
"include": [
|
||||
"src/**/*.ts",
|
||||
"src/**/*.tsx",
|
||||
"src/**/*.js"
|
||||
"src/**/*.js",
|
||||
"scripts/**/*.mjs",
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
|
||||
Reference in New Issue
Block a user