Skip to content
This repository has been archived by the owner on Oct 28, 2023. It is now read-only.

ytFiles.get(itag).getUrl() returns null #54

Open
YogevUzan opened this issue Mar 8, 2018 · 21 comments
Open

ytFiles.get(itag).getUrl() returns null #54

YogevUzan opened this issue Mar 8, 2018 · 21 comments

Comments

@YogevUzan
Copy link

Hi,
I just noticed there's an issue with extracting old youtube videos.

For example:
I'm trying to download Timbaland - Apologize (2009) and app crashes,

java.lang.nullpointerexception: Attempt to invoke virtual method 'java.lang.String at.huber.youtubeExtractor.YtFile.getUrl()' on a null object reference

@hannojg
Copy link

hannojg commented Mar 8, 2018

Yes, the age gate ...
That is something that the library can’t detected
I will take a look into it tomorrow
Can you provide a url ?

@YogevUzan
Copy link
Author

@Skullper
Copy link

Any progress here?
In my case onUrisAvailable callback returns ytFiles==null.
But earlier it was working fine. Maybe youtube change smth?

@YogevUzan
Copy link
Author

Asking again...
Any progress here??

@Skullper
Copy link

Skullper commented Apr 3, 2018

@YogevUzan I have started to using this library:
https://github.com/Commit451/YouTubeExtractor

@YogevUzan
Copy link
Author

YogevUzan commented Apr 11, 2018

@Skullper Thanks! I'll start using it too...

  • Do you know if there's a way to get video information ?

@jeroenstevens
Copy link

Maybe this can be useful to somebody. One of the ways for me to fix it was to go over multiple itags (resolutions). As for the video mentioned above, the highest resolution is 480 :D

        @Override
        protected void onExtractionComplete(SparseArray<YtFile> files, VideoMeta videoMeta) {
            if (files != null) {

                // 720, 1080, 480
                List<Integer> iTags = Arrays.asList(22, 137, 18);

                for (Integer iTag : iTags) {

                    YtFile ytFile = files.get(iTag);

                    if (ytFile != null) {

                        String downloadUrl = ytFile.getUrl();

                        if (downloadUrl != null && !downloadUrl.isEmpty()) {

                            Uri youtubeUri = Uri.parse(downloadUrl);

                            mSingleSubscriber.onSuccess(youtubeUri);
                            return;

                        }

                    }

                }

            }

            onExtractionFailed();
        }

@sensoft2207
Copy link

@jeroenstevens thank you man, your solution is working well.

@masday86
Copy link

@jeroenstevens itags 137 no sound comes out
are there another index beside 22, 18, 137, 17?

@VishnuSivadasVS
Copy link

VishnuSivadasVS commented May 3, 2019

Try this while calling


                YTDownload(18);
            

                YTDownload(22);
      

My function:

public void YTDownload(final int itag){
        String VideoURLDownload = "https://www.youtube.com/watch?v=5izFFbdHnWY";
        @SuppressLint("StaticFieldLeak") YouTubeUriExtractor youTubeUriExtractor = new YouTubeUriExtractor(this) {
            @Override
            public void onUrisAvailable(String videoId, String videoTitle, SparseArray<YtFile> ytFiles) {
                if (ytFiles != null) {
                    String downloadURL = ytFiles.get(itag).getUrl();
                    Log.e("Download URL: ", downloadURL);
                    DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
                    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(downloadURL));
                    request.setTitle(videoTitle);
                    request.setDestinationInExternalPublicDir("/Downloads/YouTube-Downloader/", videoTitle + ".mp4");
                    if (downloadManager != null) {
                        downloadManager.enqueue(request);
                    }
                }
            }
        };
        youTubeUriExtractor.execute(VideoURLDownload);
    }

@imrankhanluhar
Copy link

hi , youtube video url are played , but if video is live at current time then getting error

@imrankhanluhar
Copy link

Maybe this can be useful to somebody. One of the ways for me to fix it was to go over multiple itags (resolutions). As for the video mentioned above, the highest resolution is 480 :D

        @Override
        protected void onExtractionComplete(SparseArray<YtFile> files, VideoMeta videoMeta) {
            if (files != null) {

                // 720, 1080, 480
                List<Integer> iTags = Arrays.asList(22, 137, 18);

                for (Integer iTag : iTags) {

                    YtFile ytFile = files.get(iTag);

                    if (ytFile != null) {

                        String downloadUrl = ytFile.getUrl();

                        if (downloadUrl != null && !downloadUrl.isEmpty()) {

                            Uri youtubeUri = Uri.parse(downloadUrl);

                            mSingleSubscriber.onSuccess(youtubeUri);
                            return;

                        }

                    }

                }

            }

            onExtractionFailed();
        }

can you please share the complete code here

@birdeveloper
Copy link

### for me, "int itag = 18;" worked

String youtubeLink = ("https://www.youtube.com/watch?v=" + youtubeDataModel.getVideo_id());
YouTubeUriExtractor ytEx = new YouTubeUriExtractor(getApplicationContext()) {
@OverRide
public void onUrisAvailable(String videoID, String videoTitle, SparseArray ytFiles) {
if (ytFiles != null) {
int itag = 18;
//This is the download URL
String downloadURL = ytFiles.get(itag).getUrl();
Log.e("download URL :", downloadURL);

                //now download it like a file
                new RequestDownloadVideoStream().execute(downloadURL, videoTitle);


            }

        }
    };

    ytEx.execute(youtubeLink);

``

@VishnuSivadasVS
Copy link

VishnuSivadasVS commented Oct 11, 2019

The tag 18 and 22 is working perfectly. Though there are some other problems with the URL formats too. But for now use 18 (480p) and 22 (720p). 137 (1080) is not having audio. I have mentioned the codes above.

@birdeveloper
Copy link

The tag 18 and 22 is working perfectly. Though there are some other problems with the URL formats too. But for now use 18 (480p) and 22 (720p). 137 (1080) is to having audio. I have mentioned the codes above.

roger that, boss. you are the king :))

@noushadullal
Copy link

for me tag=18 worked

@partho5
Copy link

partho5 commented Dec 16, 2020

All available formats (for an example video) :

171 webm audio only DASH audio 115k , audio@128k (44100Hz), 2.59MiB (worst)
140 m4a audio only DASH audio 129k , audio@128k (44100Hz), 3.02MiB
141 m4a audio only DASH audio 255k , audio@256k (44100Hz), 5.99MiB
160 mp4 256x144 DASH video 111k , 12fps, video only, 2.56MiB
247 webm 1280x720 DASH video 1807k , 1fps, video only, 23.48MiB
136 mp4 1280x720 DASH video 2236k , 24fps, video only, 27.73MiB
248 webm 1920x1080 DASH video 3993k , 1fps, video only, 42.04MiB
137 mp4 1920x1080 DASH video 4141k , 24fps, video only, 60.28MiB
43 webm 640x360
18 mp4 640x360
22 mp4 1280x720 (best)

@Aairaa
Copy link

Aairaa commented Jan 26, 2021

is there any way we can download 137(1080) video with audio?

@ghost
Copy link

ghost commented Mar 2, 2021

Is there any way to get audio also

@lifeofdekisugi
Copy link

hi , youtube video url are played , but if video is live at current time then getting error

Do you get the solution?

@Dkathayat
Copy link

Maybe this can be useful to somebody. One of the ways for me to fix it was to go over multiple itags (resolutions). As for the video mentioned above, the highest resolution is 480 :D

        @Override
        protected void onExtractionComplete(SparseArray<YtFile> files, VideoMeta videoMeta) {
            if (files != null) {

                // 720, 1080, 480
                List<Integer> iTags = Arrays.asList(22, 137, 18);

                for (Integer iTag : iTags) {

                    YtFile ytFile = files.get(iTag);

                    if (ytFile != null) {

                        String downloadUrl = ytFile.getUrl();

                        if (downloadUrl != null && !downloadUrl.isEmpty()) {

                            Uri youtubeUri = Uri.parse(downloadUrl);

                            mSingleSubscriber.onSuccess(youtubeUri);
                            return;

                        }

                    }

                }

            }

            onExtractionFailed();
        }

can you please share the complete code here

Well this download multiple files if that contains all the format

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