mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-19 04:21:35 +00:00
refactor: Remove internal uses of the .first() and .matchCondition() helpers (#889)
This commit is contained in:
@@ -155,7 +155,7 @@ export default class MusicResponsiveListItem extends YTNode {
|
||||
}
|
||||
|
||||
#parseOther() {
|
||||
this.title = this.flex_columns.first().title.toString();
|
||||
this.title = this.flex_columns[0].title.toString();
|
||||
|
||||
if (this.endpoint) {
|
||||
this.item_type = 'endpoint';
|
||||
@@ -183,10 +183,10 @@ export default class MusicResponsiveListItem extends YTNode {
|
||||
|
||||
#parseSong() {
|
||||
this.id = this.#playlist_item_data.video_id || this.endpoint?.payload?.videoId;
|
||||
this.title = this.flex_columns.first().title.toString();
|
||||
this.title = this.flex_columns[0].title.toString();
|
||||
|
||||
const duration_text = this.flex_columns.at(1)?.title.runs?.find(
|
||||
(run) => (/^\d+$/).test(run.text.replace(/:/g, '')))?.text || this.fixed_columns.first()?.title?.toString();
|
||||
(run) => (/^\d+$/).test(run.text.replace(/:/g, '')))?.text || this.fixed_columns[0]?.title?.toString();
|
||||
|
||||
if (duration_text) {
|
||||
this.duration = {
|
||||
@@ -230,7 +230,7 @@ export default class MusicResponsiveListItem extends YTNode {
|
||||
|
||||
#parseVideo() {
|
||||
this.id = this.#playlist_item_data.video_id;
|
||||
this.title = this.flex_columns.first().title.toString();
|
||||
this.title = this.flex_columns[0].title.toString();
|
||||
this.views = this.flex_columns.at(1)?.title.runs?.find((run) => run.text.match(/(.*?) views/))?.toString();
|
||||
|
||||
const author_runs = this.flex_columns.at(1)?.title.runs?.filter(
|
||||
@@ -250,7 +250,7 @@ export default class MusicResponsiveListItem extends YTNode {
|
||||
}
|
||||
|
||||
const duration_text = this.flex_columns[1].title.runs?.find(
|
||||
(run) => (/^\d+$/).test(run.text.replace(/:/g, '')))?.text || this.fixed_columns.first()?.title.runs?.find((run) => (/^\d+$/).test(run.text.replace(/:/g, '')))?.text;
|
||||
(run) => (/^\d+$/).test(run.text.replace(/:/g, '')))?.text || this.fixed_columns[0]?.title.runs?.find((run) => (/^\d+$/).test(run.text.replace(/:/g, '')))?.text;
|
||||
|
||||
if (duration_text) {
|
||||
this.duration = {
|
||||
@@ -262,30 +262,30 @@ export default class MusicResponsiveListItem extends YTNode {
|
||||
|
||||
#parseArtist() {
|
||||
this.id = this.endpoint?.payload?.browseId;
|
||||
this.name = this.flex_columns.first().title.toString();
|
||||
this.name = this.flex_columns[0].title.toString();
|
||||
this.subtitle = this.flex_columns.at(1)?.title;
|
||||
this.subscribers = this.subtitle?.runs?.find((run) => (/^(\d*\.)?\d+[M|K]? subscribers?$/i).test(run.text))?.text || '';
|
||||
}
|
||||
|
||||
#parseLibraryArtist() {
|
||||
this.name = this.flex_columns.first().title.toString();
|
||||
this.name = this.flex_columns[0].title.toString();
|
||||
this.subtitle = this.flex_columns.at(1)?.title;
|
||||
this.song_count = this.subtitle?.runs?.find((run) => (/^\d+(,\d+)? songs?$/i).test(run.text))?.text || '';
|
||||
}
|
||||
|
||||
#parseNonMusicTrack() {
|
||||
this.id = this.#playlist_item_data.video_id || this.endpoint?.payload?.videoId;
|
||||
this.title = this.flex_columns.first().title.toString();
|
||||
this.title = this.flex_columns[0].title.toString();
|
||||
}
|
||||
|
||||
#parsePodcastShow() {
|
||||
this.id = this.endpoint?.payload?.browseId;
|
||||
this.title = this.flex_columns.first().title.toString();
|
||||
this.title = this.flex_columns[0].title.toString();
|
||||
}
|
||||
|
||||
#parseAlbum() {
|
||||
this.id = this.endpoint?.payload?.browseId;
|
||||
this.title = this.flex_columns.first().title.toString();
|
||||
this.title = this.flex_columns[0].title.toString();
|
||||
|
||||
const author_run = this.flex_columns.at(1)?.title.runs?.find(
|
||||
(run) =>
|
||||
@@ -308,7 +308,7 @@ export default class MusicResponsiveListItem extends YTNode {
|
||||
|
||||
#parsePlaylist() {
|
||||
this.id = this.endpoint?.payload?.browseId;
|
||||
this.title = this.flex_columns.first().title.toString();
|
||||
this.title = this.flex_columns[0].title.toString();
|
||||
|
||||
const item_count_run = this.flex_columns.at(1)?.title
|
||||
.runs?.find((run) => run.text.match(/\d+ (song|songs)/));
|
||||
|
||||
@@ -58,7 +58,7 @@ export default class CommentThread extends YTNode {
|
||||
throw new InnertubeError('Unexpected response.', response);
|
||||
|
||||
this.replies = this.#getPatchedReplies(response.on_response_received_endpoints_memo);
|
||||
this.#continuation = response.on_response_received_endpoints_memo.getType(ContinuationItem).first();
|
||||
this.#continuation = response.on_response_received_endpoints_memo.getType(ContinuationItem)[0];
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -87,7 +87,7 @@ export default class CommentThread extends YTNode {
|
||||
throw new InnertubeError('Unexpected response.', response);
|
||||
|
||||
this.replies = this.#getPatchedReplies(response.on_response_received_endpoints_memo);
|
||||
this.#continuation = response.on_response_received_endpoints_memo.getType(ContinuationItem).first();
|
||||
this.#continuation = response.on_response_received_endpoints_memo.getType(ContinuationItem)[0];
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user