mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-26 08:08:54 +00:00
29
src/parser/classes/GridShow.ts
Normal file
29
src/parser/classes/GridShow.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { ObservedArray, YTNode } from '../helpers.js';
|
||||
import { RawNode } from '../index.js';
|
||||
import Parser from '../parser.js';
|
||||
import Author from './misc/Author.js';
|
||||
import Text from './misc/Text.js';
|
||||
import NavigationEndpoint from './NavigationEndpoint.js';
|
||||
import ShowCustomThumbnail from './ShowCustomThumbnail.js';
|
||||
import ThumbnailOverlayBottomPanel from './ThumbnailOverlayBottomPanel.js';
|
||||
|
||||
export default class GridShow extends YTNode {
|
||||
static type = 'GridShow';
|
||||
|
||||
title: Text;
|
||||
thumbnail_renderer: ShowCustomThumbnail | null;
|
||||
endpoint: NavigationEndpoint;
|
||||
long_byline_text: Text;
|
||||
thumbnail_overlays: ObservedArray<ThumbnailOverlayBottomPanel> | null;
|
||||
author: Author;
|
||||
|
||||
constructor(data: RawNode) {
|
||||
super();
|
||||
this.title = new Text(data.title);
|
||||
this.thumbnail_renderer = Parser.parseItem(data.thumbnailRenderer, ShowCustomThumbnail);
|
||||
this.endpoint = new NavigationEndpoint(data.navigationEndpoint);
|
||||
this.long_byline_text = new Text(data.longBylineText);
|
||||
this.thumbnail_overlays = Parser.parseArray(data.thumbnailOverlays, ThumbnailOverlayBottomPanel);
|
||||
this.author = new Author(data.shortBylineText, undefined);
|
||||
}
|
||||
}
|
||||
14
src/parser/classes/ShowCustomThumbnail.ts
Normal file
14
src/parser/classes/ShowCustomThumbnail.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { YTNode } from '../helpers.js';
|
||||
import { RawNode } from '../index.js';
|
||||
import Thumbnail from './misc/Thumbnail.js';
|
||||
|
||||
export default class ShowCustomThumbnail extends YTNode {
|
||||
static type = 'ShowCustomThumbnail';
|
||||
|
||||
thumbnail: Thumbnail[];
|
||||
|
||||
constructor(data: RawNode) {
|
||||
super();
|
||||
this.thumbnail = Thumbnail.fromResponse(data.thumbnail);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,22 @@
|
||||
import { YTNode } from '../helpers.js';
|
||||
import { RawNode } from '../index.js';
|
||||
import Text from './misc/Text.js';
|
||||
|
||||
class ThumbnailOverlayBottomPanel extends YTNode {
|
||||
static type = 'ThumbnailOverlayBottomPanel';
|
||||
|
||||
icon_type: string;
|
||||
text?: Text;
|
||||
icon_type?: string;
|
||||
|
||||
constructor(data: any) {
|
||||
constructor(data: RawNode) {
|
||||
super();
|
||||
this.icon_type = data.icon.iconType;
|
||||
if (Reflect.has(data, 'text')) {
|
||||
this.text = new Text(data.text);
|
||||
}
|
||||
|
||||
if (Reflect.has(data, 'icon') && Reflect.has(data.icon, 'iconType')) {
|
||||
this.icon_type = data.icon.iconType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ export function escape(text: string) {
|
||||
.replace(/'/g, ''');
|
||||
}
|
||||
|
||||
class Text {
|
||||
export default class Text {
|
||||
text?: string;
|
||||
runs;
|
||||
endpoint?: NavigationEndpoint;
|
||||
@@ -39,8 +39,11 @@ class Text {
|
||||
if (typeof data === 'object' && data !== null && Reflect.has(data, 'titleNavigationEndpoint')) {
|
||||
this.endpoint = new NavigationEndpoint(data.titleNavigationEndpoint);
|
||||
}
|
||||
if (!this.endpoint)
|
||||
this.endpoint = (this.runs?.[0] as TextRun)?.endpoint;
|
||||
if (!this.endpoint) {
|
||||
if ((this.runs?.[0] as TextRun)?.endpoint) {
|
||||
this.endpoint = (this.runs?.[0] as TextRun)?.endpoint;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
toHTML() {
|
||||
@@ -54,6 +57,4 @@ class Text {
|
||||
toString() {
|
||||
return this.text || 'N/A';
|
||||
}
|
||||
}
|
||||
|
||||
export default Text;
|
||||
}
|
||||
Reference in New Issue
Block a user