0
votes

I'm writing an app that downloads youtube videos and I got a lttle problem.

As you might know, each video link in youtuube contains direct links to the video. When the page uses the flash flayer (and not html5 or so), it is stored in the flash object (in it's flashvar attr). My app parses that flash object and extract from it those direct links (one link for each available video quality).

I get the flash object's html code by downloading the video's html code (e.g http://www.youtube.com/watch?v=VIDEOID) and parsing it.

I use asynctask to dowload the html code (the non mobile version), and here is my downloading code :

      HttpClient client = new DefaultHttpClient();
      client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0.1)");

      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;

Now I got a little problem:

The code above doesn't download the whloe html code. The downloaded html string gets cut somewhere in the middle and I don't get the flash object part. This function works fine with other sites!

Am I doing something wrong?

Thanks :)

1
Are you really sure for the working for other sites? Have you tried a big site, such as a long entry in wikipedia?İsmet Alkan
Just tried a wikipedia entry and it didn't work neither. So I restarted eclipse and now it's OK! I set the html as text in a TextView, so maybe I just didn't see the whole HTML for some reason...eviabs

1 Answers

0
votes

Check out BasicResponseHandler.

  String html = client.execute(request, new BasicResponseHandler());