Androz2091 / discord-player

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

Suggestion: API key option in Player (Youtube, maybe Spotify) #245

Closed mertushka closed 3 years ago

mertushka commented 3 years ago

To get faster results and optimize ram cpu usage, there should be an api key option, when we set our api key there, module must make queries through the api, not via youtube-sr. If the api key is not specified, module must make search through youtube-sr.

twlite commented 3 years ago

🤔 not a bad idea tbh. I think discord-player should detect api keys from process.env instead of having options? for example: process.env.YOUTUBE_API_KEY or process.env.SPOTIFY_API_KEY

Androz2091 commented 3 years ago

Yes, it could be possible. Actually we switched to scraping because a lot of users were ratelimited in a short period of time, but we could support both scraping and the official API.

mertushka commented 3 years ago

🤔 not a bad idea tbh. I think discord-player should detect api keys from process.env instead of having options? for example: process.env.YOUTUBE_API_KEY or process.env.SPOTIFY_API_KEY

Good idea.

Majoramari commented 3 years ago

Yes, it could be possible. Actually we switched to scraping because a lot of users were ratelimited in a short period of time, but we could support both scraping and the official API.

i think discord-player should support ipv6 for requests to avoid ratelimit

Spencer-0003 commented 3 years ago

This would be really helpful as my bot is getting rate limited.

kimoVoid commented 3 years ago

Fully agree with this

twlite commented 3 years ago

This would be really helpful as my bot is getting rate limited.

you mean youtube 429? If you are talking about youtube 429 then no, api keys wont solve your problem

thaddeuskkr commented 3 years ago

API keys is a good idea and it would be even better if the module detected ratelimits and switched to scraping automatically so there would be lesser errors / close to none

+1

twlite commented 3 years ago

@ThaddeusKKR yeah, if you are okay with slow response (api request > failed > scrape) 😀

thaddeuskkr commented 3 years ago

@ThaddeusKKR yeah, if you are okay with slow response (api request > failed > scrape) 😀

i guess once the api fails once it could be disabled until the bot instance is restarted / api is manually reenabled so the lag will only occur once. A suggestion would be: client.player.useYTAPI = {boolean} and if spotify keys are added client.player.useSpotifyAPI = {boolean}

twlite commented 3 years ago

@ThaddeusKKR yeah, good idea. I will start working on api based youtube search

twlite commented 3 years ago

You should be able to use youtube api like this:

require("youtube-sr").default.set("api", "YOUTUBE_API_KEY");

it should automatically switch to api mode. And to go back to scraper, you can set it to false or use YouTube.delete("api")

twlite commented 3 years ago

done for YouTube, not gonna do it for others (soundcloud uses api key when required)