mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-28 00:56:23 +00:00
refactor: misc fixes and additions (#142)
* feat: add `header` to `Grid` parser * feat: parse title in `MusicHeader` * feat: improve parsing of artist-type items
This commit is contained in:
@@ -11,6 +11,10 @@ class Grid extends YTNode {
|
||||
this.visible_row_count = data.visibleRowCount;
|
||||
this.target_id = data.targetId;
|
||||
this.continuation = data.continuations?.[0]?.nextContinuationData?.continuation || null;
|
||||
|
||||
if (data.header) {
|
||||
this.header = Parser.parse(data.header);
|
||||
}
|
||||
}
|
||||
|
||||
// XXX: alias for consistency
|
||||
|
||||
15
src/parser/classes/GridHeader.ts
Normal file
15
src/parser/classes/GridHeader.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import Text from './misc/Text';
|
||||
import { YTNode } from '../helpers';
|
||||
|
||||
class GridHeader extends YTNode {
|
||||
static type = 'GridHeader';
|
||||
|
||||
title: Text;
|
||||
|
||||
constructor(data: any) {
|
||||
super();
|
||||
this.title = new Text(data.title);
|
||||
}
|
||||
}
|
||||
|
||||
export default GridHeader;
|
||||
@@ -1,12 +1,20 @@
|
||||
import Parser from '../index';
|
||||
import { YTNode } from '../helpers';
|
||||
import Text from './misc/Text';
|
||||
|
||||
class MusicHeader extends YTNode {
|
||||
static type = 'MusicHeader';
|
||||
|
||||
constructor(data) {
|
||||
super();
|
||||
this.header = Parser.parse(data.header);
|
||||
|
||||
if (data.header) {
|
||||
this.header = Parser.parse(data.header);
|
||||
}
|
||||
|
||||
if (data.title) {
|
||||
this.title = new Text(data.title);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,9 @@ class MusicResponsiveListItem extends YTNode {
|
||||
}[];
|
||||
|
||||
name?: string;
|
||||
subtitle?: Text;
|
||||
subscribers?: string;
|
||||
song_count?: string;
|
||||
// TODO: these might be replaceable with Author class
|
||||
author?: {
|
||||
name: string,
|
||||
@@ -186,7 +188,9 @@ class MusicResponsiveListItem extends YTNode {
|
||||
#parseArtist() {
|
||||
this.id = this.endpoint?.browse?.id;
|
||||
this.name = this.#flex_columns[0].key('title').instanceof(Text).toString();
|
||||
this.subscribers = this.#flex_columns[1].key('title').instanceof(Text).runs?.[2]?.text || '';
|
||||
this.subtitle = this.#flex_columns[1].key('title').instanceof(Text);
|
||||
this.subscribers = this.subtitle.runs?.find((run) => (/^(\d*\.)?\d+[M|K]? subscribers?$/i).test(run.text))?.text || '';
|
||||
this.song_count = this.subtitle.runs?.find((run) => (/^\d+(,\d+)? songs?$/i).test(run.text))?.text || '';
|
||||
}
|
||||
|
||||
#parseAlbum() {
|
||||
|
||||
@@ -22,7 +22,7 @@ class MusicTwoRowItem extends YTNode {
|
||||
switch (this.endpoint?.browse?.page_type) {
|
||||
case 'MUSIC_PAGE_TYPE_ARTIST':
|
||||
this.item_type = 'artist';
|
||||
this.subscribers = this.subtitle.toString();
|
||||
this.subscribers = this.subtitle.runs?.find((run) => (/^(\d*\.)?\d+[M|K]? subscribers?$/i).test(run.text))?.text || '';
|
||||
break;
|
||||
case 'MUSIC_PAGE_TYPE_PLAYLIST':
|
||||
this.item_type = 'playlist';
|
||||
|
||||
Reference in New Issue
Block a user