mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-27 08:39:23 +00:00
chore: v8.1.0 release
This commit is contained in:
30
deno/src/parser/classes/AvatarView.ts
Normal file
30
deno/src/parser/classes/AvatarView.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { YTNode } from '../helpers.ts';
|
||||
import { type RawNode } from '../index.ts';
|
||||
import { Thumbnail } from '../misc.ts';
|
||||
|
||||
export default class AvatarView extends YTNode {
|
||||
static type = 'AvatarView';
|
||||
|
||||
image: {
|
||||
sources: Thumbnail[],
|
||||
processor: {
|
||||
border_image_processor: {
|
||||
circular: boolean
|
||||
}
|
||||
}
|
||||
};
|
||||
avatar_image_size: string;
|
||||
|
||||
constructor(data: RawNode) {
|
||||
super();
|
||||
this.image = {
|
||||
sources: data.image.sources.map((x: any) => new Thumbnail(x)).sort((a: Thumbnail, b: Thumbnail) => b.width - a.width),
|
||||
processor: {
|
||||
border_image_processor: {
|
||||
circular: data.image.processor.borderImageProcessor.circular
|
||||
}
|
||||
}
|
||||
};
|
||||
this.avatar_image_size = data.avatarImageSize;
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,6 @@ export default class ChannelExternalLinkView extends YTNode {
|
||||
|
||||
this.title = Text.fromAttributed(data.title);
|
||||
this.link = Text.fromAttributed(data.link);
|
||||
this.favicon = data.favicon.sources.map((x: any) => new Thumbnail(x)).sort((a: Thumbnail, b: Thumbnail) => b.width - a.width);
|
||||
this.favicon = Thumbnail.fromResponse(data.favicon);
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ export default class ContentPreviewImageView extends YTNode {
|
||||
|
||||
constructor(data: RawNode) {
|
||||
super();
|
||||
this.image = data.image.sources.map((x: any) => new Thumbnail(x)).sort((a: Thumbnail, b: Thumbnail) => b.width - a.width);
|
||||
this.image = Thumbnail.fromResponse(data.image);
|
||||
this.style = data.style;
|
||||
}
|
||||
}
|
||||
19
deno/src/parser/classes/DecoratedAvatarView.ts
Normal file
19
deno/src/parser/classes/DecoratedAvatarView.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { YTNode } from '../helpers.ts';
|
||||
import type { RawNode } from '../index.ts';
|
||||
import NavigationEndpoint from './NavigationEndpoint.ts';
|
||||
import AvatarView from './AvatarView.ts';
|
||||
|
||||
export default class DecoratedAvatarView extends YTNode {
|
||||
static type = 'DecoratedAvatarView';
|
||||
|
||||
avatar: AvatarView;
|
||||
a11y_label: string;
|
||||
on_tap_endpoint: NavigationEndpoint;
|
||||
|
||||
constructor(data: RawNode) {
|
||||
super();
|
||||
this.avatar = new AvatarView(data.avatar.avatarViewModel);
|
||||
this.a11y_label = data.a11yLabel;
|
||||
this.on_tap_endpoint = new NavigationEndpoint(data.rendererContext.commandContext.onTap.innertubeCommand);
|
||||
}
|
||||
}
|
||||
16
deno/src/parser/classes/DislikeButtonView.ts
Normal file
16
deno/src/parser/classes/DislikeButtonView.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { YTNode } from '../helpers.ts';
|
||||
import { Parser, type RawNode } from '../index.ts';
|
||||
import ToggleButtonView from './ToggleButtonView.ts';
|
||||
|
||||
export default class DislikeButtonView extends YTNode {
|
||||
static type = 'DislikeButtonView';
|
||||
|
||||
toggle_button: ToggleButtonView | null;
|
||||
dislike_entity_key: string;
|
||||
|
||||
constructor(data: RawNode) {
|
||||
super();
|
||||
this.toggle_button = Parser.parseItem(data.toggleButtonViewModel, ToggleButtonView);
|
||||
this.dislike_entity_key = data.dislikeEntityKey;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { YTNode } from '../helpers.ts';
|
||||
import { NavigationEndpoint } from '../nodes.ts';
|
||||
import NavigationEndpoint from './NavigationEndpoint.ts';
|
||||
import Text from './misc/Text.ts';
|
||||
|
||||
import type { RawNode } from '../types/index.ts';
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import NavigationEndpoint from './NavigationEndpoint.ts';
|
||||
import Thumbnail from './misc/Thumbnail.ts';
|
||||
import { YTNode, observe } from '../helpers.ts';
|
||||
import { type RawNode } from '../index.ts';
|
||||
|
||||
@@ -6,11 +7,7 @@ export class Panel extends YTNode {
|
||||
static type = 'Panel';
|
||||
|
||||
thumbnail?: {
|
||||
image: {
|
||||
url: string;
|
||||
width: number;
|
||||
height: number;
|
||||
}[];
|
||||
image: Thumbnail[];
|
||||
endpoint: NavigationEndpoint;
|
||||
on_long_press_endpoint: NavigationEndpoint;
|
||||
content_mode: string;
|
||||
@@ -18,16 +15,8 @@ export class Panel extends YTNode {
|
||||
};
|
||||
|
||||
background_image: {
|
||||
image: {
|
||||
url: string;
|
||||
width: number;
|
||||
height: number;
|
||||
}[];
|
||||
gradient_image: {
|
||||
url: string;
|
||||
width: number;
|
||||
height: number;
|
||||
}[];
|
||||
image: Thumbnail[];
|
||||
gradient_image: Thumbnail[];
|
||||
};
|
||||
|
||||
strapline: string;
|
||||
@@ -48,7 +37,7 @@ export class Panel extends YTNode {
|
||||
|
||||
if (data.thumbnail) {
|
||||
this.thumbnail = {
|
||||
image: data.thumbnail.image.sources,
|
||||
image: Thumbnail.fromResponse(data.thumbnail.image),
|
||||
endpoint: new NavigationEndpoint(data.thumbnail.onTap),
|
||||
on_long_press_endpoint: new NavigationEndpoint(data.thumbnail.onLongPress),
|
||||
content_mode: data.thumbnail.contentMode,
|
||||
@@ -57,8 +46,8 @@ export class Panel extends YTNode {
|
||||
}
|
||||
|
||||
this.background_image = {
|
||||
image: data.backgroundImage.image.sources,
|
||||
gradient_image: data.backgroundImage.gradientImage.sources
|
||||
image: Thumbnail.fromResponse(data.backgroundImage.image),
|
||||
gradient_image: Thumbnail.fromResponse(data.backgroundImage.gradientImage)
|
||||
};
|
||||
|
||||
this.strapline = data.strapline;
|
||||
|
||||
24
deno/src/parser/classes/LikeButtonView.ts
Normal file
24
deno/src/parser/classes/LikeButtonView.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { YTNode } from '../helpers.ts';
|
||||
import { Parser, type RawNode } from '../index.ts';
|
||||
import ToggleButtonView from './ToggleButtonView.ts';
|
||||
|
||||
export default class LikeButtonView extends YTNode {
|
||||
static type = 'LikeButtonView';
|
||||
|
||||
toggle_button: ToggleButtonView | null;
|
||||
like_status_entity_key: string;
|
||||
like_status_entity: {
|
||||
key: string,
|
||||
like_status: string
|
||||
};
|
||||
|
||||
constructor(data: RawNode) {
|
||||
super();
|
||||
this.toggle_button = Parser.parseItem(data.toggleButtonViewModel, ToggleButtonView);
|
||||
this.like_status_entity_key = data.likeStatusEntityKey;
|
||||
this.like_status_entity = {
|
||||
key: data.likeStatusEntity.key,
|
||||
like_status: data.likeStatusEntity.likeStatus
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import NavigationEndpoint from './NavigationEndpoint.ts';
|
||||
import Thumbnail from './misc/Thumbnail.ts';
|
||||
import { YTNode } from '../helpers.ts';
|
||||
import type { RawNode } from '../index.ts';
|
||||
|
||||
@@ -21,11 +22,7 @@ class ActionButton {
|
||||
class Panel {
|
||||
static type = 'Panel';
|
||||
|
||||
image: {
|
||||
url: string;
|
||||
width: number;
|
||||
height: number;
|
||||
}[];
|
||||
image: Thumbnail[];
|
||||
|
||||
content_mode: string;
|
||||
crop_options: string;
|
||||
@@ -34,7 +31,7 @@ class Panel {
|
||||
action_buttons: ActionButton[];
|
||||
|
||||
constructor (data: RawNode) {
|
||||
this.image = data.image.image.sources;
|
||||
this.image = Thumbnail.fromResponse(data.image.image);
|
||||
this.content_mode = data.image.contentMode;
|
||||
this.crop_options = data.image.cropOptions;
|
||||
this.image_aspect_ratio = data.imageAspectRatio;
|
||||
|
||||
@@ -2,6 +2,7 @@ import { YTNode } from '../helpers.ts';
|
||||
import { Parser, type RawNode } from '../index.ts';
|
||||
import ContentMetadataView from './ContentMetadataView.ts';
|
||||
import ContentPreviewImageView from './ContentPreviewImageView.ts';
|
||||
import DecoratedAvatarView from './DecoratedAvatarView.ts';
|
||||
import DynamicTextView from './DynamicTextView.ts';
|
||||
import FlexibleActionsView from './FlexibleActionsView.ts';
|
||||
|
||||
@@ -9,14 +10,14 @@ export default class PageHeaderView extends YTNode {
|
||||
static type = 'PageHeaderView';
|
||||
|
||||
title: DynamicTextView | null;
|
||||
image: ContentPreviewImageView | null;
|
||||
image: ContentPreviewImageView | DecoratedAvatarView | null;
|
||||
metadata: ContentMetadataView | null;
|
||||
actions: FlexibleActionsView | null;
|
||||
|
||||
constructor(data: RawNode) {
|
||||
super();
|
||||
this.title = Parser.parseItem(data.title, DynamicTextView);
|
||||
this.image = Parser.parseItem(data.image, ContentPreviewImageView);
|
||||
this.image = Parser.parseItem(data.image, [ ContentPreviewImageView, DecoratedAvatarView ]);
|
||||
this.metadata = Parser.parseItem(data.metadata, ContentMetadataView);
|
||||
this.actions = Parser.parseItem(data.actions, FlexibleActionsView);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ObservedArray} from '../helpers.ts';
|
||||
import type { ObservedArray } from '../helpers.ts';
|
||||
import { YTNode } from '../helpers.ts';
|
||||
import type { RawNode } from '../index.ts';
|
||||
import { Parser } from '../index.ts';
|
||||
|
||||
56
deno/src/parser/classes/SegmentedLikeDislikeButtonView.ts
Normal file
56
deno/src/parser/classes/SegmentedLikeDislikeButtonView.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { YTNode } from '../helpers.ts';
|
||||
import { Parser, type RawNode } from '../index.ts';
|
||||
import LikeButtonView from './LikeButtonView.ts';
|
||||
import DislikeButtonView from './DislikeButtonView.ts';
|
||||
|
||||
export default class SegmentedLikeDislikeButtonView extends YTNode {
|
||||
static type = 'SegmentedLikeDislikeButtonView';
|
||||
|
||||
like_button: LikeButtonView | null;
|
||||
dislike_button: DislikeButtonView | null;
|
||||
icon_type: string;
|
||||
like_count_entity: {
|
||||
key: string
|
||||
};
|
||||
dynamic_like_count_update_data: {
|
||||
update_status_key: string,
|
||||
placeholder_like_count_values_key: string,
|
||||
update_delay_loop_id: string,
|
||||
update_delay_sec: number
|
||||
};
|
||||
|
||||
like_count?: number;
|
||||
short_like_count?: string;
|
||||
|
||||
constructor(data: RawNode) {
|
||||
super();
|
||||
this.like_button = Parser.parseItem(data.likeButtonViewModel, LikeButtonView);
|
||||
this.dislike_button = Parser.parseItem(data.dislikeButtonViewModel, DislikeButtonView);
|
||||
this.icon_type = data.iconType;
|
||||
|
||||
if (this.like_button && this.like_button.toggle_button) {
|
||||
const toggle_button = this.like_button.toggle_button;
|
||||
|
||||
if (toggle_button.default_button) {
|
||||
this.short_like_count = toggle_button.default_button.title;
|
||||
|
||||
this.like_count = parseInt(toggle_button.default_button.accessibility_text.replace(/\D/g, ''));
|
||||
} else if (toggle_button.toggled_button) {
|
||||
this.short_like_count = toggle_button.toggled_button.title;
|
||||
|
||||
this.like_count = parseInt(toggle_button.toggled_button.accessibility_text.replace(/\D/g, ''));
|
||||
}
|
||||
}
|
||||
|
||||
this.like_count_entity = {
|
||||
key: data.likeCountEntity.key
|
||||
};
|
||||
|
||||
this.dynamic_like_count_update_data = {
|
||||
update_status_key: data.dynamicLikeCountUpdateData.updateStatusKey,
|
||||
placeholder_like_count_values_key: data.dynamicLikeCountUpdateData.placeholderLikeCountValuesKey,
|
||||
update_delay_loop_id: data.dynamicLikeCountUpdateData.updateDelayLoopId,
|
||||
update_delay_sec: data.dynamicLikeCountUpdateData.updateDelaySec
|
||||
};
|
||||
}
|
||||
}
|
||||
20
deno/src/parser/classes/ToggleButtonView.ts
Normal file
20
deno/src/parser/classes/ToggleButtonView.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { YTNode } from '../helpers.ts';
|
||||
import { Parser, type RawNode } from '../index.ts';
|
||||
import ButtonView from './ButtonView.ts';
|
||||
|
||||
export default class ToggleButtonView extends YTNode {
|
||||
static type = 'ToggleButtonView';
|
||||
|
||||
default_button: ButtonView | null;
|
||||
toggled_button: ButtonView | null;
|
||||
identifier?: string;
|
||||
is_toggling_disabled: boolean;
|
||||
|
||||
constructor(data: RawNode) {
|
||||
super();
|
||||
this.default_button = Parser.parseItem(data.defaultButtonViewModel, ButtonView);
|
||||
this.toggled_button = Parser.parseItem(data.toggledButtonViewModel, ButtonView);
|
||||
this.identifier = data.identifier;
|
||||
this.is_toggling_disabled = data.isTogglingDisabled;
|
||||
}
|
||||
}
|
||||
@@ -10,9 +10,7 @@ import Thumbnail from './misc/Thumbnail.ts';
|
||||
export default class VideoAttributeView extends YTNode {
|
||||
static type = 'VideoAttributeView';
|
||||
|
||||
image: ContentPreviewImageView | {
|
||||
sources: Thumbnail[];
|
||||
} | null;
|
||||
image: ContentPreviewImageView | Thumbnail[] | null;
|
||||
image_style: string;
|
||||
title: string;
|
||||
subtitle: string;
|
||||
@@ -26,11 +24,9 @@ export default class VideoAttributeView extends YTNode {
|
||||
|
||||
constructor(data: RawNode) {
|
||||
super();
|
||||
// @NOTE: "image" is not a renderer so not sure why we're parsing it as one. Leaving this hack here for now to avoid breaking things.
|
||||
|
||||
if (data.image?.sources) {
|
||||
this.image = {
|
||||
sources: data.image.sources.map((x: any) => new Thumbnail(x)).sort((a: Thumbnail, b: Thumbnail) => b.width - a.width)
|
||||
};
|
||||
this.image = Thumbnail.fromResponse(data.image);
|
||||
} else {
|
||||
this.image = Parser.parseItem(data.image, ContentPreviewImageView);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ObservedArray} from '../helpers.ts';
|
||||
import type { ObservedArray } from '../helpers.ts';
|
||||
import { YTNode } from '../helpers.ts';
|
||||
import type { RawNode } from '../index.ts';
|
||||
import { Parser } from '../index.ts';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ObservedArray} from '../helpers.ts';
|
||||
import type { ObservedArray } from '../helpers.ts';
|
||||
import { YTNode } from '../helpers.ts';
|
||||
import { Parser, type RawNode } from '../index.ts';
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Parser } from '../../index.ts';
|
||||
import type { ObservedArray} from '../../helpers.ts';
|
||||
import type { ObservedArray } from '../../helpers.ts';
|
||||
import { YTNode } from '../../helpers.ts';
|
||||
import type { RawNode } from '../../index.ts';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ObservedArray} from '../../helpers.ts';
|
||||
import type { ObservedArray } from '../../helpers.ts';
|
||||
import { YTNode } from '../../helpers.ts';
|
||||
import type { RawNode } from '../../index.ts';
|
||||
import { Parser } from '../../index.ts';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ObservedArray} from '../../helpers.ts';
|
||||
import type { ObservedArray } from '../../helpers.ts';
|
||||
import { YTNode } from '../../helpers.ts';
|
||||
import type { RawNode } from '../../index.ts';
|
||||
import { Parser } from '../../index.ts';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { SuperParsedResult} from '../../helpers.ts';
|
||||
import type { SuperParsedResult } from '../../helpers.ts';
|
||||
import { YTNode } from '../../helpers.ts';
|
||||
import type { RawNode } from '../../index.ts';
|
||||
import { Parser } from '../../index.ts';
|
||||
|
||||
@@ -15,7 +15,20 @@ export default class Thumbnail {
|
||||
* Get thumbnails from response object.
|
||||
*/
|
||||
static fromResponse(data: any): Thumbnail[] {
|
||||
if (!data || !data.thumbnails) return [];
|
||||
return data.thumbnails.map((x: any) => new Thumbnail(x)).sort((a: Thumbnail, b: Thumbnail) => b.width - a.width);
|
||||
if (!data) return [];
|
||||
|
||||
let thumbnail_data;
|
||||
|
||||
if (data.thumbnails) {
|
||||
thumbnail_data = data.thumbnails;
|
||||
} else if (data.sources) {
|
||||
thumbnail_data = data.sources;
|
||||
}
|
||||
|
||||
if (thumbnail_data) {
|
||||
return thumbnail_data.map((x: any) => new Thumbnail(x)).sort((a: Thumbnail, b: Thumbnail) => b.width - a.width);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user