3

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

Kalai
  • 469
  • 2
  • 9
  • 20

1 Answers1

4

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;
    }
Community
  • 1
  • 1
eviabs
  • 621
  • 1
  • 8
  • 24
  • Which tag should i use to download the video? I mean in which tag i can find the direct download url? – Mitesh Shah Apr 08 '15 at 10:21
  • Unfortunately, there is no tag that holds the direct link. The flash object holds all of the needed parameters, and you need to extract them and reproduce the direct link. – eviabs Apr 10 '15 at 23:12
  • Ok. Thank you. I got it. I needed to create the new link from the different tags. Finally, i have make it – Mitesh Shah Apr 15 '15 at 06:13
  • @MiteshShah can you pls help me to do same. – Chintan Khetiya Sep 09 '15 at 13:40
  • @MiteshShah Bro, i am also in need of help to find direct link to download with download manager from youtube link, please please help me all of you guys – Pir Fahim Shah Sep 15 '17 at 10:37