Reputation: 467
I want to download videos from you tube in android by programmatically..Still now i can able to stream these you tube videos.I searched in Internet..But there is no perfect solution for me..Please suggest that possible solutions for that issue..Thanks
Upvotes: 2
Views: 6834
Reputation: 619
Check this out. I use this function to extract the direct download links from a youtube video (it returns an array with links). All you need to do is to get the html code of the video (not the mobile version!) using this:
// url = youtube link (e.g. http://www.youtube.com/watch?v=fJ9rUzIMcZQ)
public String DownloadText(String url) throws IOException{
String userAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0.1)";
HttpClient client = new DefaultHttpClient();
client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, userAgent);
HttpGet request = new HttpGet(url);
HttpResponse response = client.execute(request);
String html = "";
InputStream in = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder str = new StringBuilder();
String line = null;
while((line = reader.readLine()) != null)
{
str.append(line);
}
in.close();
html = str.toString();
return html;
}
Upvotes: 3