I am getting java.io.FileNotFoundException error while trying to download video from youtube using android-youtubeextrator lib. Full error code:
JavaScript
x
2021-05-21 19:44:19.342 5544-5694/com.example.SampleApp W/System.err: java.io.FileNotFoundException: https://www.youtube.com/get_video_info?video_id=GJVrna5Rm5U&eurl=https%3A%2F%2Fyoutube.googleapis.com%2Fv%2FGJVrna5Rm5U
2021-05-21 19:44:19.343 5544-5694/com.example.SampleApp W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:251)
2021-05-21 19:44:19.343 5544-5694/com.example.SampleApp W/System.err: at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
2021-05-21 19:44:19.345 5544-5694/com.example.SampleApp W/System.err: at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:26)
2021-05-21 19:44:19.346 5544-5694/com.example.SampleApp W/System.err: at at.huber.youtubeExtractor.YouTubeExtractor.getStreamUrls(YouTubeExtractor.java:220)
2021-05-21 19:44:19.346 5544-5694/com.example.SampleApp W/System.err: at at.huber.youtubeExtractor.YouTubeExtractor.doInBackground(YouTubeExtractor.java:196)
2021-05-21 19:44:19.346 5544-5694/com.example.SampleApp W/System.err: at at.huber.youtubeExtractor.YouTubeExtractor.doInBackground(YouTubeExtractor.java:34)
2021-05-21 19:44:19.346 5544-5694/com.example.SampleApp W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:333)
2021-05-21 19:44:19.346 5544-5694/com.example.SampleApp W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2021-05-21 19:44:19.347 5544-5694/com.example.SampleApp W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
2021-05-21 19:44:19.347 5544-5694/com.example.SampleApp W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
2021-05-21 19:44:19.347 5544-5694/com.example.SampleApp W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
2021-05-21 19:44:19.347 5544-5694/com.example.SampleApp W/System.err: at java.lang.Thread.run(Thread.java:764)
My Download Function:
JavaScript
public static void download_youtube_video(Activity activity) {
String youtubeLink = "https://www.youtube.com/watch?v=cMhbUWFJqzU";
YouTubeExtractor ytEx = new YouTubeExtractor(activity) {
@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);
DownloadManager.Request request = new DownloadManager.Request(youtubeUri);
String title = "test";
request.setTitle(title);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, title + ".mp4");
@SuppressLint("ServiceCast") DownloadManager downloadManager = (DownloadManager) activity.getSystemService(Context.DISPLAY_SERVICE);
request.allowScanningByMediaScanner();
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
downloadManager.enqueue(request);
}
}
}
}
}
};
ytEx.execute(youtubeLink);
}
I tried changing the version of android-youtubeextrator. Still it is giving same error. Please help.
Advertisement
Answer
you can track the same issue on the Lib From Github
for sample answer from there:
JavaScript
add html5=1 in your link. Sample:
https://www.youtube.com/get_video_info?video_id=Ls-blYpVgwE&html5=1&eurl=https%3A%2F%2Fyoutube.googleapis.com%2Fv%2FLs-blYpVgwE