mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-07-04 12:47:04 +00:00
feat: add merchandise parser
This commit is contained in:
17
lib/parser/contents/classes/EmergencyOnebox.js
Normal file
17
lib/parser/contents/classes/EmergencyOnebox.js
Normal file
@@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
const Text = require('./Text');
|
||||
const Parser = require('..');
|
||||
const NavigationEndpoint = require('./NavigationEndpoint');
|
||||
|
||||
class EmergencyOnebox {
|
||||
type = 'emergencyOneboxRenderer';
|
||||
|
||||
constructor(data) {
|
||||
this.title = new Text(data.title);
|
||||
this.first_option = Parser.parse(data.firstOption);
|
||||
this.menu = Parser.parse(data.menu);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = EmergencyOnebox;
|
||||
25
lib/parser/contents/classes/MerchandiseItem.js
Normal file
25
lib/parser/contents/classes/MerchandiseItem.js
Normal file
@@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
const Text = require('./Text');
|
||||
const Thumbnail = require('./Thumbnail');
|
||||
const NavigationEndpoint = require('./NavigationEndpoint');
|
||||
|
||||
class MerchandiseItem {
|
||||
type = 'merchandiseItemRenderer';
|
||||
|
||||
constructor(data) {
|
||||
this.title = data.title;
|
||||
this.description = data.description;
|
||||
this.thumbnails = new Thumbnail(data.thumbnail).thumbnails;
|
||||
this.price = data.price;
|
||||
this.vendor_name = data.vendorName;
|
||||
this.button_text = data.buttonText;
|
||||
this.button_accessibility_text = data.buttonAccessibilityText;
|
||||
this.from_vendor_text = data.fromVendorText;
|
||||
this.additional_fees_text = data.additionalFeesText;
|
||||
this.region_format = data.regionFormat;
|
||||
this.endpoint = new NavigationEndpoint(data.buttonCommand);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MerchandiseItem;
|
||||
15
lib/parser/contents/classes/MerchandiseShelf.js
Normal file
15
lib/parser/contents/classes/MerchandiseShelf.js
Normal file
@@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
const Parser = require('..');
|
||||
|
||||
class MerchandiseShelf {
|
||||
type = 'merchandiseShelfRenderer';
|
||||
|
||||
constructor(data) {
|
||||
this.title = data.title;
|
||||
this.menu = Parser.parse(data.actionButton);
|
||||
this.items = Parser.parse(data.items);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MerchandiseShelf;
|
||||
@@ -8,13 +8,20 @@ class NavigationEndpoint {
|
||||
constructor(data) {
|
||||
data?.serviceEndpoint &&
|
||||
(data = data.serviceEndpoint);
|
||||
|
||||
this.metadata = {
|
||||
url: data?.commandMetadata?.webCommandMetadata.url || null,
|
||||
page_type: data?.commandMetadata?.webCommandMetadata.webPageType || null,
|
||||
api_url: data?.commandMetadata?.webCommandMetadata.apiUrl || null,
|
||||
send_post: data?.commandMetadata?.webCommandMetadata.sendPost || null
|
||||
}
|
||||
|
||||
this.metadata = {};
|
||||
|
||||
data?.commandMetadata?.webCommandMetadata?.url &&
|
||||
(this.metadata.url = data.commandMetadata.webCommandMetadata.url);
|
||||
|
||||
data?.commandMetadata?.webCommandMetadata?.webPageType &&
|
||||
(this.metadata.page_type = data.commandMetadata.webCommandMetadata.webPageType);
|
||||
|
||||
data?.commandMetadata?.webCommandMetadata?.apiUrl &&
|
||||
(this.metadata.api_url = data.commandMetadata.webCommandMetadata.apiUrl);
|
||||
|
||||
data?.commandMetadata?.webCommandMetadata?.sendPost &&
|
||||
(this.metadata.send_post = data.commandMetadata.webCommandMetadata.sendPost);
|
||||
|
||||
if (data?.browseEndpoint) {
|
||||
this.browse = {
|
||||
|
||||
19
lib/parser/contents/classes/PlayerErrorMessage.js
Normal file
19
lib/parser/contents/classes/PlayerErrorMessage.js
Normal file
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
const Parser = require('..');
|
||||
const Text = require('./Text');
|
||||
const Thumbnail = require('./Thumbnail');
|
||||
|
||||
class PlayerErrorMessage {
|
||||
type = 'playerErrorMessageRenderer';
|
||||
|
||||
constructor(data) {
|
||||
this.subreason = new Text(data.subreason);
|
||||
this.reason = new Text(data.reason);
|
||||
this.proceed_button = Parser.parse(data.proceedButton);
|
||||
this.thumbnails = new Thumbnail(data.thumbnail).thumbnails;
|
||||
this.icon_type = data.icon.iconType;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PlayerErrorMessage;
|
||||
18
lib/parser/contents/classes/SingleActionEmergencySupport.js
Normal file
18
lib/parser/contents/classes/SingleActionEmergencySupport.js
Normal file
@@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
const Text = require('./Text');
|
||||
const NavigationEndpoint = require('./NavigationEndpoint');
|
||||
|
||||
class SingleActionEmergencySupport {
|
||||
type = 'singleActionEmergencySupportRenderer';
|
||||
|
||||
constructor(data) {
|
||||
this.action_text = new Text(data.actionText);
|
||||
this.nav_text = new Text(data.navigationText);
|
||||
this.details = new Text(data.detailsText);
|
||||
this.icon_type = data.icon.iconType;
|
||||
this.endpoint = new NavigationEndpoint(data.navigationEndpoint);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SingleActionEmergencySupport;
|
||||
@@ -16,11 +16,11 @@ class TwoColumnWatchNextResults {
|
||||
}
|
||||
|
||||
get secondary_results() {
|
||||
return Parser.parse(this.#data.secondaryResults.secondaryResults.results);
|
||||
return Parser.parse(this.#data.secondaryResults?.secondaryResults.results);
|
||||
}
|
||||
|
||||
get conversation_bar() {
|
||||
return Parser.parse(this.#data.conversationBar);
|
||||
return Parser.parse(this.#data?.conversationBar);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user