mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-17 11:32:27 +00:00
* tests: improve coverage * refactor: clean up nodes * chore: lint * feat(parser): ignore `BrandVideoShelf` Seems to be used for ads. * feat(parser): ignore `BrandVideoSingleton` too
48 lines
1.7 KiB
TypeScript
48 lines
1.7 KiB
TypeScript
import { YTNode } from '../helpers.js';
|
|
import type { RawNode } from '../index.js';
|
|
import NavigationEndpoint from './NavigationEndpoint.js';
|
|
import Text from './misc/Text.js';
|
|
import Thumbnail from './misc/Thumbnail.js';
|
|
|
|
export default class Poll extends YTNode {
|
|
static type = 'Poll';
|
|
|
|
choices: {
|
|
text: Text;
|
|
select_endpoint: NavigationEndpoint | null;
|
|
deselect_endpoint: NavigationEndpoint | null;
|
|
vote_ratio_if_selected: number | null;
|
|
vote_percentage_if_selected: Text;
|
|
vote_ratio_if_not_selected: number | null;
|
|
vote_percentage_if_not_selected: Text;
|
|
image: Thumbnail[] | null;
|
|
}[];
|
|
|
|
poll_type?: string;
|
|
total_votes?: Text;
|
|
live_chat_poll_id?: string;
|
|
|
|
constructor(data: RawNode) {
|
|
super();
|
|
|
|
this.choices = data.choices.map((choice: RawNode) => ({
|
|
text: new Text(choice.text),
|
|
select_endpoint: choice.selectServiceEndpoint ? new NavigationEndpoint(choice.selectServiceEndpoint) : null,
|
|
deselect_endpoint: choice.deselectServiceEndpoint ? new NavigationEndpoint(choice.deselectServiceEndpoint) : null,
|
|
vote_ratio_if_selected: choice?.voteRatioIfSelected || null,
|
|
vote_percentage_if_selected: new Text(choice.votePercentageIfSelected),
|
|
vote_ratio_if_not_selected: choice?.voteRatioIfSelected || null,
|
|
vote_percentage_if_not_selected: new Text(choice.votePercentageIfSelected),
|
|
image: choice.image ? Thumbnail.fromResponse(choice.image) : null
|
|
}));
|
|
|
|
if (Reflect.has(data, 'type'))
|
|
this.poll_type = data.type;
|
|
|
|
if (Reflect.has(data, 'totalVotes'))
|
|
this.total_votes = new Text(data.totalVotes);
|
|
|
|
if (Reflect.has(data, 'liveChatPollId'))
|
|
this.live_chat_poll_id = data.liveChatPollId;
|
|
}
|
|
} |