skick1234 / DisTube

A powerful Discord.js module for simplifying music commands and effortless playback of various sources with integrated audio filters.
https://distube.js.org
MIT License
421 stars 95 forks source link

Allow array of search strings in playCustomPlaylist #40

Closed sebastianwd closed 3 years ago

sebastianwd commented 3 years ago

I'm trying to play songs from a spotify playlist url by getting the youtube url of every song in it with ytsr and then passing the array of urls to the playCustomPlaylist method. The problem with this is that it creates too many requests at once to youtube and they end up blocking my ip temporarily

Something I propose is to let playCustomPlaylist accept search strings, and let distube perform the search of metadata just when the player is about to play a song.

Jeydin21 commented 3 years ago

Did you add the YouTube cookie :>

On Wed, Dec 23, 2020 at 4:24 PM Sebastian L. notifications@github.com wrote:

I'm trying to play songs from a spotify playlist url by getting the youtube url of every song in it with ytsr and then passing the array of urls to the playCustomPlaylist method. The problem with this is that it creates too many requests at once to youtube and they end up blocking my ip temporarily

Something I propose is to let playCustomPlaylist accept search strings, and let distube perform the search of metadata just when the player is about to play a song.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/skick1234/DisTube/issues/40, or unsubscribe https://github.com/notifications/unsubscribe-auth/AO6ECW565TT5K3XUINPWDNDSWJU2PANCNFSM4VHQDGCA .

sebastianwd commented 3 years ago

Did you add the YouTube cookie :>

I did, this is the code I'm using

client.player = new DisTube(client, {
  searchSongs: false,
  emitNewSongOnly: false,
  youtubeCookie: YT_COOKIE,
  youtubeIdentityToken: X_YT_ID_TOKEN,
})

and I use this one for individually searching songs from a spotify playlist

const ytSearch = async (query: string) => {
  try {
  const userAgent = new UserAgent()

    const results = await yts(query, {
      limit: 1,
      requestOptions: {
      headers: {
        'User-Agent': userAgent.toString(),
        cookie: config.YT_COOKIE,
        'x-youtube-identity-token': config.X_YT_ID_TOKEN,
      },
    } as any)

    return results.items
  } catch (error) {
    logger.error('ytSearch: ', error)

    return []
  }
}

after querying around 60 songs I start gettting code 429 from youtube

Samir-OP commented 3 years ago

Did you add the YouTube cookie :>

I did, this is the code I'm using

client.player = new DisTube(client, {
  searchSongs: false,
  emitNewSongOnly: false,
  youtubeCookie: YT_COOKIE,
  youtubeIdentityToken: X_YT_ID_TOKEN,
})

and I use this one for individually searching songs from a spotify playlist

const ytSearch = async (query: string) => {
  try {
  const userAgent = new UserAgent()

    const results = await yts(query, {
      limit: 1,
      requestOptions: {
      headers: {
        'User-Agent': userAgent.toString(),
        cookie: config.YT_COOKIE,
        'x-youtube-identity-token': config.X_YT_ID_TOKEN,
      },
    } as any)

    return results.items
  } catch (error) {
    logger.error('ytSearch: ', error)

    return []
  }
}

after querying around 60 songs I start gettting code 429 from youtube

Your IP got banned from YouTube

skick1234 commented 3 years ago

I don't have any problem with it. I'm using <DisTube>.search() then <DisTube>.playCustomPlaylist. And it's doesn't necessary to support search strings because it will work in the same way as search + playCustomPlaylist.

Tomato6966 commented 3 years ago

Hey, ur ip got banned, attention! the more you try while your banned the longer you need to wait^^ so just wait like 2-4 days then u will be unbanned and dont do playlist fetching at once try fetching for each song in the playlist, why? well regarding to google request token limits which are around about 10k per ip, a song will cost you somewhere under 10 tokens but a playlist will cost u at least 1000 tokens no matter how many songs there are in there, plus for like 40songs+ playlists for each song more tokens so if u fetch each song singularily, you will be "finer" I hope this helps