android-youtubeExtractor
android-youtubeExtractor copied to clipboard
ytFiles.get(itag).getUrl() returns null
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
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 ?
https://www.youtube.com/watch?v=ZSM3w1v-A_Y
Any progress here? In my case onUrisAvailable callback returns ytFiles==null. But earlier it was working fine. Maybe youtube change smth?
Asking again... Any progress here??
@YogevUzan I have started to using this library: https://github.com/Commit451/YouTubeExtractor
@Skullper Thanks! I'll start using it too...
- Do you know if there's a way to get video information ?
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();
}
@jeroenstevens thank you man, your solution is working well.
@jeroenstevens itags 137 no sound comes out are there another index beside 22, 18, 137, 17?
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);
}
hi , youtube video url are played , but if video is live at current time then getting error
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
### 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<YtFile> 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);
``
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.
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 :))
for me tag=18 worked
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)
is there any way we can download 137(1080) video with audio?
Is there any way to get audio also
hi , youtube video url are played , but if video is live at current time then getting error
Do you get the solution?
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