I try to make a youtube video downloader, I use android-youtubeExtractor from https://jitpack.io, it's work with all video except music and video who can't be display in embded like : https://www.youtube.com/embed/q2c7Ie1Sz1Q. That's my code :
public void downloadVideo(View v){
String link = webView.getUrl();
YouTubeUriExtractor youTubeUriExtractor = new YouTubeUriExtractor(MainActivity.this) {
@Override
public void onUrisAvailable(String videoId, String videoTitle, SparseArray<YtFile> ytFiles) {
if(ytFiles != null){
int tag = 22;
String title = "test";
newLink = ytFiles.get(tag).getUrl();
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(newLink));
request.setTitle(title);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,title+".mp4");
DownloadManager downloadManager = (DownloadManager)getSystemService(Context.DOWNLOAD_SERVICE);
request.allowScanningByMediaScanner();
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
downloadManager.enqueue(request);
}
}
};
youTubeUriExtractor.execute(link);
}
Thanks