diff --git a/src/parser/classes/CompactMovie.ts b/src/parser/classes/CompactMovie.ts new file mode 100644 index 000000000..7b2d18d7e --- /dev/null +++ b/src/parser/classes/CompactMovie.ts @@ -0,0 +1,57 @@ +import { YTNode, type ObservedArray } from '../helpers.js'; +import type { RawNode } from '../index.js'; +import Parser from '../index.js'; +import Author from './misc/Author.js'; +import NavigationEndpoint from './NavigationEndpoint.js'; +import Thumbnail from './misc/Thumbnail.js'; +import Menu from './menus/Menu.js'; +import { timeToSeconds } from '../../utils/Utils.js'; + +export default class CompactMovie extends YTNode { + static type = 'CompactMovie'; + + id: string; + title: Text; + top_metadata_items: Text; + thumbnails: Thumbnail[]; + thumbnail_overlays: ObservedArray; + author: Author; + + duration: { + text: string; + seconds: number; + }; + + endpoint: NavigationEndpoint; + badges: ObservedArray; + use_vertical_poster: boolean; + menu: Menu | null; + + constructor(data: RawNode) { + super(); + console.log(data); + const overlay_time_status = data.thumbnailOverlays + .find((overlay: RawNode) => overlay.thumbnailOverlayTimeStatusRenderer) + ?.thumbnailOverlayTimeStatusRenderer.text || 'N/A'; + + this.id = data.videoId; + this.title = new Text(data.title); + + this.top_metadata_items = new Text(data.topMetadataItems); + this.thumbnails = Thumbnail.fromResponse(data.thumbnail); + this.thumbnail_overlays = Parser.parseArray(data.thumbnailOverlays); + this.author = new Author(data.shortBylineText); + + const durationText = data.lengthText ? new Text(data.lengthText).toString() : new Text(overlay_time_status).toString(); + + this.duration = { + text: durationText, + seconds: timeToSeconds(durationText) + }; + + this.endpoint = new NavigationEndpoint(data.navigationEndpoint); + this.badges = Parser.parseArray(data.badges); + this.use_vertical_poster = data.useVerticalPoster; + this.menu = Parser.parseItem(data.menu, Menu); + } +} \ No newline at end of file diff --git a/src/parser/nodes.ts b/src/parser/nodes.ts index a99185fd2..497245725 100644 --- a/src/parser/nodes.ts +++ b/src/parser/nodes.ts @@ -69,6 +69,7 @@ export { default as SponsorCommentBadge } from './classes/comments/SponsorCommen export { default as CompactChannel } from './classes/CompactChannel.js'; export { default as CompactLink } from './classes/CompactLink.js'; export { default as CompactMix } from './classes/CompactMix.js'; +export { default as CompactMovie } from './classes/CompactMovie.js'; export { default as CompactPlaylist } from './classes/CompactPlaylist.js'; export { default as CompactStation } from './classes/CompactStation.js'; export { default as CompactVideo } from './classes/CompactVideo.js';