mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-20 04:51:16 +00:00
feat: add YouTube livechat renderers
Next up: refactor old livechat parser
This commit is contained in:
25
lib/parser/contents/classes/LiveChat.js
Normal file
25
lib/parser/contents/classes/LiveChat.js
Normal file
@@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
const Parser = require('..');
|
||||
const Text = require('./Text');
|
||||
|
||||
class LiveChat {
|
||||
type = 'LiveChat';
|
||||
|
||||
constructor(data) {
|
||||
this.header = Parser.parse(data.header);
|
||||
|
||||
this.initial_display_state = data.initialDisplayState;
|
||||
this.continuation = data.continuations[0]?.reloadContinuationData?.continuation;
|
||||
|
||||
this.client_messages = {
|
||||
reconnect_message: new Text(data.clientMessages.reconnectMessage),
|
||||
unable_to_reconnect_message: new Text(data.clientMessages.unableToReconnectMessage),
|
||||
fatal_error: new Text(data.clientMessages.fatalError),
|
||||
reconnected_message: new Text(data.clientMessages.reconnectedMessage),
|
||||
generic_error: new Text(data.clientMessages.genericError)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = LiveChat;
|
||||
15
lib/parser/contents/classes/LiveChatHeader.js
Normal file
15
lib/parser/contents/classes/LiveChatHeader.js
Normal file
@@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
const Parser = require('..');
|
||||
|
||||
class LiveChatHeader {
|
||||
type = 'LiveChatHeader';
|
||||
|
||||
constructor(data) {
|
||||
this.overflow_menu = Parser.parse(data.overflowMenu);
|
||||
this.collapse_button = Parser.parse(data.collapseButton);
|
||||
this.view_selector = Parser.parse(data.viewSelector);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = LiveChatHeader;
|
||||
20
lib/parser/contents/classes/SortFilterSubMenu.js
Normal file
20
lib/parser/contents/classes/SortFilterSubMenu.js
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
const { observe } = require('../../../utils/Utils');
|
||||
|
||||
class SortFilterSubMenu {
|
||||
type = 'SortFilterSubMenu';
|
||||
|
||||
constructor(data) {
|
||||
this.sub_menu_items = observe(data.subMenuItems.map((item) => ({
|
||||
title: item.title,
|
||||
selected: item.selected,
|
||||
continuation: item.continuation?.reloadContinuationData.continuation,
|
||||
subtitle: item.subtitle
|
||||
})));
|
||||
|
||||
this.label = data.accessibility.accessibilityData.label;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SortFilterSubMenu;
|
||||
@@ -34,7 +34,7 @@ class VideoInfo {
|
||||
|
||||
if (info.playability_status.status === 'ERROR')
|
||||
throw new InnertubeError('This video is unavailable', info.playability_status);
|
||||
|
||||
|
||||
/**
|
||||
* @type {import('../contents/classes/VideoDetails')}
|
||||
*/
|
||||
@@ -122,7 +122,12 @@ class VideoInfo {
|
||||
/**
|
||||
* @type {import('../contents/classes/CommentsEntryPointHeader')}
|
||||
*/
|
||||
this.comments_entry_point_header = comments_entry_point?.contents.get({ type: 'CommentsEntryPointHeader' }) || {};
|
||||
this.comments_entry_point_header = comments_entry_point?.contents.get({ type: 'CommentsEntryPointHeader' }) || null;
|
||||
|
||||
/**
|
||||
* @type {import('../contents/classes/LiveChat')}
|
||||
*/
|
||||
this.livechat = next.contents_memo.get('LiveChat')?.[0] || null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user