refactor: clean up parser and tests (#387)

* tests: improve coverage

* refactor: clean up nodes

* chore: lint

* feat(parser): ignore `BrandVideoShelf`

Seems to be used for ads.

* feat(parser): ignore `BrandVideoSingleton` too
This commit is contained in:
LuanRT
2023-04-23 06:37:33 -03:00
committed by GitHub
parent f66f0bd656
commit 257bd475a0
358 changed files with 2823 additions and 3126 deletions

View File

@@ -1,22 +1,23 @@
import { YTNode } from '../helpers.js';
import type { RawNode } from '../index.js';
import Text from './misc/Text.js';
import Thumbnail from './misc/Thumbnail.js';
import { YTNode } from '../helpers.js';
class PlayerMicroformat extends YTNode {
export default class PlayerMicroformat extends YTNode {
static type = 'PlayerMicroformat';
title: Text;
description: Text;
thumbnails;
embed: {
embed?: {
iframe_url: string;
flash_url: string;
flash_secure_url: string;
// TODO: check these
width: any;
height: any;
} | null;
};
length_seconds: number;
@@ -36,13 +37,13 @@ class PlayerMicroformat extends YTNode {
available_countries: string[];
start_timestamp: Date | null;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.title = new Text(data.title);
this.description = new Text(data.description);
this.thumbnails = Thumbnail.fromResponse(data.thumbnail);
if (data.embed) {
if (Reflect.has(data, 'embed')) {
this.embed = {
iframe_url: data.embed.iframeUrl,
flash_url: data.embed.flashUrl,
@@ -50,8 +51,6 @@ class PlayerMicroformat extends YTNode {
width: data.embed.width,
height: data.embed.height
};
} else {
this.embed = null;
}
this.length_seconds = parseInt(data.lengthSeconds);
@@ -72,6 +71,4 @@ class PlayerMicroformat extends YTNode {
this.available_countries = data.availableCountries;
this.start_timestamp = data.liveBroadcastDetails?.startTimestamp ? new Date(data.liveBroadcastDetails.startTimestamp) : null;
}
}
export default PlayerMicroformat;
}