mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-17 11:32:27 +00:00
perf: use getBasicInfo()
This commit is contained in:
@@ -178,6 +178,21 @@ class Innertube {
|
||||
return new VideoInfo(response, this.actions, this.#player, cpn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves basic video info.
|
||||
*
|
||||
* @param {string} video_id
|
||||
* @returns {Promise.<VideoInfo>}
|
||||
*/
|
||||
async getBasicInfo(video_id) {
|
||||
Utils.throwIfMissing({ video_id });
|
||||
const cpn = Utils.generateRandomString(16);
|
||||
|
||||
const response = await this.actions.getVideoInfo(video_id, cpn);
|
||||
|
||||
return new VideoInfo([ response, {} ], this.actions, this.#player, cpn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches a given query.
|
||||
*
|
||||
@@ -418,7 +433,7 @@ class Innertube {
|
||||
* @returns {Promise.<object>}
|
||||
*/
|
||||
async getStreamingData(video_id, options = {}) {
|
||||
const info = await this.getInfo(video_id);
|
||||
const info = await this.getBasicInfo(video_id);
|
||||
|
||||
return info.chooseFormat(options);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ class VideoInfo {
|
||||
this.#cpn = cpn;
|
||||
|
||||
const info = Parser.parseResponse(data[0]);
|
||||
const next = Parser.parseResponse(data[1].data);
|
||||
const next = Parser.parseResponse(data[1].data || {});
|
||||
|
||||
this.#page = [info, next];
|
||||
|
||||
@@ -51,42 +51,7 @@ class VideoInfo {
|
||||
has_ypc_metadata: info.microformat.has_ypc_metadata
|
||||
}
|
||||
};
|
||||
|
||||
const results = next.contents.results;
|
||||
const secondary_results = next.contents.secondary_results;
|
||||
|
||||
/**
|
||||
* @type {import('../contents/classes/VideoPrimaryInfo')}
|
||||
*/
|
||||
this.primary_info = results.get({ type: 'VideoPrimaryInfo' });
|
||||
|
||||
/**
|
||||
* @type {import('../contents/classes/VideoSecondaryInfo')}
|
||||
*/
|
||||
this.secondary_info = results.get({ type: 'VideoSecondaryInfo' });
|
||||
|
||||
/**
|
||||
* @type {import('../contents/classes/MerchandiseShelf')}
|
||||
*/
|
||||
this.merchandise = results?.get({ type: 'MerchandiseShelf' }) || null;
|
||||
|
||||
/**
|
||||
* @type {import('../contents/classes/ChipCloud')}
|
||||
*/
|
||||
this.related_chip_cloud = secondary_results?.get({ type: 'RelatedChipCloud' })?.content;
|
||||
|
||||
this.watch_next_feed = secondary_results?.get({ target_id: 'watch-next-feed' })?.contents;
|
||||
this.#watch_next_continuation = this.watch_next_feed?.pop();
|
||||
|
||||
/**
|
||||
* @type {import('../contents/classes/PlayerOverlay')}
|
||||
*/
|
||||
this.player_overlays = next.player_overlays;
|
||||
|
||||
this.basic_info.like_count = this.primary_info.menu.top_level_buttons.get({ icon_type: 'LIKE' }).like_count;
|
||||
this.basic_info.is_liked = this.primary_info.menu.top_level_buttons.get({ icon_type: 'LIKE' }).is_toggled;
|
||||
this.basic_info.is_disliked = this.primary_info.menu.top_level_buttons.get({ icon_type: 'DISLIKE' }).is_toggled;
|
||||
|
||||
|
||||
this.streaming_data = info.streaming_data || null;
|
||||
this.playability_status = info.playability_status;
|
||||
|
||||
@@ -99,7 +64,7 @@ class VideoInfo {
|
||||
* @type {import('../contents/classes/PlayerStoryboardSpec')}
|
||||
*/
|
||||
this.storyboards = info.storyboards;
|
||||
|
||||
|
||||
/**
|
||||
* @type {import('../contents/classes/Endscreen')}
|
||||
*/
|
||||
@@ -115,12 +80,49 @@ class VideoInfo {
|
||||
*/
|
||||
this.cards = info.cards;
|
||||
|
||||
const comments_entry_point = results.get({ target_id: 'comments-entry-point' });
|
||||
const results = next.contents?.results;
|
||||
const secondary_results = next.contents?.secondary_results;
|
||||
|
||||
if (results && secondary_results) {
|
||||
/**
|
||||
* @type {import('../contents/classes/VideoPrimaryInfo')}
|
||||
*/
|
||||
this.primary_info = results.get({ type: 'VideoPrimaryInfo' });
|
||||
|
||||
/**
|
||||
* @type {import('../contents/classes/CommentsEntryPointHeader')}
|
||||
*/
|
||||
this.comments_entry_point_header = comments_entry_point?.contents.get({ type: 'CommentsEntryPointHeader' }) || {};
|
||||
/**
|
||||
* @type {import('../contents/classes/VideoSecondaryInfo')}
|
||||
*/
|
||||
this.secondary_info = results.get({ type: 'VideoSecondaryInfo' });
|
||||
|
||||
/**
|
||||
* @type {import('../contents/classes/MerchandiseShelf')}
|
||||
*/
|
||||
this.merchandise = results?.get({ type: 'MerchandiseShelf' }) || null;
|
||||
|
||||
/**
|
||||
* @type {import('../contents/classes/ChipCloud')}
|
||||
*/
|
||||
this.related_chip_cloud = secondary_results?.get({ type: 'RelatedChipCloud' })?.content;
|
||||
|
||||
this.watch_next_feed = secondary_results?.get({ target_id: 'watch-next-feed' })?.contents;
|
||||
this.#watch_next_continuation = this.watch_next_feed?.pop();
|
||||
|
||||
/**
|
||||
* @type {import('../contents/classes/PlayerOverlay')}
|
||||
*/
|
||||
this.player_overlays = next.player_overlays;
|
||||
|
||||
this.basic_info.like_count = this.primary_info.menu.top_level_buttons.get({ icon_type: 'LIKE' }).like_count;
|
||||
this.basic_info.is_liked = this.primary_info.menu.top_level_buttons.get({ icon_type: 'LIKE' }).is_toggled;
|
||||
this.basic_info.is_disliked = this.primary_info.menu.top_level_buttons.get({ icon_type: 'DISLIKE' }).is_toggled;
|
||||
|
||||
const comments_entry_point = results.get({ target_id: 'comments-entry-point' });
|
||||
|
||||
/**
|
||||
* @type {import('../contents/classes/CommentsEntryPointHeader')}
|
||||
*/
|
||||
this.comments_entry_point_header = comments_entry_point?.contents.get({ type: 'CommentsEntryPointHeader' }) || {};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user