mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-30 09:55:18 +00:00
dev: check if renderer should be ignore before parsing
Will mostly be used to ignore ad renderers.
This commit is contained in:
13
lib/parser/contents/classes/Message.js
Normal file
13
lib/parser/contents/classes/Message.js
Normal 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;
|
||||
@@ -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;
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user