Skip to content
This repository has been archived by the owner on Mar 11, 2022. It is now read-only.

default.downloadFromInfo is not a function #9

Closed
idoor88 opened this issue Jul 26, 2019 · 2 comments
Closed

default.downloadFromInfo is not a function #9

idoor88 opened this issue Jul 26, 2019 · 2 comments

Comments

@idoor88
Copy link

idoor88 commented Jul 26, 2019

Hi, I am trying to test downloading a youtube video with the following code, but got error saying: downloadFromInfo is not a function:

`videoID = "04GiqLjRO3A";

    ytdl.getInfo(videoID, {}, (err, info) => {

        console.log("componentDidMount info: ", info);

        if (err) console.log(err);

        let vd = ytdl.downloadFromInfo(info, {});

        console.log('found vd: ', vd);`

So any idea what is going on? I checked your ytdl.js file, there is no downloadFromInfo function in there.

Thanks

@jibbex
Copy link

jibbex commented Jul 27, 2019

Hello,

the downloadFromInfo() function is not implemented. ytdl-core uses the node stream module and m3u8stream to download files.

Unfortunately this packages are not available for react-native. You could use rn-fetch-blob instead. But for Android apps i would honestly stick to the native Android Download Manager. Conveniently, rn-fetch-blob offers the possibility to use the Download Manager.

Just get the wanted url with ytdl.chooseFormat and choose you preferred method to download.

ytdl.getInfo(videoID, {}, (err, info) => {
  const format = ytdl.chooseFormat(info.formats, {quality: 'highest'});
    
  RNFetchBlob
    .config({
        addAndroidDownloads: {
            useDownloadManager: true,
            mime: format.type
        }
    })
    .fetch('GET', format.url)
    .then((resp) => {
      resp.path()
  })
})

@idoor88
Copy link
Author

idoor88 commented Jul 30, 2019

Got you, thanks

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

No branches or pull requests

3 participants
@jibbex @idoor88 and others