TimeForANinja/node-ytpl

TypeError: Cannot read property '4' of null

dinaAlsaid opened this issue ยท 28 comments

TypeError: Cannot read property '4' of null

    async function getPlaylistHandler(req, res) {
    const playlist = await ytpl(req.body.playlist);
  at Object.<anonymous>.exports.getGeneralInfo (node_modules/ytpl/lib/util.js:39:31)
  at Object.<anonymous>.module.exports (node_modules/ytpl/lib/firstpage.js:29:25)
  at Object.<anonymous>.module.exports (node_modules/ytpl/lib/main.js:13:20)
  at getPlaylistHandler (lib/server.js:56:20)

version installed: 1.0.1

I can confirm that this issue is happening to me too

i have been getting the same

(node:3956) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '4' of null
at Object.exports.getGeneralInfo (C:\Users\Galactica\Desktop\ytpl\YOUTUBE CODE\node_modules\ytpl\lib\util.js:39:31)
at module.exports (C:\Users\Galactica\Desktop\ytpl\YOUTUBE CODE\node_modules\ytpl\lib\firstpage.js:29:25)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async module.exports (C:\Users\Galactica\Desktop\ytpl\YOUTUBE CODE\node_modules\ytpl\lib\main.js:13:20)
(node:3956) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:3956) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Ya this happened to me too. Pretty weird how it worked just several hours ago but now it is giving errors.

๐Ÿค” looks like we're in for the same changes as ytsr

I had a quick look. The regex is failing. Seems like the HTML has changed. The initial error started with authorMatch and then fails at the playlist as well.

Any idea of when a fix is going to happen?

dbrn commented

I'm going to investigate it tomorrow, and hopefully find a fix that works for me. If I'm finding one, I'm going to open a PR.

dbrn commented

The response body from youtube has dramatically changed. It seems that now it returns a sort of javascript object where most of the data can be retrieved. I've included a dump of that object that I got from firstpage.js at line 14.
In utils.js most of the data is retrieved via regular expressions. I think that browsing and retrieving data from the object is way more convenient and most of the utils.js file should be rewritten, at this point.
I'm taking a break for tonight, I'll keep you updated during the weekend as I work further on the issue.
If someone wants to continue from where I got, please ping me here so none of us will waste time ;)
I attached a zip file containing the object I got.
Thank you.
ytdata.js.zip

dbrn commented

I've almost finished fixing the function getGeneralInfo in /lib/utils.js.
I think that I will be able to finish it, and probably the other functions as well by tomorrow.
I'm heading to bed! ;)

dbrn commented

I uploaded my fix, I don't know if it will be merged, but feel free to use it while waiting for an official merge or improvement. You can find it in the pull requests.

I uploaded my fix, I don't know if it will be merged, but feel free to use it while waiting for an official merge or improvement. You can find it in the pull requests.

Thanks heaps!
How do you install specific branches?

Doesn't seem to be working even after updating that file

dbrn commented

I've a couple ideas why it's not working. Please send me the playlists you are using, so I can understand why it happens

I updated the util.js file to what you made it unless I did something wrong?
But here is the playlist link I tried: https://www.youtube.com/playlist?list=PLMC9KNkIncKtPzgY-5rmhvj7fax8fdxoj
image

@dbrn check my comments in the pull request if you want more playlist not working. i got a error with json.parse and another one with string.replace(/\n\r?/g, ' ')

thanks

dbrn commented

@dbrn check my comments in the pull request if you want more playlist not working. i got a error with json.parse and another one with string.replace(/\n\r?/g, ' ')

thanks

I'm giving it a look just now :)

dbrn commented

Thank you everybody for your feedback and links!.
I added a new commit. Check the latest one, where I took your URLs as examples and did my best to fix the bugs that arose.

This repo is very slow and inactive. Just use youtube-dl or YouTube's data API which can fetch playlist details easily

dbrn commented

This repo is very slow and inactive. Just use youtube-dl or YouTube's data API which can fetch playlist details easily

Some people would have to rewrite their code to switch libraries. Finding a way to make it work again could be an easier solution.

This repo is very slow and inactive. Just use youtube-dl or YouTube's data API which can fetch playlist details easily

Some people would have to rewrite their code to switch libraries. Finding a way to make it work again could be an easier solution.

This repo is very slow and inactive. Just use youtube-dl or YouTube's data API which can fetch playlist details easily

Also, I much prefer the promise based coding format of this library rather than the event listening based format of something like youtube-dl.

Some people would have to rewrite their code to switch libraries. Finding a way to make it work again could be an easier solution.

Also, I much prefer the promise based coding format of this library rather than the event listening based format of something like youtube-dl.

I agree with you, but if it takes such a long time to update this library every time it breaks, it's time to consider switching to a more reliable library.

Secondly, take a look into YouTube's data API and see if it fits your needs. I switched to it after ytpl broke and I'm finding it to be very fast and more reliable. Plus it has a quota of 10,000 free requests per day which is more than enough in most cases.

This repo is very slow and inactive. Just use youtube-dl or YouTube's data API which can fetch playlist details easily

I always recommend the official api but it doesn't fit everyone's needs

I agree with you, but if it takes such a long time to update this library every time it breaks, it's time to consider switching to a more reliable library.

Gotta defend myself.
Most times the Problem is YouTube using rolling releases which means that just few people experience the problem and i am unable to recreate them.
This time it's just covid & working in IT that's keeping me way 2 busy.

This repo is very slow and inactive. Just use youtube-dl or YouTube's data API which can fetch playlist details easily

I always recommend the official api but it doesn't fit everyone's needs

I agree with you, but if it takes such a long time to update this library every time it breaks, it's time to consider switching to a more reliable library.

Gotta defend myself.
Most times the Problem is YouTube using rolling releases which means that just few people experience the problem and i am unable to recreate them.
This time it's just covid & working in IT that's keeping me way 2 busy.

Fair enough. Hope you're doing well. Tbh I don't mind waiting. I much much prefer your libraries because of the promise based coding. Also because it's fully anonymous youtube downloader.
Also, it is nice to see that you are alive and well and not another creator of an npm library that lets it gather dust for years.

@dbrn where's your code? I don't see a PR

@TimeForANinja I think we could apply evolutionary algos to traversing a parsed HTML or a bunch of parsing rules and run them on known playlists with expected output. I don;t really know how this library works exactly - the magic of using a library instead of rolling your own ;)
Do you think it could work?

evolutionary algos to traversing a parsed HTML

no idea if it work's but just throwing ML at everything would crush efficiency

@dbrn where's your code? I don't see a PR

it was merged in a secondary branch to do some more work, you can find it in the closed pull request. #88

I meant to produce patches with them, not to use them in runtime.

I took a look at the page source of a playlist and got another idea - to make a fuzzy search on paths in json.
I got to a point of being able to fuzzy search paths pointing to string values. Need more work before I can get an array of items that way.

[edit]
got the first demo of fuzzy searching for an object
https://github.com/naugtur/fluffy-eureka