ytdl-js / react-native-ytdl

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

default.downloadFromInfo is not a function #9

Closed idoor88 closed 5 years ago

idoor88 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

Got you, thanks