discord-player-play-dl/src/Structures/ExtractorModel.ts

70 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-06-11 15:32:22 +05:00
import { ExtractorModelData } from "../types/types";
class ExtractorModel {
name: string;
private _raw: any;
/**
* Model for raw Discord Player extractors
2021-06-13 10:55:20 +05:00
* @param {string} extractorName Name of the extractor
* @param {object} data Extractor object
2021-06-11 15:32:22 +05:00
*/
constructor(extractorName: string, data: any) {
/**
* The extractor name
2021-06-13 10:55:20 +05:00
* @type {string}
2021-06-11 15:32:22 +05:00
*/
this.name = extractorName;
Object.defineProperty(this, "_raw", { value: data, configurable: false, writable: false, enumerable: false });
}
/**
* Method to handle requests from `Player.play()`
2021-06-13 10:55:20 +05:00
* @param {string} query Query to handle
2021-06-11 15:32:22 +05:00
* @returns {Promise<ExtractorModelData>}
*/
async handle(query: string): Promise<ExtractorModelData> {
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
};
}
/**
* Method used by Discord Player to validate query with this extractor
2021-06-13 10:55:20 +05:00
* @param {string} query The query to validate
* @returns {boolean}
2021-06-11 15:32:22 +05:00
*/
validate(query: string): boolean {
return Boolean(this._raw.validate(query));
}
/**
* The extractor version
2021-06-13 10:55:20 +05:00
* @type {string}
2021-06-11 15:32:22 +05:00
*/
get version(): string {
return this._raw.version ?? "0.0.0";
}
/**
* If player should mark this extractor as important
2021-06-13 10:55:20 +05:00
* @type {boolean}
2021-06-11 15:32:22 +05:00
*/
get important(): boolean {
return Boolean(this._raw.important);
}
}
export { ExtractorModel };