Files
YouTube.js/lib/parser/contents/classes/Author.js
LuanRT 1d62e469a9 refactor: rewrite Comments Section logic (#88)
* feat: add core comments section classes

* chore: update type declarations

* chore: fix linter warnings

* style: fix linter

* chore: update tests

* chore(tests): fix typo

* chore(tests): fix typo x2

* fix(tests): `getReplies()` method is only present in `CommentThread` and not `Comment`

* chore(tests): fix comment id path

* chore(tests): remove outdated code

* chore(tests): fix results path

* chore: enforce code style

* chore: update type declarations

* docs: add examples and documentation

* chore(docs): fix paths

* chore(docs): fix more paths

* chore(docs): fix `Comments.js` path

* chore(docs): fix typo

* chore(docs): mention example file

* chore(examples): fix imports

* chore(examples): fix typo
2022-07-02 19:55:33 -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;