Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

TypeError: Cannot read property '4' of null #84

Closed
dinaAlsaid opened this issue Nov 9, 2020 · 28 comments · Fixed by #94
Closed

TypeError: Cannot read property '4' of null #84

dinaAlsaid opened this issue Nov 9, 2020 · 28 comments · Fixed by #94
Labels

Comments

@dinaAlsaid
Copy link

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

@chrisr11
Copy link

chrisr11 commented Nov 9, 2020

I can confirm that this issue is happening to me too

@chrisr11
Copy link

chrisr11 commented Nov 9, 2020

@gatestuff7
Copy link

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.

@Peppy8651
Copy link

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

@TimeForANinja
Copy link
Owner

🤔 looks like we're in for the same changes as ytsr

@octalpixel
Copy link

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.

@Muh9049
Copy link

Muh9049 commented Nov 11, 2020

Any idea of when a fix is going to happen?

@dbrn
Copy link
Contributor

dbrn commented Nov 12, 2020

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

dbrn commented Nov 13, 2020

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

dbrn commented Nov 14, 2020

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

dbrn commented Nov 15, 2020

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.

@Arniox
Copy link

Arniox commented Nov 16, 2020

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?

@Muh9049
Copy link

Muh9049 commented Nov 16, 2020

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

@dbrn
Copy link
Contributor

dbrn commented Nov 16, 2020

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

@Muh9049
Copy link

Muh9049 commented Nov 16, 2020

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

@mirsella
Copy link

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

dbrn commented Nov 16, 2020

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

dbrn commented Nov 16, 2020

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.

@chrisr11
Copy link

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

@dbrn
Copy link
Contributor

dbrn commented Nov 18, 2020

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.

@Arniox
Copy link

Arniox commented Nov 19, 2020

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.

@chrisr11
Copy link

chrisr11 commented Nov 19, 2020

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.

@TimeForANinja
Copy link
Owner

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.

@Arniox
Copy link

Arniox commented Nov 19, 2020

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.

@naugtur
Copy link

naugtur commented Nov 27, 2020

@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?

@TimeForANinja
Copy link
Owner

evolutionary algos to traversing a parsed HTML

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

@mirsella
Copy link

@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

@naugtur
Copy link

naugtur commented Nov 27, 2020

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

@TimeForANinja TimeForANinja mentioned this issue Dec 11, 2020
5 tasks
TimeForANinja added a commit that referenced this issue Dec 13, 2020
- [x] fix requests

- [x] update exaple responses

- [x] update typings

- [x] update documentation / README

- [x] rewrite tests

closes #72 
closes #83 
closes #84 
closes #100 

# Porting code
* request options for miniget were moved to `options#requestOptions`
* nextpageRef was replaced by the continuation feature => check the README for more information
*  `pages` was added as a more request-efficient alternative to `limit`
* `playlist#visibility#link_only` was renamed to `unlisted`
* all thumbnails are now Objects of type `Image` featuring `url`, `width` and `height` properties - arrays of images are always sorted by descending resolution
* all links have been renamed from `ref` to `url` to keep it consistend across all libraries
* all snake_case variables were replaced by CamelCase
* `response#result_items` is now `response#estimatedItemCount`
* all users/channels feature both the `channelID` as well as a canonical `url`
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.