Files
YouTube.js/lib/parser/contents/classes/Author.js
LuanRT 748e34758f feat: tidy things up and implement more renderers
- Finished Library parser
- Fixed search continuations
- Improved channel parser
- Improved playlist parser
- Added support for posts of type poll
- Improved History parser
- Removed redundant code
2022-06-20 03:02:42 -03:00

40 lines
1.4 KiB
JavaScript

'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;