Giter Site home page Giter Site logo

play-dl / play-dl Goto Github PK

View Code? Open in Web Editor NEW
202.0 6.0 48.0 1.93 MB

Mainly used for Discord js Bots to play music.

Home Page: https://play-dl.github.io/

License: GNU General Public License v3.0

TypeScript 100.00%
soundcloud soundcloud-dl youtube youtube-dl music spotify spotify-dl discordjs discord-js discord

play-dl's Introduction

Play-dl

A light-weight YouTube, SoundCloud, Spotify and Deezer streaming and searching library.

  • Search by video, playlist/album, channel/artist
  • Stream audio from YouTube and SoundCloud

Why play-dl ?

ytdl-core has some issues with miniget and also stream abort issues. On the other hand, youtube-dl is a perfect alternative but it takes time to launch. Hence, play-dl is created to avoid these issues along with providing comparatively faster performance than others.

Discord NPM

Support

You can contact us for support on our chat server.

Installation

Node.js 16.0.0 or newer is required.

npm install play-dl@latest
pnpm add play-dl@latest
yarn add play-dl@latest

Importing

TypeScript:

import play from 'play-dl'; // Everything

import { video_basic_info, stream } from 'play-dl'; // Individual functions

CommonJS modules:

const play = require('play-dl'); // Everything

// Individual functions by using destructuring
const { video_basic_info, stream } = require('play-dl');

ES6 modules:

import play from 'play-dl'; // Everything

import { video_basic_info, stream } from 'play-dl'; // Individual functions

Compatibility issues - discord-player

Because discord-player doesn't work with raw opus packets you need to enable the compatibility mode in play-dl, if you want to use both frameworks together.

  • To fix the playback of YouTube videos with discord-player, you can disable some of play-dl's optimisations and fixes by setting the discordPlayerCompatibility option for stream and stream_from_info to true

  • The discordPlayerCompatiblity option might break the playback of long YouTube videos.

  • Even with the discordPlayerCompatibility option set you will not be able to use the seek option for stream and stream_from_info.

play-dl's People

Contributors

absidue avatar ataritom avatar cjh980402 avatar darker-ink avatar dependabot[bot] avatar ducktrshessami avatar github-actions[bot] avatar iim-ayush avatar kane50613 avatar karyeet avatar kingrainbow44 avatar tr1ckydev avatar vladexa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

play-dl's Issues

[=BUG=] Initial Player Response Data is undefined (possibly proxy)

Describe the bug

Some songs throw this error. I personally have not been able to reproduce it but my users see it, especially after songs play for a while on the same proxy. Strangely, when it occurs it only happens on one song and others work fine.

The songs that the issue has been noticed on have been (the Spotify one is converted to the VEVO youtube version of it):
https://www.youtube.com/watch?v=B4MOVJg6WbI
https://open.spotify.com/track/2gbMPBrBVj3CuNTLp2dHYs?si=7cb55bff04a84da1

  • Node.js version: 16.9.1
  • OS & version: Raspbian 10

Actual behavior

Certain songs throw the error listed in the title.

Expected behavior

All songs should play normally.

ScreenShots

Screenshot 2021-10-29 161031

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Play-dl.

[=BUG=] ReadError: The server aborted pending request

Describe the bug

  • Node.js version: 16.9.0
  • OS & version: ubuntu 20.04

I play this song (https://www.youtube.com/watch?v=NGYYKJ0R0OA) at 21:20. And I got this error (ReadError: The server aborted pending request) at 21:32.

url: https://www.youtube.com/watch?v=NGYYKJ0R0OA
duration: 8226
Error stack: ReadError: The server aborted pending request
    at IncomingMessage.<anonymous> (/home/ubuntu/bot/node_modules/got/dist/source/core/index.js:803:31)
    at Object.onceWrapper (node:events:513:28)
    at IncomingMessage.emit (node:events:406:35)
    at IncomingMessage.origin.emit (/home/ubuntu/bot/node_modules/@szmarczak/http-timer/dist/source/index.js:43:20)
    at IncomingMessage._destroy (node:_http_incoming:179:10)
    at _destroy (node:internal/streams/destroy:102:25)
    at IncomingMessage.destroy (node:internal/streams/destroy:64:5)
    at TLSSocket.socketCloseListener (node:_http_client:407:11)
    at TLSSocket.emit (node:events:406:35)
    at node:net:672:12

Actual behavior

Sometimes, I got the ReadError.

Expected behavior

It should be no error.

Code to reproduce

ScreenShots

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Play-dl.

[=BUG=] Checking

Describe the bug

  • Node.js version:
  • OS & version:

Actual behavior

Expected behavior

Code to reproduce

ScreenShots

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Play-dl.

Playlists

i've been facing the issue of playlists not giving me the videos no matter how many times i fetch

[=BUG=] ETIMEDOUT error with proxy connection

Describe the bug

  • Node.js version: 16.9.1
  • OS & version: Raspbian 10

After playing music for an extended period of time, this error can come up. I have not observed any pattern to it appearing in neither time nor song played. It can also appear if the bot is not playing any music for hours and then finally is being used to play.

The error persists for the rest of the bot's lifecycle and restarting the bot fixes it overall. For this reason, I am not entirely certain it may be play-dl's fault but the issue points to the TCP used in the proxy connection. I am willing to privately provide the credentials to the one listed in the error for testing.

ScreenShots

Screenshot 2021-10-10 234755

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Play-dl.

[=FEATURE=] Customizable Stream Buffer sizes

What problem are you trying to solve?

10MB per stream is quite chonky depending on scale and is not actually the minimum required to operate depending on network stability and throughput. Being able to customize this depending on the user's circumstances could be huge in terms of memory efficiency.

Describe the feature

play_dl.stream(ID, undefined, { highWaterMark: 2_000_000 }); // 2MB is very reasonable on a stable and high throughput connection. A similar implementation could be achieved on other methods which make use of the Stream and LiveStream classes.

Checklist

  • I have read the documentation and made sure this feature doesn't already exist.

[=BUG=] Long Playback is still not working

Describe the bug

Connection reset after 15-18m of the same song

Actual behavior

It gives following error

Expected behavior

It should play the song completely

Code to reproduce

await youtube.stream(url)

ScreenShots

IMAGE

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Play-dl.

Live Download

Is your play dl can download live stream?

Checklist

  • I have read the documentation.

[=BUG=] MaxListenersExceededWarning in PassThrough

Describe the bug

  • Node.js version: 16.9.1
  • OS & version: Raspbian 10
(node:620) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:620) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:620) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 unpipe listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:620) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 finish listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:620) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 drain listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit

This seems to be similar to the issue that was "fixed" and discussed here: #52

The only difference that I am seeing is that this time it includes "drain listeners" whereas the previous one did not include that remark.

For further information, I am using a proxy to run the stream.

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Play-dl.

[=BUG=] YouTube Extract ID not respecting YouTube ID format

Describe the bug

  • Node.js version: 16.6
  • OS & version: Ubuntu 20

YouTube's extractID fn doesn't check for if the extracted ID matches the /^[a-zA-Z\d]+$/ (Video IDs only. PL includes - and \d)

Actual behavior

The extractor can return IDs which include any characters.

Expected behavior

The extractor throws an Error expecting the ID to be in a specific format

Code to reproduce

const play = require("play-dl")
const testString = "pogu my guy$$XD";
const val = play.extractID(testString);
console.log(testString === val); // true

ScreenShots

N.A.

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Play-dl.

[=BUG=] Length of some playlist id isnt' 34

Describe the bug

1st URL: https://www.youtube.com/watch?v=UclSNeLc2aI&list=FLMalFh3zoiVTPWqg-5lx8-Q
length of id: 24

2nd: URL: https://www.youtube.com/watch?v=FZu097wb8wU&list=RDFZu097wb8wU
length of id: 13

I found some link about youtube id. (https://linuxpanda.wordpress.com/2013/07/24/ultimate-best-regex-pattern-to-get-grab-parse-youtube-video-id-from-any-youtube-link-url/)

Code to reproduce

ScreenShots

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Play-dl.

[=BUG=] Error: read ECONNRESET is Unhandled 'error' event in v0.9.9

Describe the bug

  • Node.js version: 16.9.0
  • OS & version: ubuntu 20.04
node:events:371
      throw er; // Unhandled 'error' event
      ^

Error: read ECONNRESET
    at TLSWrap.onStreamRead (node:internal/stream_base_commons:220:20)
Emitted 'error' event on ClientRequest instance at:
    at TLSSocket.socketErrorListener (node:_http_client:447:9)
    at TLSSocket.emit (node:events:394:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -104,
  code: 'ECONNRESET',
  syscall: 'read'
}

I get this Unhandled 'error' event, so my bot is rebooted in v0.9.9

Actual behavior

Unhandled 'error' event is occured.

Expected behavior

Error: read ECONNRESET should be handled by error event of Stream.stream.

Code to reproduce

ScreenShots

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Play-dl.

[=BUG=] Playlist info error

Describe the bug

  • 16.x.x
  • Windows 10 pro:

The bug is related to playlist info with playlist_info function which return video_id = url.split('watch?v=')[1].split('&')[0]; as err!

Actual behavior

Throws err video_id = url.split('watch?v=')[1].split('&')[0];

Expected behavior

It should return the playlist data.

Code to reproduce

  yt.playlist_info(query) .then(output =>
    
    
        { 
        console.log(output)
         console.log(`yes used! playlist_url`)
         return {
             title: output.title,
             duration: output.durationInSec * 1000,
             thumbnail: output.thumbnail,
             engine: yt.stream_from_info(output).then(m=>m),
             views: output.views,
             author: output.channel,
             description: output.description,
             url: output.url}
             
         } 
         );

ScreenShots

Checklist

  • [ .] I have read the documentation.
  • [. ] I have tried my code with the latest version of Node.js and Play-dl.

[=BUG=] RequestError: read ECONNRESET (rarely bug)

Describe the bug

  • Node.js version: 16.6.2
  • OS & version: ubuntu 20.04
node:events:371
      throw er; // Unhandled 'error' event
      ^

RequestError: read ECONNRESET
    at ClientRequest.<anonymous> (/home/ubuntu/bot/node_modules/got/dist/source/core/index.js:956:111)
    at Object.onceWrapper (node:events:514:26)
    at ClientRequest.emit (node:events:406:35)
    at ClientRequest.origin.emit (/home/ubuntu/bot/node_modules/@szmarczak/http-timer/dist/source/index.js:43:20)
    at TLSSocket.socketErrorListener (node:_http_client:447:9)
    at TLSSocket.emit (node:events:394:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
    at TLSWrap.onStreamRead (node:internal/stream_base_commons:211:20)
Emitted 'error' event on Request instance at:
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  code: 'ECONNRESET',
  timings: {
    start: 1630408508781,
    socket: 1630408508782,
    lookup: 1630408508782,
    connect: 1630408508785,
    secureConnect: 1630408508789,
    upload: 1630408508789,
    response: 1630408508799,
    end: undefined,
    error: 1630408590273,
    abort: 1630408590274,
    phases: {
      wait: 1,
      dns: 0,
      tcp: 3,
      tls: 4,
      request: 0,
      firstByte: 10,
      download: undefined,
      total: 81493
    }
  }
}

In before issue, I ignore ECONNRESET error to add When I add stream.once('error', () => {}); or stream.once('error', () => { stream.destroy(); }); in Stream.normal_start(), Stream.loop_start(), Stream.loop(), and etc.
Can it be solution about this rarely bug?

Actual behavior

Expected behavior

Code to reproduce

ScreenShots

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Play-dl.

Memory Leak

Discussed in #42

Originally posted by cjh980402 September 4, 2021
When the bot started, bot process memory usage is about 14%.
When the bot is running about 23 hours, bot proccess memory usage is about 40%.
image
above picture is memory usage of bot server.

I'm asking questions here because I can't find the exact cause. There was a problem with singing streaming even in similar situations before (use other youtube module).
Is there any additional solution that users should do?

[=ASK=] Is there a way to play streams longer than 5 minutes?

What would you like to discuss?

I saw that in 0.6.0 there was a loop point set to 5 minutes, and before that there were some crashing issues due to long streams.
Is there any plan to make long streams usable, or is it going to be capped at 5 minutes for the foreseeable future?

As a workaround, is there any way to grab a second stream starting at a certain time in the video as a way to simulate one long stream? (so I could grab 0:00-5:00, then a separate stream from 5:00-10:00, etc)

Checklist

  • I have read the documentation.

[=FEATURE=] A safer way of using secret tokens

What problem are you trying to solve?

Today, if you want to play a track from Spotify or SoundCloud, you have to pass a token for that.

According to these lines of code:

let spotifyData: SpotifyDataOptions;
if (fs.existsSync('.data/spotify.data')) {
spotifyData = JSON.parse(fs.readFileSync('.data/spotify.data').toString());
}

I have to save the secrets inside my fails which is considered as bad practice. You don't want to share tokens/credentials in your source code. Personally, I use environment variables.

Describe the feature

Instead of reading the token from a file, read it from an argument and let the consumer choose their way of passing down the tokens.

Instead of:

export async function spotify(url: string): Promise<Spotify> {

Do:

export async function spotify(url: string, spotifyData: SpotifyData): Promise<Spotify> { 

Checklist

  • I have read the documentation and made sure this feature doesn't already exist.

[=ASK=] How to search Spotify?

What would you like to discuss?

Hi, I've been trying to search a track on Spotify but keep getting error.

I've followed the instruction posted here, but still getting the following error:
image

Please note that I have added a console.log(), so it can tell me the error code here
image

Here is my current code.
image

Also, I noticed that refresh_token is required, how do I get that? The instruction only showed how to get CLIENT_ID and CLIENT_SECRET.

Checklist

  • I have read the documentation.

[=BUG=] extractID() couldn't detect Youtube url

Describe the bug

extractID(url) does not detect the following link https://www.youtube.com/watch?v=_8ldAdQd9WU&list=RD-HRpDfAqe7w

I have looked at the code, and extractId(url) uses yt_validate(url) and yt_validate(url) returns false; hence the error.

I think it's because yt_validate(url) looks for the "list=" string, which the url does includes, so it thinks it's a playlist url, which tries to match the playlist_pattern here, and ultimately fails because it's a mixed playlist.

  • Node.js version: v16.13.0
  • OS & version: Windows 10 x64

Actual behavior

Error: This is not a YouTube url or videoId or PlaylistID

Expected behavior

Code to reproduce

const playdl = require('play-dl');
const url = 'https://www.youtube.com/watch?v=_8ldAdQd9WU&list=RD-HRpDfAqe7w';
console.log(playdl.extractID(url));

ScreenShots

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Play-dl.

[=BUG=] TCP connection does not end.

Describe the bug

  • Node.js version: 16.6.2
  • OS & version: ubuntu 20.04

This is the result of 'lsof -i -a' command that song is normally finished.

COMMAND   PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
node    10274 ubuntu   20u  IPv4 161808      0t0  TCP ubuntu-vm:40644->162.159.138.232:https (ESTABLISHED)
node    10274 ubuntu   21u  IPv4 161828      0t0  TCP ubuntu-vm:39840->162.159.135.232:https (ESTABLISHED)
node    10274 ubuntu   23u  IPv4 161814      0t0  TCP ubuntu-vm:58812->162.159.130.234:https (ESTABLISHED)
node    10274 ubuntu   24u  IPv4 162167      0t0  TCP ubuntu-vm:37216->162.159.130.235:https (ESTABLISHED)
node    10274 ubuntu   25u  IPv4 162168      0t0  UDP *:52051 

This is the result of 'lsof -i -a' command that song is forcely finished when song played about 20 seconds.

COMMAND   PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
node    10274 ubuntu   20u  IPv4 161808      0t0  TCP ubuntu-vm:40644->162.159.138.232:https (ESTABLISHED)
node    10274 ubuntu   21u  IPv4 161828      0t0  TCP ubuntu-vm:39840->162.159.135.232:https (ESTABLISHED)
node    10274 ubuntu   23u  IPv4 161814      0t0  TCP ubuntu-vm:58812->162.159.130.234:https (ESTABLISHED)
node    10274 ubuntu   26u  IPv4 161790      0t0  TCP ubuntu-vm:56754->kix03s05-in-f11.1e100.net:https (ESTABLISHED)

This is the result of 'lsof -i -a' command that after 5minutes of second result.

COMMAND   PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
node    10274 ubuntu   20u  IPv4 161808      0t0  TCP ubuntu-vm:40644->162.159.138.232:https (ESTABLISHED)
node    10274 ubuntu   21u  IPv4 161828      0t0  TCP ubuntu-vm:39840->162.159.135.232:https (ESTABLISHED)
node    10274 ubuntu   23u  IPv4 161814      0t0  TCP ubuntu-vm:58812->162.159.130.234:https (ESTABLISHED)
node    10274 ubuntu   26u  IPv4 161790      0t0  TCP ubuntu-vm:56754->kix03s05-in-f11.1e100.net:https (CLOSE_WAIT)

I found the bug that youtube TCP connection(kix03s05-in-f11.1e100.net:https) does not end when song is forcely finished.

Actual behavior

Expected behavior

Code to reproduce

ScreenShots

Checklist

  • [o] I have read the documentation.
  • [o] I have tried my code with the latest version of Node.js and Play-dl.

[=BUG=] Fails to parse unlisted youtube video basic info in versions >=1.0.0

Describe the bug

  • Node.js version: 16.6.2
  • OS & version: Windows 10

There's some trouble parsing the basic info for Youtube videos that wasn't previously in this package.

Actual behavior

video_basic_info produces the following error at JSON.parse(player_data):
SyntaxError: Unexpected token ; in JSON at position 55868

I've noticed that the position number changes, but a log before parsing as JSON revealed the text that triggers the error is always the same:

;var meta = document.createElement('meta'); meta.name = 'referrer'; meta.content = 'origin'; document.getElementsByTagName('head')[0].appendChild(meta)

Tested on 0.9.9, 1.0.0, and 1.2.8; only 0.9.9 did not have this issue.

Expected behavior

Removing the last bit of text from the unparsed JSON allowed the function to proceed with no further errors.
I imagine there was previously a way to detect unlisted videos or extra text in JSON that didn't make it to 1.0.0

Code to reproduce

const play = require("play-dl");

const url = "https://youtu.be/J5gbytKM5Us";

play.video_basic_info(url)
    .then(info => info.video_details.title)
    .then(console.log)
    .catch(console.error);

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Play-dl.

[=FEATURE=] Get related videos

Discussed in #95

Originally posted by tr1ckydev September 22, 2021
A method through which we can get the related videos (similar videos recommended by youtube) from a video url using play-dl.

[=BUG=] Parsing errors when using proxies

Describe the bug

  • Node.js version: 16.9.1
  • OS & version: Raspbian 10

When using proxies, parsing errors occur with no noticeable pattern. The same song can go from working to having issues and the issue will remain even through restarts for a while. May be related to a result returned from YouTube after long streaming?

The errors that have been noticed are always the following:
TypeError: Cannot read properties of undefined (reading 'split') at video_basic_info
SyntaxError: Unexpected end of JSON input

The first is more common than the second. I do not have an exact location as to where the JSON input error points to, unfortunately.

There is no specific song this occurs to, it can happen to any song.

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Play-dl.

[=BUG=] Unavailable video breaks playlist_info(url)

Describe the bug

  • Node.js version: 16.7.0
  • OS & version: linux (most likely latest)

playlist_info throws an TypeError when there is unavailable video that is hidden instead of returning the rest of the playlist.

Actual behavior

It Throws an TypeError as response.alerts[0] does not contain attribute alertRenderer:

Output of console.log(JSON.stringify(response.alerts));

[{"alertWithButtonRenderer":{"type":"INFO","text":{"simpleText":"1 unavailable video is hidden"},"dismissButton":{"buttonRenderer":{"style":"STYLE_DEFAULT","size":"SIZE_DEFAULT","isDisabled":false,"icon":{"iconType":"CLOSE"},"trackingParams":"CCQQ8FsiEwizpMKrq8fyAhUNplEKHV-iDng=","accessibilityData":{"accessibilityData":{"label":"Dismiss"}}}}}}]

Expected behavior

It should just ignore the unavailable video, and process the playlist.

Code to reproduce

URL where a playlist contains a video that is not available for the server host's country ( mostly likely due to region lock).

const res = await (await playlist_info(url)).fetch();

Screenshots

image

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Play-dl.

How I temporary fixed it on my end.

From:

if(response.alerts && response.alerts[0].alertRenderer.type === 'ERROR') throw new Error(`While parsing playlist url\n ${response.alerts[0].alertRenderer.text.runs[0].text}`)

To:

if (response.alerts && response.alerts[0].alertRenderer?.type === 'ERROR') throw new Error(`While parsing playlist url\n   ${response.alerts[0].alertRenderer.text.runs[0].text}`)

(I added optional chaining on alertRenderer)

[=BUG=] Cannot fetch tracks from SpotifyAlbum or SpotifyPlaylist

Describe the bug

I'm trying to .fetch() tracks from SpotifyAlbum/Playlist but get undefined

  • Node.js version: 16.9.1
  • OS & version: Windows 10

Actual behavior

get album with play.spotify() --> get tracks from album with .fetch --> success

Expected behavior

get album with play.spotify() --> get tracks from album with .fetch --> got undefined

Code to reproduce

if (
      /^(ftp|http|https):\/\/[^ "]+$/.test(query) &&
      playDl.sp_validate(query)
    ) {
      if (playDl.is_expired()) {
        await playDl.refreshToken()
      }
      playDl
        .spotify(query)
        .then(async (data) => {
          switch (data.type) {
            case 'album':
              const test = await data.fetch()
              console.log(data) // I can see fetched_tracks private property with correct data, but no result with .fetch()
              console.log(test) // undefined
              break
            default:
              break
          }
        })
        .catch((error) => {
          console.error(error) // no error
        })
    }

ScreenShots

Checklist

I see fetched_tracks when log album response from play.spotify() but this property is private
image

  • [yes] I have read the documentation.
  • [yes] I have tried my code with the latest version of Node.js and Play-dl.

Am I doing something wrong?

[=ASK=] Lib types behaviour-change

What would you like to discuss?

The way to extract metadata does not seem quite optimal with the .toJSON property as it works today.

Eg.

const query = await play.search(args.join(" "), { limit: 1 });
if (query[0].url) {
   const metadata = query[0].toJSON; // Would preferably return an object with the keys on the object such as
   return { title: metadata.title, url: metadata.url};
   // would allow for destructuring like this:
   const { title, url } = query[0].toJSON;
}

Typescript cannot infer what the type of play.search will be. It suggests: (Video | Channel | PlayList)[] but i cannot set any of those types explicitly on query as they are not exported by the lib(?).

As far as I can tell there's no real way of getting to the properties that .toJSON returns when the object structure looks like this when logging what .toJSON returns.

[ Video { 
    title: "",
    url: "",
    ...
} ]

Any thoughts on possibly making changes to this?

Checklist

  • I have read the documentation.

[=BUG=] Sign in to confirm your age

  • Node.js version: V16.9.1
  • OS & version: Linux/Debian 10

When we request a youtube URL with stream(url) if the video is subject to an age limit the bot crash with this error

/home/debian/discord_music/node_modules/play-dl/dist/YouTube/utils/extractor.js:67
throw new Error(`While getting info from url\n${(_k = (_j = player_response.playabilityStatus.errorScreen.playerErrorMessageRenderer) === null || _j === void 0 ? void 0 : _j.reason.simpleText) !== null && _k !== void 0 ? _k : (_l = player_response.playabilityStatus.errorScreen.playerKavRenderer) === null || _l === void 0 ? void 0 : _l.reason.simpleText}`);

Error: While getting info from url
Sign in to confirm your age
    at video_basic_info (/home/debian/discord_music/node_modules/play-dl/dist/YouTube/utils/extractor.js:67:15)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.video_info (/home/debian/discord_music/node_modules/play-dl/dist/YouTube/utils/extractor.js:120:16)
    at async Object.stream (/home/debian/discord_music/node_modules/play-dl/dist/YouTube/stream.js:27:16)
    at async module.exports (/home/debian/discord_music/module/playRandomMusic.js:22:18)
    at async AudioPlayer.<anonymous> (/home/debian/discord_music/module/clentReady.js:22:20)

[=BUG=] Song is normally end at mid of song

Describe the bug

  • Node.js version: 16.6.2
  • OS & version: ubuntu 20.04

Thank you for your kind feedback and light-weight youtube module! So now I am using your module for my discord bot.
In v0.7.3, there's no critical bug or error like uncaught error. However, when I play the long song (duration is longer than 1h), song is normally end at mid of song.

Actual behavior

Expected behavior

Code to reproduce

ScreenShots

image

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Play-dl.

[=BUG=] Error 401 Unauthorized

Describe the bug

  • Node.js version: v16.8.0(May vary due to build system, locked to v16 and above)
  • OS & version: Heroku Node Buildpack, latest release

Error 401 (Unauthenticated) occurs after playing a Livestream for an hour.
Livestream is confirmed to be non-copyright, and not age-restricted.

Actual behavior

Server Startup, Stream Initiated
Random amount of time passes(around 1 hour, sometimes more, sometimes less)
Server Crash, Error 401 thrown.

Expected behavior

Server Startup, Stream Initiated
Stream perpetually runs.

Code to reproduce

player = createAudioPlayer({ behaviors: { noSubscriber: NoSubscriberBehavior.Pause } });
const source = await stream(STREAM_URL);
player.play(createAudioResource(source.stream, { inputType: source.type }));

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Play-dl.

[=BUG=] validate() and yt_validate() returning a false promise even with a valid playlist link.

Describe the bug

  • Node.js version: 16.9.1
  • OS & version: Windows 10

The validate() and yt_validate() function returns a Promise<false> | false even when it's provided with a valid playlist link.

Actual behavior

Return a false promise even with a valid link.

Expected behavior

Should returned a yt_playlist type.

Code to reproduce

import Command from "../structures/Command";
import { validate } from 'play-dl'

export default new Command({
	name: "test",
	description: "test",
	async execute(message, args) {
		const val = await validate(args[0])
		console.log(args[0])
		console.log(val)
	}
})

ScreenShots

image

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Play-dl.

[=Feature=] Live Stream - HLS manifest

What problem are you trying to solve?

Live Stream still uses HLS manifest, need to upgrade to Dash Manifest for better efficiency

Describe the feature

Change Live Stream to Dash Manifest

Checklist

  • I have read the documentation and made sure this feature doesn't already exist.

[=FEATURE=] Accept IDs for developer convenience

What problem are you trying to solve?

Passing only links to the lib is inconvenient and can easily lead to logical issues on the developer's end. The lib should instead accept both links and IDs and also offer a method to extract an ID from arbitrary string input similar to ytdl-core. Whether or not it parses an actual ID or what is intended to be a search result can be up to the developer and not this lib.

Describe the feature

// example
require("play-dl").extractID(`https://www.youtube.com/watch?v=kJQP7kiw5Fk`) // kJQP7kiw5Fk
require("play-dl").extractID("kJQP7kiw5Fk") // kJQP7kiw5Fk
await require("play-dl").video_basic_info("kJQP7kiw5Fk") // Video {...

Checklist

  • I have read the documentation and made sure this feature doesn't already exist.

[=BUG=] MaxListenersExceededWarning occured in PassThrough

Describe the bug

  • Node.js version: 16.6.2
  • OS & version: ubuntu 20.04
(node:79419) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:79419) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:79419) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 finish listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:79419) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 unpipe listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:79419) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:79419) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:79419) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:79419) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 finish listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:79419) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 unpipe listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:79419) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:79419) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 finish listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:79419) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:79419) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:79419) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 finish listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:79419) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 unpipe listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:79419) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:79419) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:79419) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 finish listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:79419) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 unpipe listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:79419) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:79419) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:79419) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 finish listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:79419) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 unpipe listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:79419) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:79419) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:79419) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 finish listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(node:79419) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 unpipe listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit

I got this error log. I think cause in Stream class, play-dl add the listener to same stream (this.stream) repeatedly in loop method.
It should be fixed.

Actual behavior

Expected behavior

Code to reproduce

ScreenShots

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Play-dl.

[=BUG=] .toJSON

Describe the bug

  • Node.js version: 16.9.1
  • OS & version: Mac OS Big Sur

Code to reproduce

    import * as play from "play-dl";
    ...
    let yt_info = await play.search("nestor 1989 audio", { limit: 1 });
    console.log(yt_info[0].toJSON);

Error

/Users/X/Documents/git/X/node_modules/play-dl/dist/YouTube/classes/Video.js:41
            thumbnail: (_a = this.thumbnail) === null || _a === void 0 ? void 0 : _a.toJSON(),
                                                                                     ^

TypeError: _a.toJSON is not a function
    at Video.get toJSON [as toJSON] (/Users/X/Documents/git/X/node_modules/play-dl/dist/YouTube/classes/Video.js:41:86)
    at App.<anonymous> (/Users/jX/Documents/git/X/dist/app.js:73:48)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/X/Documents/git/X/dist/app.js:24:58)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Play-dl.

[=FEATURE=] Cleaning of useless Codes

What problem are you trying to solve?

Cleanup of useless codes in play-dl.

Describe the feature

Just removing useless codes in my milestone

Checklist

  • I have read the documentation and made sure this feature doesn't already exist.

[=BUG=] Playing age restricted video gives 410 error

Describe the bug

  • Node.js version: v16.8.0
  • OS & version: Ubuntu 18.04.5 LTS

Actual behavior

I'm trying to play a video that is age restricted but I am getting an error and video does not play on my Discord bot.

Expected behavior

Playing the video without problems and no error in console.

Code to reproduce

ScreenShots

image

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Play-dl.

[=BUG=] Playing music through youtube crashes

Following README example

  • Node.js version: 16.9.1
  • OS & version: Mac OS Big Sur

Actual behavior

Bot joins channel fine, then it crashes.

Expected behavior

It starts playing music.

Code to reproduce

  public startBot = async (): Promise<void> => {
    await this.login();
    this.client.on("ready", () => {
      console.log("Bot is running... ✅", this?.client?.user?.tag);
    });

    this.client.on("messageCreate", async (message: Message) => {
      if (!message.content.startsWith(this.prefix) || message.author.bot) {
        return;
      }

      const args = message.content.slice(this.prefix.length).split(/ +/);
      const cmd = args.shift()?.toLowerCase();
      if (cmd === "play") {
        if (!message?.member?.voice?.channel)
          await message.channel.send("Connect to a Voice Channel");
        else if (
          message.member?.voice.channel &&
          message.guild &&
          message.guild.id
        ) {
          const connection = joinVoiceChannel({
            channelId: message.member.voice.channel.id,
            guildId: message.guild.id,
            adapterCreator: message.guild.voiceAdapterCreator,
          });

          let yt_info = await play.search(args.join(" "), { limit: 1 });
          if (!yt_info[0].url) return;
          let stream = await play.stream(yt_info[0].url);
          let resource = createAudioResource(stream.stream, {
            inputType: stream.type,
          });
          let player = createAudioPlayer({
            behaviors: {
              noSubscriber: NoSubscriberBehavior.Play,
            },
          });
          player.play(resource);
          await message.channel.send(`Now playing **${args.join(" ")}**`);
          connection.subscribe(player);
        }
      } else if (cmd) command(this.client, message, cmd, args);
    });
  };

ScreenShots

node:events:371
throw er; // Unhandled 'error' event
^

Error: read ECONNRESET
at TLSWrap.onStreamRead (node:internal/stream_base_commons:220:20)
Emitted 'error' event on ClientRequest instance at:
at TLSSocket.socketErrorListener (node:_http_client:447:9)
at TLSSocket.emit (node:events:394:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -54,
code: 'ECONNRESET',
syscall: 'read'
}

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Play-dl.

[=BUG=] HTTPError: Response code 403 (Forbidden)

Describe the bug

  • Node.js version: 16.6.2
  • OS & version: ubuntu 20.04
node:events:371
      throw er; // Unhandled 'error' event
      ^

HTTPError: Response code 403 (Forbidden)
    at Request._onResponseBase (/home/ubuntu/bot/node_modules/got/dist/source/core/index.js:899:31)
    at Request._onResponse (/home/ubuntu/bot/node_modules/got/dist/source/core/index.js:934:24)
    at ClientRequest.<anonymous> (/home/ubuntu/bot/node_modules/got/dist/source/core/index.js:948:23)
    at Object.onceWrapper (node:events:514:26)
    at ClientRequest.emit (node:events:406:35)
    at ClientRequest.origin.emit (/home/ubuntu/bot/node_modules/@szmarczak/http-timer/dist/source/index.js:43:20)
    at HTTPParser.parserOnIncomingClient (node:_http_client:621:27)
    at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17)
    at TLSSocket.socketOnData (node:_http_client:487:22)
    at TLSSocket.emit (node:events:394:28)
Emitted 'error' event on Request instance at:
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  code: undefined,
  timings: {
    start: 1630298022597,
    socket: 1630298022597,
    lookup: 1630298022678,
    connect: 1630298022680,
    secureConnect: 1630298022685,
    upload: 1630298022686,
    response: 1630298022688,
    end: 1630298022689,
    error: undefined,
    abort: 1630298022690,
    phases: {
      wait: 0,
      dns: 81,
      tcp: 2,
      tls: 5,
      request: 1,
      firstByte: 2,
      download: 1,
      total: 93
    }
  }
}

I got this error even if I handled error event of AudioPlayer(discordjs/voice)

Actual behavior

Expected behavior

Code to reproduce

ScreenShots

Checklist

  • [o] I have read the documentation.
  • [o] I have tried my code with the latest version of Node.js and Play-dl.

[=BUG=] TypeError: player_response.streamingData.adaptiveFormats is not iterable (cannot read property undefined)

Describe the bug

  • Node.js version: 16.9.1
  • OS & version: ubuntu 20.04

Actual behavior

song url: https://www.youtube.com/watch?v=tL7HKKEoW1Y
Error is occured

TypeError: player_response.streamingData.adaptiveFormats is not iterable (cannot read property undefined)
    at video_basic_info (/home/ubuntu/bot/node_modules/play-dl/dist/YouTube/utils/extractor.js:95:12)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.video_info (/home/ubuntu/bot/node_modules/play-dl/dist/YouTube/utils/extractor.js:120:16)
    at async stream (/home/ubuntu/bot/node_modules/play-dl/dist/YouTube/stream.js:27:16)

Expected behavior

No any error.

Code to reproduce

ScreenShots

image
Some video doesn't have player_response.streamingData.adaptiveFormats like this.

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Play-dl.

Playlists

What would you like to discuss?

Is it possible when getting playlist info to fetch the videos despite there being hidden videos within the playlist?

Checklist

  • [ X ] I have read the documentation.

Playlist Bug

Describe the bug

  • Node.js version:

  • OS & version:

             throw new Error(`While parsing playlist url\n   ${response.alerts[0].alertWithButtonRenderer.text.simpleText}`);
                   ^
    

Error: While parsing playlist url
অনুপলভ্য ভিডিওগুলি আড়ালে আছে
at Object.playlist_info (E:\Work\DISCORD JS\Working Files\oculetbot\node_modules\play-dl\dist\YouTube\utils\extractor.js:130:23)
at processTicksAndRejections (node:internal/process/task_queues:96:5)

Actual behavior

Expected behavior

Code to reproduce

ScreenShots

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Play-dl.

[=BUG=] Handeling of legacy format videos

Describe the bug

  • Node.js version: 16.11.0
  • OS & version: Windows 10
  • play-dl version: 1.0.8

When trying to stream a video with only legacy formats available (video and audio merged into mp4), play-dl tries to read the codec property of undefined.

The video in question only provides a 360p mp4 stream: https://youtube.com/watch?v=aA6zYJNPWXI

Actual behavior

Uncaught TypeError: Cannot read properties of undefined (reading 'codec')
    at Object.stream (C:\workspace\boombox_bot\node_modules\.pnpm\[email protected]\node_modules\play-dl\dist\YouTube\stream.js:54:45)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async stream (C:\workspace\boombox_bot\node_modules\.pnpm\[email protected]\node_modules\play-dl\dist\index.js:49:16)

Expected behavior

Ideally play-dl would handle legacy format videos by piping the stream to ffmpeg to convert to opus, it might have a noticable performance impact depending on the host machine. Alternatively play-dl could throw an error stating that the video doesn't provide a format that play-dl is capable of dealing with, that way each developer could decide for themselves how they want to handle such cases.

Code to reproduce

const { stream } = require('play-dl');

(async function() {
    await stream('aA6zYJNPWXI');
})();

ScreenShots

See console output in the Actual behavior section

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Play-dl.

[=FEATURE=] Seek option

Add stream option to download from audio begin to download at defined start

For example i wan't to download audio at the 7 second, i can with this option

Stream

Create stream from extracted urls.

[=BUG=] Cannot read property split of undefined when extracting youtu.be url ID.

Describe the bug

  • Node.js version: 16.0.0
  • OS & version: Windows 11
> const yt = require("play-dl");
undefined
> yt.extractID("https://youtu.be/nBcTKyqwlcI");
Uncaught TypeError: Cannot read property 'split' of undefined
    at yt_validate (C:\Users\papi\Documents\GitHub\Volcano\node_modules\play-dl\dist\YouTube\utils\extractor.js:22:46)
    at Object.extractID (C:\Users\papi\Documents\GitHub\Volcano\node_modules\play-dl\dist\YouTube\utils\extractor.js:58:19)

Actual behavior

The function errors

Expected behavior

The ID gets extracted properly

Code to reproduce

Refer to console output for code used

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Play-dl.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.