2021-04-08 19:42:08 +05:00
|
|
|
import { ExtractorModelData } from '../types/types';
|
2021-04-08 18:03:04 +05:00
|
|
|
|
|
|
|
class ExtractorModel {
|
|
|
|
name: string;
|
|
|
|
private _raw: any;
|
|
|
|
|
2021-04-19 18:32:10 +05:00
|
|
|
/**
|
|
|
|
* Model for raw Discord Player extractors
|
2021-04-21 11:52:59 +05:00
|
|
|
* @param {String} extractorName Name of the extractor
|
2021-04-21 10:08:33 +05:00
|
|
|
* @param {Object} data Extractor object
|
2021-04-19 18:32:10 +05:00
|
|
|
*/
|
2021-04-08 18:03:04 +05:00
|
|
|
constructor(extractorName: string, data: any) {
|
2021-04-19 18:32:10 +05:00
|
|
|
/**
|
|
|
|
* The extractor name
|
2021-04-21 11:52:59 +05:00
|
|
|
* @type {String}
|
2021-04-19 18:32:10 +05:00
|
|
|
*/
|
2021-04-08 18:03:04 +05:00
|
|
|
this.name = extractorName;
|
|
|
|
|
2021-04-08 19:42:08 +05:00
|
|
|
Object.defineProperty(this, '_raw', { value: data, configurable: false, writable: false, enumerable: false });
|
2021-04-08 18:03:04 +05:00
|
|
|
}
|
|
|
|
|
2021-04-19 18:32:10 +05:00
|
|
|
/**
|
|
|
|
* Method to handle requests from `Player.play()`
|
2021-04-21 11:52:59 +05:00
|
|
|
* @param {String} query Query to handle
|
2021-04-19 18:32:10 +05:00
|
|
|
*/
|
|
|
|
async handle(query: string): Promise<ExtractorModelData> {
|
2021-04-08 18:03:04 +05:00
|
|
|
const data = await this._raw.getInfo(query);
|
|
|
|
if (!data) return null;
|
|
|
|
|
|
|
|
return {
|
|
|
|
title: data.title,
|
|
|
|
duration: data.duration,
|
|
|
|
thumbnail: data.thumbnail,
|
|
|
|
engine: data.engine,
|
|
|
|
views: data.views,
|
|
|
|
author: data.author,
|
|
|
|
description: data.description,
|
|
|
|
url: data.url
|
2021-04-19 18:32:10 +05:00
|
|
|
};
|
2021-04-08 18:03:04 +05:00
|
|
|
}
|
|
|
|
|
2021-04-19 18:32:10 +05:00
|
|
|
/**
|
|
|
|
* Method used by Discord Player to validate query with this extractor
|
2021-04-21 11:52:59 +05:00
|
|
|
* @param {String} query The query to validate
|
2021-04-19 18:32:10 +05:00
|
|
|
*/
|
|
|
|
validate(query: string): boolean {
|
2021-04-08 18:03:04 +05:00
|
|
|
return Boolean(this._raw.validate(query));
|
|
|
|
}
|
|
|
|
|
2021-04-19 18:32:10 +05:00
|
|
|
/**
|
|
|
|
* The extractor version
|
2021-04-21 11:52:59 +05:00
|
|
|
* @type {String}
|
2021-04-19 18:32:10 +05:00
|
|
|
*/
|
|
|
|
get version(): string {
|
2021-04-08 19:42:08 +05:00
|
|
|
return this._raw.version ?? '0.0.0';
|
2021-04-08 18:03:04 +05:00
|
|
|
}
|
|
|
|
|
2021-04-19 18:32:10 +05:00
|
|
|
/**
|
|
|
|
* If player should mark this extractor as important
|
2021-04-21 11:52:59 +05:00
|
|
|
* @type {Boolean}
|
2021-04-19 18:32:10 +05:00
|
|
|
*/
|
|
|
|
get important(): boolean {
|
2021-04-08 18:03:04 +05:00
|
|
|
return Boolean(this._raw.important);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ExtractorModel;
|
2021-04-08 19:42:08 +05:00
|
|
|
export { ExtractorModel };
|