@twitchfy/chatbot
Version:
A powerful node module to make your own Twitch ChatBot
105 lines (104 loc) • 2.7 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Video = void 0;
const Base_1 = require("./Base");
const BaseUser_1 = require("./BaseUser");
const util_1 = require("../util");
/**
* Represents a Twitch video.
*/
class Video extends Base_1.Base {
/**
* The id of the video.
*/
id;
/**
* The id of the stream the video was created from. If the stream was ended this will be null.
*/
streamId;
/**
* The user who created the video.
*/
user;
/**
* The title of the video.
*/
title;
/**
* The description of the video.
*/
description;
/**
* The video's url.
*/
url;
/**
* The number of views the video has.
*/
viewCount;
/**
* The language of the video.
*/
language;
/**
* The type of the video.
*/
type;
/**
* The muted segments of the video.
*/
mutedSegments;
/**
* The data of the video from the API.
*/
data;
constructor(chatbot, data) {
super(chatbot);
this.data = data;
this.id = data.id;
this.streamId = data.stream_id;
this.user = new BaseUser_1.BaseUser(chatbot, { id: data.user_id, login: data.user_login, display_name: data.user_name });
this.title = data.title;
this.description = data.description;
this.url = data.url;
this.viewCount = data.view_count;
this.language = data.language;
this.type = data.type;
this.mutedSegments = data.muted_segments;
}
/**
* The creation date of the video in JavaScript Date object.
*/
get createdAt() {
return new Date(this.data.created_at);
}
/**
* The publish date of the video in JavaScript Date object.
*/
get publishedAt() {
return new Date(this.data.published_at);
}
/**
* The thumbnail URL of the video.
* @param options The options for the thumbnail.
* @returns The thumbnail URL of the video.
*/
thumbnailURL(options) {
return this.data.thumbnail_url.replace('%{width}', options?.width?.toString() || '1920').replace('%{height}', options?.height?.toString() || '1080');
}
/**
* The duration of the video in seconds.
*/
get duration() {
let duration = 0;
const regex = new RegExp(/(\d+[a-zA-Z]+)/g);
const split = this.data.duration.split(regex);
for (const value of split) {
const time = (0, util_1.parseTime)(value);
if (time)
duration += time;
}
return duration / 1000;
}
}
exports.Video = Video;