Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

crackodille
Copy link

fix #1644

@spashii
Copy link

spashii commented Jun 17, 2024

thanks for fixing!

@crackodille
Copy link
Author

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
Copy link

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
Copy link

paulodsncir commented Jun 18, 2024

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 play-dl/play-dl#371

@crackodille
Copy link
Author

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.

@crackodille crackodille changed the title fix(song.ts): changing youtube-sr to ytdl-core in Song.ts makeResource() fix(song.ts): changing play-dl to ytdl-core in Song.ts makeResource() Jun 18, 2024
@SametKUM
Copy link

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
Copy link

itsmemac commented Jun 20, 2024

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

@lucaschain
Copy link

can also confirm it worked on a docker environment

@j0hnVu
Copy link

j0hnVu commented Jun 21, 2024

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
Copy link

CameronMunroe commented Jun 21, 2024

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
Copy link

lucaschain commented Jun 21, 2024

@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
Copy link

IIyn commented Jul 9, 2024

Works fine, thanks !

@CoocooFroggy
Copy link

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
Copy link

j0hnVu commented Jul 11, 2024

@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
Copy link

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
Copy link

IIyn commented Jul 13, 2024

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
Copy link

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

fent/node-ytdl-core#1295

@CoocooFroggy
Copy link

CoocooFroggy commented Jul 15, 2024

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

crackodille#1

@crackodille
Copy link
Author

@paulodsncir @CoocooFroggy nice work. merged :)

@itsmemac
Copy link

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

@crackodille
Copy link
Author

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
Copy link

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

play-dl/play-dl#370

@Snaklilopin
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The song seems to loads but doesnt play🐛