dev: check if renderer should be ignore before parsing

Will mostly be used to ignore ad renderers.
This commit is contained in:
LuanRT
2022-06-10 04:32:24 -03:00
parent 9840acc63d
commit 53965630b7
3 changed files with 27 additions and 4 deletions

View File

@@ -0,0 +1,13 @@
'use strict';
const Text = require('./Text');
class Message {
type = 'messageRenderer'
constructor(data) {
this.text = new Text(data.text);
}
}
module.exports = Message;

View File

@@ -91,7 +91,9 @@ class Parser {
for (let item of data) {
const keys = Object.keys(item);
const classname = this.sanitizeClassName(keys[0]);
if (this.shouldIgnore(classname)) return;
try {
const TargetClass = require('./classes/' + classname);
results.push(new TargetClass(item[keys[0]], ctx));
@@ -106,6 +108,8 @@ class Parser {
const keys = Object.keys(data);
const classname = this.sanitizeClassName(keys[0]);
if (this.shouldIgnore(classname)) return;
try {
const TargetClass = require('./classes/' + classname);
return new TargetClass(data[keys[0]], ctx);
@@ -136,6 +140,12 @@ class Parser {
.replace(/Renderer|Model/g, '')
.replace(/Radio/g, 'Mix').trim();
}
static shouldIgnore(classname) {
return [
'PromotedSparklesWeb'
].includes(classname);
}
}
module.exports = Parser;

View File

@@ -63,7 +63,7 @@ class VideoInfo {
/**
* @type {import('../contents/classes/MerchandiseShelf')}
*/
this.merchandise = results?.get({ type: 'merchandiseShelfRenderer' });
this.merchandise = results?.get({ type: 'merchandiseShelfRenderer' }) || {};
/**
* @type {import('../contents/classes/ChipCloud')}
@@ -140,7 +140,7 @@ class VideoInfo {
/**
* Retrieves watch next feed continuation.
* @returns {Promise.<CompactVideo[]>}
* @returns {Promise.<CompactVideo[] | CompactMix[]>}
*/
async getWatchNextContinuation() {
const response = await this.#watch_next_continuation.endpoint.call(this.#actions);
@@ -154,7 +154,7 @@ class VideoInfo {
/** @type {string} */
get filters() {
return this.related_chip_cloud.chips.map((chip) => chip.text);
return this.related_chip_cloud?.chips.map((chip) => chip.text) || [];
}
get page() {