From 6e30309f565485e73c1a3a0fd0b320b270c7672d Mon Sep 17 00:00:00 2001 From: LuanRT Date: Mon, 13 Feb 2023 19:42:49 -0300 Subject: [PATCH] style: clean up and fix minor inconsistencies --- examples/browser/web/src/main.ts | 6 ++++-- src/Innertube.ts | 8 ++++---- src/core/Actions.ts | 11 ++++------- src/parser/parser.ts | 3 +-- src/parser/youtube/VideoInfo.ts | 2 +- src/parser/ytkids/VideoInfo.ts | 2 +- src/parser/ytmusic/TrackInfo.ts | 2 +- src/utils/FormatUtils.ts | 7 +++---- 8 files changed, 19 insertions(+), 22 deletions(-) diff --git a/examples/browser/web/src/main.ts b/examples/browser/web/src/main.ts index f3de15d1..e25c0867 100644 --- a/examples/browser/web/src/main.ts +++ b/examples/browser/web/src/main.ts @@ -26,6 +26,9 @@ async function main() { // now serialize the headers url.searchParams.set('__headers', JSON.stringify([...headers])); + // @ts-ignore + input.duplex = 'half'; + // copy over the request const request = new Request( url, @@ -42,7 +45,7 @@ async function main() { headers }); }, - cache: new UniversalCache(), + cache: new UniversalCache(false), }); const span = document.getElementById('video_name') as HTMLSpanElement; @@ -66,7 +69,6 @@ async function main() { } try { const video = await yt.getInfo(video_id); - console.log(video); span.textContent = video.basic_info.title || null; diff --git a/src/Innertube.ts b/src/Innertube.ts index e49b641d..c33c3b69 100644 --- a/src/Innertube.ts +++ b/src/Innertube.ts @@ -14,10 +14,10 @@ import VideoInfo from './parser/youtube/VideoInfo.js'; import AccountManager from './core/AccountManager.js'; import Feed from './core/Feed.js'; import InteractionManager from './core/InteractionManager.js'; +import YTKids from './core/Kids.js'; import YTMusic from './core/Music.js'; import PlaylistManager from './core/PlaylistManager.js'; import YTStudio from './core/Studio.js'; -import YTKids from './core/Kids.js'; import TabbedFeed from './core/TabbedFeed.js'; import HomeFeed from './parser/youtube/HomeFeed.js'; import Proto from './proto/index.js'; @@ -26,10 +26,10 @@ import Constants from './utils/Constants.js'; import type Actions from './core/Actions.js'; import type Format from './parser/classes/misc/Format.js'; -import { generateRandomString, throwIfMissing } from './utils/Utils.js'; -import type { FormatOptions, DownloadOptions } from './utils/FormatUtils.js'; import type { ApiResponse } from './core/Actions.js'; -import type { IBrowseResponse, IParsedResponse } from './parser/types/ParsedResponse.js'; +import type { IBrowseResponse, IParsedResponse } from './parser/types/index.js'; +import type { DownloadOptions, FormatOptions } from './utils/FormatUtils.js'; +import { generateRandomString, throwIfMissing } from './utils/Utils.js'; export type InnertubeConfig = SessionOptions; diff --git a/src/core/Actions.ts b/src/core/Actions.ts index ed585a89..00425eb5 100644 --- a/src/core/Actions.ts +++ b/src/core/Actions.ts @@ -5,13 +5,10 @@ import type Session from './Session.js'; import type { IBrowseResponse, IGetNotificationsMenuResponse, - INextResponse, IParsedResponse, IPlayerResponse, - IResolveURLResponse, ISearchResponse, - IUpdatedMetadataResponse -} from '../parser/types/ParsedResponse.js'; - -import type { IRawResponse } from '../parser/types/RawResponse.js'; - + INextResponse, IPlayerResponse, IResolveURLResponse, + ISearchResponse, IUpdatedMetadataResponse, + IParsedResponse, IRawResponse +} from '../parser/types/index.js'; export interface ApiResponse { success: boolean; diff --git a/src/parser/parser.ts b/src/parser/parser.ts index 50fbaa98..88aaa68e 100644 --- a/src/parser/parser.ts +++ b/src/parser/parser.ts @@ -11,8 +11,7 @@ import type LiveChatHeader from './classes/LiveChatHeader.js'; import type LiveChatItemList from './classes/LiveChatItemList.js'; import type Alert from './classes/Alert.js'; -import type { IParsedResponse } from './types/ParsedResponse.js'; -import type { IRawResponse, RawData, RawNode } from './types/RawResponse.js'; +import type { IParsedResponse, IRawResponse, RawData, RawNode } from './types/index.js'; import MusicMultiSelectMenuItem from './classes/menus/MusicMultiSelectMenuItem.js'; import Format from './classes/misc/Format.js'; diff --git a/src/parser/youtube/VideoInfo.ts b/src/parser/youtube/VideoInfo.ts index 3851263e..5b43bde8 100644 --- a/src/parser/youtube/VideoInfo.ts +++ b/src/parser/youtube/VideoInfo.ts @@ -311,7 +311,7 @@ class VideoInfo { * @param format_filter - Function to filter the formats. * @returns DASH manifest */ - toDash(url_transformer: URLTransformer = (url) => url, format_filter: FormatFilter): string { + toDash(url_transformer?: URLTransformer, format_filter?: FormatFilter): string { return FormatUtils.toDash(this.streaming_data, url_transformer, format_filter, this.#cpn, this.#player); } diff --git a/src/parser/ytkids/VideoInfo.ts b/src/parser/ytkids/VideoInfo.ts index 5b878c86..a84dc825 100644 --- a/src/parser/ytkids/VideoInfo.ts +++ b/src/parser/ytkids/VideoInfo.ts @@ -73,7 +73,7 @@ class VideoInfo { * @param format_filter - Function to filter the formats. * @returns DASH manifest */ - toDash(url_transformer: URLTransformer = (url) => url, format_filter: FormatFilter): string { + toDash(url_transformer?: URLTransformer, format_filter?: FormatFilter): string { return FormatUtils.toDash(this.streaming_data, url_transformer, format_filter, this.#cpn, this.#actions.session.player); } diff --git a/src/parser/ytmusic/TrackInfo.ts b/src/parser/ytmusic/TrackInfo.ts index be49baa5..bc1282c9 100644 --- a/src/parser/ytmusic/TrackInfo.ts +++ b/src/parser/ytmusic/TrackInfo.ts @@ -95,7 +95,7 @@ class TrackInfo { * @param format_filter - Function to filter the formats. * @returns DASH manifest */ - toDash(url_transformer: URLTransformer = (url) => url, format_filter: FormatFilter): string { + toDash(url_transformer?: URLTransformer, format_filter?: FormatFilter): string { return FormatUtils.toDash(this.streaming_data, url_transformer, format_filter, this.#cpn, this.#actions.session.player); } diff --git a/src/utils/FormatUtils.ts b/src/utils/FormatUtils.ts index 123c8d96..94110236 100644 --- a/src/utils/FormatUtils.ts +++ b/src/utils/FormatUtils.ts @@ -311,7 +311,7 @@ class FormatUtils { if (!video_format.index_range || !video_format.init_range) { return; } - const mime_type = video_format.mime_type.split(';')[0]; + const mime_type = video_format.mime_type; const mime_type_index = mime_types.indexOf(mime_type); if (mime_type_index > -1) { mime_objects[mime_type_index].push(video_format); @@ -324,7 +324,6 @@ class FormatUtils { let set_id = 0; for (let i = 0; i < mime_types.length; i++) { - // When the video has multiple different audio tracks/langues we want to include the extra information in the manifest if (mime_objects[i][0].has_audio && mime_objects[i][0].language) { const languages: string[] = []; @@ -367,7 +366,7 @@ class FormatUtils { const set = this.#el(document, 'AdaptationSet', { id: `${set_id++}`, - mimeType: mime_types[i], + mimeType: mime_types[i].split(';')[0], startWithSAP: '1', subsegmentAlignment: 'true', lang: languages[j] @@ -382,7 +381,7 @@ class FormatUtils { } else { const set = this.#el(document, 'AdaptationSet', { id: `${set_id++}`, - mimeType: mime_types[i], + mimeType: mime_types[i].split(';')[0], startWithSAP: '1', subsegmentAlignment: 'true' });