mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-16 19:12:24 +00:00
40 lines
1.4 KiB
JavaScript
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; |