mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-30 09:55:18 +00:00
refactor!: finish parser migration
Finally! :) This removes all code related to the old parser. #65
This commit is contained in:
40
lib/parser/classes/Author.js
Normal file
40
lib/parser/classes/Author.js
Normal file
@@ -0,0 +1,40 @@
|
||||
'use strict';
|
||||
|
||||
const Parser = require('..');
|
||||
const NavigatableText = require('./NavigatableText');
|
||||
const Thumbnail = require('./Thumbnail');
|
||||
const Constants = require('../../utils/Constants');
|
||||
|
||||
class Author {
|
||||
#nav_text;
|
||||
|
||||
constructor(item, badges, thumbs) {
|
||||
this.#nav_text = new NavigatableText(item);
|
||||
|
||||
this.id =
|
||||
this.#nav_text.runs?.[0].endpoint.browse?.id ||
|
||||
this.#nav_text.endpoint?.browse?.id || 'N/A';
|
||||
|
||||
this.name = this.#nav_text.text || 'N/A';
|
||||
this.thumbnails = thumbs ? Thumbnail.fromResponse(thumbs) : [];
|
||||
this.endpoint = this.#nav_text.runs?.[0].endpoint || this.#nav_text.endpoint;
|
||||
this.badges = Array.isArray(badges) ? Parser.parse(badges) : [];
|
||||
this.is_verified = this.badges?.some((badge) => badge.style == 'BADGE_STYLE_TYPE_VERIFIED') || null;
|
||||
this.is_verified_artist = this.badges?.some((badge) => badge.style == 'BADGE_STYLE_TYPE_VERIFIED_ARTIST') || null;
|
||||
|
||||
this.url =
|
||||
this.#nav_text.runs?.[0].endpoint.browse &&
|
||||
`${Constants.URLS.YT_BASE}${this.#nav_text.runs[0].endpoint.browse?.base_url || `/u/${this.#nav_text.runs[0].endpoint.browse?.id}`}` ||
|
||||
`${Constants.URLS.YT_BASE}${this.#nav_text.endpoint?.browse?.base_url || `/u/${this.#nav_text.endpoint?.browse?.id}`}` ||
|
||||
null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {Thumbnail | undefined}
|
||||
*/
|
||||
get best_thumbnail() {
|
||||
return this.thumbnails[0];
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Author;
|
||||
Reference in New Issue
Block a user