eritislami / evobot

🤖 EvoBot is a Discord Music Bot built with TypeScript + Discord.js, includes Docker builds & localization in 20+ languages
MIT License
1.85k stars 2.01k forks source link

fix(song.ts): changing play-dl to ytdl-core in Song.ts makeResource() #1645

Open crackodille opened 3 months ago

crackodille commented 3 months ago

fix #1644

spashii commented 3 months ago

thanks for fixing!

crackodille commented 3 months ago

I am convinced that it would be worthwhile to completely replace the youtube-sr library with ytdl-core to maintain uniformity and improve clarity, but that's rather a larger topic for potential future consideration. Here's a quick fix ready.

haruma1115 commented 3 months ago

If a longer video is played, the following error occurs and the playback is interrupted after some time:

AudioPlayerError: aborted
    at connResetException (node:internal/errors:717:14)
    at TLSSocket.socketCloseListener (node:_http_client:462:19)
    at TLSSocket.emit (node:events:525:35)
    at TLSSocket.emit (node:domain:489:12)
    at node:net:322:12
    at TCP.done (node:_tls_wrap:588:7) {
  resource: AudioResource {
    playStream: Encoder {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 5,
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: true,
      encoder: null,
      _options: [Object],
      _required: 3840,
      _buffer: null,
      [Symbol(kCapture)]: false,
      [Symbol(kCallback)]: [Function: bound onwrite]
    },
    edges: [ [Object], [Object], [Object] ],
    metadata: Song {
      url: 'https://youtube.com/watch?v=mx9Npfwf8xQ',
      title: '*周杰伦*Jay Chou慢歌精选30首合集 - 陪你一个慵懒的下午 - 30 Songs of the Most Popular Chinese Singer',
      duration: 8064
    },
    volume: VolumeTransformer {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 5,
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: true,
      _readInt: [Function (anonymous)],
      _writeInt: [Function (anonymous)],
      _bits: 16,
      _bytes: 2,
      _extremum: 32768,
      volume: 0.42807238607682996,
      _chunk: null,
      [Symbol(kCapture)]: false,
      [Symbol(kCallback)]: [Function: bound onwrite]
    },
    encoder: Encoder {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 5,
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: true,
      encoder: null,
      _options: [Object],
      _required: 3840,
      _buffer: null,
      [Symbol(kCapture)]: false,
      [Symbol(kCallback)]: [Function: bound onwrite]
    },
    audioPlayer: AudioPlayer {
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      _state: [Object],
      subscribers: [Array],
      behaviors: [Object],
      debug: [Function (anonymous)],
      [Symbol(kCapture)]: false
    },
    playbackDuration: 1279740,
    started: true,
    silencePaddingFrames: 5,
    silenceRemaining: -1
  }
}
paulodsncir commented 3 months ago

If a longer video is played, the following error occurs and the playback is interrupted after some time:

AudioPlayerError: aborted
    at connResetException (node:internal/errors:717:14)
    at TLSSocket.socketCloseListener (node:_http_client:462:19)
    at TLSSocket.emit (node:events:525:35)
    at TLSSocket.emit (node:domain:489:12)
    at node:net:322:12
    at TCP.done (node:_tls_wrap:588:7) {
  resource: AudioResource {
    playStream: Encoder {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 5,
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: true,
      encoder: null,
      _options: [Object],
      _required: 3840,
      _buffer: null,
      [Symbol(kCapture)]: false,
      [Symbol(kCallback)]: [Function: bound onwrite]
    },
    edges: [ [Object], [Object], [Object] ],
    metadata: Song {
      url: 'https://youtube.com/watch?v=mx9Npfwf8xQ',
      title: '*周杰伦*Jay Chou慢歌精选30首合集 - 陪你一个慵懒的下午 - 30 Songs of the Most Popular Chinese Singer',
      duration: 8064
    },
    volume: VolumeTransformer {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 5,
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: true,
      _readInt: [Function (anonymous)],
      _writeInt: [Function (anonymous)],
      _bits: 16,
      _bytes: 2,
      _extremum: 32768,
      volume: 0.42807238607682996,
      _chunk: null,
      [Symbol(kCapture)]: false,
      [Symbol(kCallback)]: [Function: bound onwrite]
    },
    encoder: Encoder {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 5,
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: true,
      encoder: null,
      _options: [Object],
      _required: 3840,
      _buffer: null,
      [Symbol(kCapture)]: false,
      [Symbol(kCallback)]: [Function: bound onwrite]
    },
    audioPlayer: AudioPlayer {
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      _state: [Object],
      subscribers: [Array],
      behaviors: [Object],
      debug: [Function (anonymous)],
      [Symbol(kCapture)]: false
    },
    playbackDuration: 1279740,
    started: true,
    silencePaddingFrames: 5,
    silenceRemaining: -1
  }
}

image

I think this problem comes from the library that was used to replace play-dl. As we see here in the play-dl documentation , ytdl is already known for this error.

Play-dll.stream issue https://github.com/play-dl/play-dl/issues/371

crackodille commented 3 months ago

I think this problem comes from the library that was used to replace play-dl. As we see here in the play-dl documentation , ytdl is already known for this error.

My bad ofc i replaced play-dl.stream() not youtube-sr as stated in pull name. I must have been thinking about something else while commiting... Anyway, right now play-dl.stream() is not working properly (in my case at all) hence the replacement.

SametKUM commented 3 months ago

Thank you so much for your contribution! Your code solved the issue perfectly. I couldn't wait for it to be merged, so I went ahead and used it already. @crackodille

itsmemac commented 3 months ago

Thank you for your fix @crackodille Bot is working as it should Hope this gets merged

lucaschain commented 3 months ago

can also confirm it worked on a docker environment

j0hnVu commented 3 months ago

can also confirm it worked on a docker environment

How did you access the file to make the change tho? I cannot find the song.ts file in the container whatsoever.

CameronMunroe commented 3 months ago

I would suggest we don't replace play-dl with ytdl-core. Another bot I use with ytdl-core regularly has issues as well.

What might be nice is having a flag or smart logic to bounce between the two.

lucaschain commented 3 months ago

@j0hnVu

can also confirm it worked on a docker environment

How did you access the file to make the change tho? I cannot find the song.ts file in the container whatsoever.

I checked-out the branch with the fix (https://github.com/crackodille/evobot/tree/issue-1644-fix-with-ytdl), built the container locally and pushed to a private registry

And if you're hosting the container locally, you don't even need to push it to a remote registry

IIyn commented 2 months ago

Works fine, thanks !

CoocooFroggy commented 2 months ago

Seems to be giving 403 now :(

AudioPlayerError: Status code: 403
at ClientRequest.<anonymous> (/node_modules/miniget/dist/index.js:206:27)
at Object.onceWrapper (node:events:632:26)
at ClientRequest.emit (node:events:517:28)
at HTTPParser.parserOnIncomingClient [as onIncoming] (node:_http_client:700:27)
at HTTPParser.parserOnHeadersComplete (node:_http_common:119:17)
at TLSSocket.socketOnData (node:_http_client:541:22)
at TLSSocket.emit (node:events:517:28)
at addChunk (node:internal/streams/readable:335:12)
at readableAddChunk (node:internal/streams/readable:308:9)
at Readable.push (node:internal/streams/readable:245:10) {
j0hnVu commented 2 months ago

@j0hnVu

can also confirm it worked on a docker environment

How did you access the file to make the change tho? I cannot find the song.ts file in the container whatsoever.

I checked-out the branch with the fix (https://github.com/crackodille/evobot/tree/issue-1644-fix-with-ytdl), built the container locally and pushed to a private registry

And if you're hosting the container locally, you don't even need to push it to a remote registry

Thank you! ~It's working flawlessly.~

EDIT: NVM I also got 403

itsmemac commented 2 months ago

Seems to be giving 403 now :(

AudioPlayerError: Status code: 403
at ClientRequest.<anonymous> (/node_modules/miniget/dist/index.js:206:27)
at Object.onceWrapper (node:events:632:26)
at ClientRequest.emit (node:events:517:28)
at HTTPParser.parserOnIncomingClient [as onIncoming] (node:_http_client:700:27)
at HTTPParser.parserOnHeadersComplete (node:_http_common:119:17)
at TLSSocket.socketOnData (node:_http_client:541:22)
at TLSSocket.emit (node:events:517:28)
at addChunk (node:internal/streams/readable:335:12)
at readableAddChunk (node:internal/streams/readable:308:9)
at Readable.push (node:internal/streams/readable:245:10) {

same error as well

IIyn commented 2 months ago

Seems to be giving 403 now :(

AudioPlayerError: Status code: 403
at ClientRequest.<anonymous> (/node_modules/miniget/dist/index.js:206:27)
at Object.onceWrapper (node:events:632:26)
at ClientRequest.emit (node:events:517:28)
at HTTPParser.parserOnIncomingClient [as onIncoming] (node:_http_client:700:27)
at HTTPParser.parserOnHeadersComplete (node:_http_common:119:17)
at TLSSocket.socketOnData (node:_http_client:541:22)
at TLSSocket.emit (node:events:517:28)
at addChunk (node:internal/streams/readable:335:12)
at readableAddChunk (node:internal/streams/readable:308:9)
at Readable.push (node:internal/streams/readable:245:10) {

same error as well

I think I found where it fails In structs/MusicQueue.ts at processQueue() :

 try {
      const resource = await next.makeResource();

      this.resource = resource!;
      this.player.play(this.resource); // -- AudioPlayerError: Status code: 403 --
      this.resource.volume?.setVolumeLogarithmic(this.volume / 100);
    } catch (error) {
      console.error(error);

      return this.processQueue();
    } finally {
      this.queueLock = false;
    }

The ressource could maybe create an issue but I also found an issue on the main repo so I am not sure if @crackodille 's changes on Song.ts are related to this error. It might be a direct error from discordjs/voice dependency

paulodsncir commented 2 months ago

Seems to be giving 403 now :(

AudioPlayerError: Status code: 403
at ClientRequest.<anonymous> (/node_modules/miniget/dist/index.js:206:27)
at Object.onceWrapper (node:events:632:26)
at ClientRequest.emit (node:events:517:28)
at HTTPParser.parserOnIncomingClient [as onIncoming] (node:_http_client:700:27)
at HTTPParser.parserOnHeadersComplete (node:_http_common:119:17)
at TLSSocket.socketOnData (node:_http_client:541:22)
at TLSSocket.emit (node:events:517:28)
at addChunk (node:internal/streams/readable:335:12)
at readableAddChunk (node:internal/streams/readable:308:9)
at Readable.push (node:internal/streams/readable:245:10) {

same error as well

I think I found where it fails In structs/MusicQueue.ts at processQueue() :

 try {
      const resource = await next.makeResource();

      this.resource = resource!;
      this.player.play(this.resource); // -- AudioPlayerError: Status code: 403 --
      this.resource.volume?.setVolumeLogarithmic(this.volume / 100);
    } catch (error) {
      console.error(error);

      return this.processQueue();
    } finally {
      this.queueLock = false;
    }

The ressource could maybe create an issue but I also found an issue on the main repo so I am not sure if @crackodille 's changes on Song.ts are related to this error. It might be a direct error from discordjs/voice dependency

The solution for error 403, https://www.npmjs.com/package/@distube/ytdl-core I tested and it worked. It should be used in conjunction with the @crackodille 's solution.

You can follow the issue here

https://github.com/fent/node-ytdl-core/issues/1295

CoocooFroggy commented 2 months ago

Submitted a pull request to @crackodille's branch that integrates @paulodsncir's new solution. Can confirm it works.

https://github.com/crackodille/evobot/pull/1

crackodille commented 2 months ago

@paulodsncir @CoocooFroggy nice work. merged :)

itsmemac commented 2 months ago

Can confirm the new updated code to be working Thank you everyone for contribution Hope evobot author merges this pull

crackodille commented 2 months ago

Unfortunately new problems.

Error: While getting info from url Sign in to confirm you’re not a bot at video_basic_info (/home/Documents/evobot/node_modules/play-dl/play-dl/YouTube/utils/extractor.ts:191:19) at processTicksAndRejections (node:internal/process/task_queues:95:5) at async Function.from (/home/Documents/evobot/structs/Song.ts:55:18) at async Object.execute (/home/Documents/evobot/commands/play.ts:56:14)

youtube is not sleeping I guess. They are trying to eliminate bots.

paulodsncir commented 2 months ago

Unfortunately new problems.

Error: While getting info from url Sign in to confirm you’re not a bot at video_basic_info (/home/Documents/evobot/node_modules/play-dl/play-dl/YouTube/utils/extractor.ts:191:19) at processTicksAndRejections (node:internal/process/task_queues:95:5) at async Function.from (/home/Documents/evobot/structs/Song.ts:55:18) at async Object.execute (/home/Documents/evobot/commands/play.ts:56:14)

youtube is not sleeping I guess. They are trying to eliminate bots.

@crackodille I saw a possible workaround in this issue, maybe it could help. I didn't have the opportunity to test it.

YouTube is giving me so much headache, I just wanted to listen to music with my friends

https://github.com/play-dl/play-dl/issues/370

Snaklilopin commented 2 months ago

I have a question I tried to play a video with an age restriction, but it was possible to get through what play-dl restricts before entering, but after it it’s no longer possible (as I understand, this is exactly what ytdl is now responsible for, since the same age error), having smoked heavily documentation, I just didn’t come to the conclusion that I could play videos with age restrictions. Maybe I just don’t understand what else is true, but has anyone actually succeeded?