Androz2091 / discord-player

🎧 Complete framework to simplify the implementation of music commands using discord.js v14
https://discord-player.js.org/
MIT License
606 stars 192 forks source link

[Discussion] Change default query resolver to something else from youtube #1673

Closed twlite closed 1 year ago

twlite commented 1 year ago

As you all know, we have seen the news of youtube taking down big music bots like Groovy, Rythm and more.

Discord Player has been using youtube as its primary source of pulling information from the beginning and it has stayed that way. This framework is mainly about building music bots and people want to avoid youtube taking down their bots. What do you think would be the best way to handle search queries? Since v6 of discord-player, we have options to completely disable specific extractors for either streaming or metadata or both. Discord Player before v6.x (aka <= v5.x) has a built-in extractor which is basically impossible to disable so v5 users are requested to switch to v6 as soon as possible.

As you know, discord-player v6 by itself has no way of pulling metadata and other information without using @discord-player/extractor library. Which states that it is much more restricted than how it used to be.

We have recently passed extractor initializer options proposal https://github.com/Androz2091/discord-player/commit/714d66b1966a905bcd8f76967a0e0276fa4dfe74 which will be released in the next version. It will allow users to pass options such as api keys or other important things for a particular extractor. It is possible to completely avoid @discord-player/extractor and use your own. Since the rewrite of our extractors api, the registered extractors are more context aware and they have access to the master player and all of its components. We will fully support community built extractors and even list them in our website.

How v6 extractor api works

import { BaseExtractor } from 'discord-player';

// since it extends BaseExtractor, it is aware of Player who loaded this extractor and thus can access informations such as queue, voice connections and more. Those data exist inside context property of BaseExtractor, which is an instance of ExtractorExecutionContext and can be accessed using `this.context`. 
class MyExtractor extends BaseExtractor {
    // (required) you should give a unique id for you extractor here.
    static identifier = 'unique-id-for-my-extractor';

    // this method is called when your extractor is loaded into discord-player's registry
    async activate() {
        // do something here, such as initializing APIs or whatever
    }

    // discord-player calls this method when your extractor is removed from its registry
    async deactivate() {
        // do something here, such as disconnecting from API or cleanup or whatever it is
    }

    // discord-player calls this method when it wants some metadata from you. When you return true, discord-player will use you for further processing. If you return false here, discord-player will query another extractor from its registry.
    async validate(query, queryType) {
        return validateQuery(query);
    }

    // discord-player calls this method when it wants a search result. It is called with the search query and a context parameter (options passed to player.search() method)
    async handle(query, context) {
        return this.createResponse(playlist?, tracks[]);
    }

    // discord-player calls this method when it wants you to stream a track. You can either return raw url pointing at a stream or node.js readable stream object. Note: this method wont be called if onBeforeCreateStream was used. It is called with discord-player track object.
    async stream(track) {
        return stream;
    }

    // discord-player calls this method when it wants some tracks for autoplay mode.
    async getRelatedTracks(track) {
        return [tracks];
    }
}

// loading
player.extractors.register(MyExtractor);

We have not been to a proper conclusion on what should be done regarding youtube streams. Please feel free to share your opinion. You can also share your custom extractors as an example if you have one.

retrouser955 commented 1 year ago

I was thinking, discord-player should let the users choose what extractor it checks first.

For example, if the default is YouTubeExtractor -> SoundCloudExtractor -> CustomExtractor, discord-player should allow the users to reorder that to CustomExtractor -> YouTubeExtractor -> SoundCloudExtractor.

retrouser955 commented 1 year ago

I would love it if custom sources are a thing because making a custom extractor for another platform other than YouTube, Apple Music, Spotify and/or SoundCloud requires the extractor to set it to a difference source which we cannot currently cannot do.

twlite commented 1 year ago

Should we allow other extractors to handle QueryType.YOUTUBE_SEARCH? I guess not. YouTube search may be necessary to resolve youtube links. We can however do something about streaming part, like redirecting youtube tracks to some other extractor?

twlite commented 1 year ago

Commit https://github.com/Androz2091/discord-player/commit/29372ca63bfaa9ea723de43a43c7f9f0219e370f introduces new query type called AUTO_SEARCH which will be the default search engine if it cant validate links.

All major extractors who support search query will be able to handle this type. YouTube extractor will be given the least priority (if it is not disabled) for search queries. It means that leaving query type to AUTO is okay to ignore youtube.

Streaming part is yet to be decided.