ytdl-js / react-native-ytdl

A YouTube downloader for React Native
120 stars 46 forks source link

Unable to retrieve metadata from link #49

Open DrEdwardPCB opened 3 years ago

DrEdwardPCB commented 3 years ago

When I tried to use the ytdl.getInfo(url).then(res=>console.log(res)) it just output a json string )]}' {"reload":"now"} [Error: Unable to retrieve video metadata] When I dig deep into the source code, I think it is probably the problem of miniget. the miniget method GET request simply cannot return anything of the video metadata But fixing it is already out of my ability.

test on react-native-ytdl 4.0.2 IOS 14.2 react native 0.63.0

DrEdwardPCB commented 3 years ago

MORE INFO exact code to reproduce should be

if (ytdl.validateURL(props.url)) {
          ytdl.getInfo(props.url).then((info) => {
                        setMetaInfo(info)
                    })
                        .catch(error => {
                            //setMetaInfo(error)
                            console.log(error)
                            setState({ type: 'FAIL' })
                        })
                } else {
                    setState({ type: 'FAIL' })
                }
AbelTesfaye commented 3 years ago

Could you provide a video id that's causing this?

DrEdwardPCB commented 3 years ago

Nearly all video I encountered have this problem. E.g. https://m.youtube.com/watch?v=J0bUGAkfutk

Sanorf commented 3 years ago

Hello, I have the same problem with a real device Huawei P20 Lite, Android 9, react-native-ytdl 3.4.2, react-native 0.63.3 100% calls to ytdl(URL), ytdl.getBasicInfo(URL), whatever the URL i use -> Error parsing info: Unable to retrieve video metadata

I tested other real devices Samsung Galaxy S8 android 9, iPhone 8 iOS 12, I don't have the problem on these devices. Even on simulator iPhone 11 ios 14.1, emulator android 8.1 -> no problem

achigo16 commented 3 years ago

This bug is from node-ytdl-core (https://github.com/fent/node-ytdl-core/issues/751) and it already fixed. So, update node-ytdl-core version is the best way to fix it

Sanorf commented 3 years ago

Yes I think this port just needs to be rebased to latest node-ytdl-core

AbelTesfaye commented 3 years ago

Should be fixed in the latest version. If not, try passing a high maxRetries like the following:

ytdl.getInfo(YOUR_URL, {
        requestOptions: { maxRetries: 100 }
      });

You are experiencing a network error, the above option will retry failed functions until they succeed.

Note: You might want to keep maxRetries under 10,000 since the retry function is implemented recursively and higher values will blow up your call stack

Sanorf commented 3 years ago

Unfortunatly it's still the same for me with the last version and until 100 retries :/ Even I had one device which didn't have this problem before and now always "Unable to retrieve video metadata". Yes it's clearly a network problem, it's not my speciality but i will dig and let you know if I find something, at least a workaround.

Sanorf commented 3 years ago

I didn't find the origin of my problem but i solved it by "homemade" sources modification.

I discovered it exists two main methods to get YT video informations:

The first method doesn't work on some devices for me, I don't know why (response blob is empty). The problem in this library inherited from node-ytdl-core is we don't try the second method if the first fails, we just throw an error. I removed the error handling and added a call to the second method and it solved my problem.

deepak-jha-kgp commented 3 years ago

Hey, @Sanorf can you please share your modified files?

deepak-jha-kgp commented 3 years ago

@AbelTesfaye does this suggestion sound good? Can we have this please?

AbelTesfaye commented 3 years ago

The above suggestion was implemented on the latest node-ytdl-core. I've rebased this library so it should be available now