Skip to content

ExtractorPlugin

This plugin can extract the info, search, and play a song directly from its source

new ExtractorPlugin(): ExtractorPlugin;

ExtractorPlugin

Plugin.constructor

readonly aliases?: string[];

Additional identifiers of the source of the plugin, e.g. ["yt"].

Plugin.aliases


distube: DisTube;

DisTube

Plugin.distube


readonly playable?: boolean;

Whether the songs of this plugin can be played directly.

When it is false, the songs of the plugin are resolved to a playable version by another plugin. It defaults to true.

Plugin.playable


readonly source?: string;

The identifier of the source of the plugin.

It defaults to the name of the class, lowercased, without the Plugin suffix (MyPlugin -> myplugin).

It is used to route a search to a plugin, and to find a plugin with DisTube#getPlugin.

Plugin.source


readonly type: PluginType = PluginType.EXTRACTOR;

The type of the plugin.

Plugin.type

get identifiers(): string[];

Every identifier of this plugin: its Plugin.source and its Plugin.aliases, lowercased.

The static properties of the class are used when the instance ones are not defined, so a plugin can declare them either way.

string[]

Plugin.identifiers


get streams(): StreamServer;

The local HTTP server of the DisTube instance.

Register a handler on it when the plugin cannot hand out a static URL to FFmpeg, instead of running its own server.

StreamServer

Plugin.streams

createSearchQuery<T>(song): Awaitable<string>;

Create the query used to find a playable version of a song.

It is used when the plugin cannot play the songs it resolves.

T

Song<T>

Input song

Awaitable<string>

The search query

override createSearchQuery(song: Song): string {
return `${song.name} ${song.uploader?.name}`;
}

Plugin.createSearchQuery


destroy(): void | Promise<void>;

Destroy the plugin.

It is called when the DisTube instance is destroyed. Override it to release every resource held by the plugin (HTTP servers, timers, browser sessions, …).

void | Promise<void>

Nothing, or a promise that resolves when the plugin is destroyed

Plugin.destroy


getRelatedSongs(_song): Awaitable<Song<unknown>[]>;

Get related songs from a supported url.

Override it to enable the autoplay for your source. Return an empty array when your source does not have any related songs.

Song

Input song

Awaitable<Song<unknown>[]>

The related songs

Plugin.getRelatedSongs


abstract getStreamURL<T>(song): Awaitable<string>;

Get the stream url from Song#url. Returns Song#url by default. Not needed if the plugin plays the song itself.

T

Song<T>

Input song

Awaitable<string>

The url of the audio stream


init(distube): void | Promise<void>;

Initialize the plugin.

It can be asynchronous: use DisTube.create to wait for the initialization of the plugins.

DisTube

The DisTube instance

void | Promise<void>

Nothing, or a promise that resolves when the plugin is initialized

override async init(distube: DisTube) {
this.client = await createSession();
}

Plugin.init


abstract resolve<T>(url, options): Awaitable<
| Song<T>
| Playlist<T>>;

Resolve the validated url to a Song or a Playlist.

T

string

URL

ResolveOptions<T>

Optional options

Awaitable< | Song<T> | Playlist<T>>

The resolved song or playlist


search<T>(query, options?): Promise<SearchResult<T>>;

Search for the songs of the source.

The default implementation returns the single result of Plugin#searchSong. Override it to return more results, or to return a playlist.

T

string

Search query

SearchOptions<T> = {}

Optional options

Promise<SearchResult<T>>

The result of the search

const result = await plugin.search("Never gonna give you up", { limit: 5 });

Plugin.search


searchSong<T>(_query, _options): Awaitable<Song<T> | null>;

Search for a song of the source.

Override it to enable the search of your source. It returns null by default, because a source that cannot be searched does not have any result.

T

string

Search query

ResolveOptions<T>

Optional options

Awaitable<Song<T> | null>

The song that was found, or null

override async searchSong(query: string): Promise<Song | null> {
return findSong(query);
}

Plugin.searchSong


abstract validate(url): Awaitable<boolean>;

Check if the url is working with this plugin

string

Input url

Awaitable<boolean>

true when the plugin can handle the url