android youtube download url 403 forbidden
android, download, youtube
Solution
This video is using cipher signature. As you can see in the info returned by http://www.youtube.com/get_video_info?video_id=itGNQbJwRSk, it has
'use_cipher_signature=True'
To download this type of video, first you have to decode its signature. Decoding algorithm is present in the player file (HTML5player or Flash player).
After decoding you have to use the same IP address to download the video from where you have fetched all the information. (You can bypass same IP restriction using Proxy)
It's better to scrape the webpage of that particular video and search for `;ytplayer.config = {(.*?)};` . This contains all the required information.
If you don't want to scrape then you can use below method to get the JSON object:
https://www.youtube.com/watch?v=<Video-ID>&spf=prefetch
Please check this API for easy solution: CipherAPI.
Another cool API: YTstream API.
Problem
there are some videos that can't download. I got download url by using this ``` http://www.youtube.com/get_video_info?video_id=itGNQbJwRSk ``` Is there anyone why below url is not available to download? total url: ``` http://r1---sn-a5m7lnek.googlevideo.com/videoplayback?expire=1391267516&ms=au&source=youtube&sver=3&upn=OzZzFV_-2o4&id=8ad18d41b2704529&itag=22&mt=1391243224&ipbits=0&ratebypass=yes&fexp=935622%2C914924%2C926515%2C916623%2C936910%2C936913&sparams=gcr%2Cid%2Cip%2Cipbits%2Citag%2Cratebypass%2Csource%2Cupn%2Cexpire&mv=m&ip=183.101.166.55&key=yt5&gcr=kr&signature=F303D0C863C27A6A46124A09E40F308BB67181E013.3FA3E17460DDF6ECA004D9E48B1356849534EBFFFF ``` separated url with each params: ``` http://r1---sn-a5m7lnek.googlevideo.com/videoplayback? expire=1391267516& ms=au& source=youtube& sver=3& upn=OzZzFV_-2o4& id=8ad18d41b2704529& itag=22& mt=1391243224& ipbits=0& ratebypass=yes& fexp=935622%2C914924%2C926515%2C916623%2C936910%2C936913& sparams=gcr%2Cid%2Cip%2Cipbits%2Citag%2Cratebypass%2Csource%2Cupn%2Cexpire& mv=m& ip=183.101.166.55& key=yt5& gcr=kr& signature=F303D0C863C27A6A46124A09E40F308BB67181E013.3FA3E17460DDF6ECA004D9E48B1356849534EBFFFF ``` and I used below codes in open stream ``` u = new URL(url); HttpURLConnection huc = (HttpURLConnection)u.openConnection();//to know the size of video huc.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.102 Safari/537.36"); huc.setRequestProperty("Accept","*/*"); huc.setRequestMethod("GET"); huc.setDoOutput(false); int size = huc.getContentLength(); int status = huc.getResponseCode(); Log.e("download", status+ huc.getResponseMessage()); is = new BufferedInputStream(huc.getInputStream()); ``` but it returns status = 403, size = -1. I couldn't find anything to help yet. Is there anyone have a idea?