Python - download video from indirect url
Question: I have a link like this

    
    
    https://r9---sn-4g57knle.googlevideo.com/videoplayback?id=10bc30daeba89d81&itag=22&source=picasa&begin=0&requiressl=yes&mm=30&mn=sn-4g57knle&ms=nxu&mv=m&nh=IgpwcjA0LmZyYTE2KgkxMjcuMC4wLjE&pl=19&sc=yes&mime=video/mp4&lmt=1439597374686662&mt=1474140191&ip=84.56.35.53&ipbits=8&expire=1474169270&sparams=ip,ipbits,expire,id,itag,source,requiressl,mm,mn,ms,mv,nh,pl,sc,mime,lmt&signature=6EF8ABF841EA789F5314FC52C3C3EA8698A587C9.9297433E91BB6CBCBAE29548978D35CDE30C19EC&key=ck2
    

which is a temporary generated redirect from (a link like) this link:
<https://2.bp.blogspot.com/bO0q678cHRVZqTDclb33qGUXve_X1CRTgHMVz9NUgA=m22>

(so the first link won't work in a couple of hours)

How can I download the video from the _googlevideo_ site with Python? I
already tried youtube-dl because of
[this](http://stackoverflow.com/a/33818090/5635812) answer, but it isn't
working for me.

The direct URL would already help me a lot!


Answer: You can use [pycurl](http://pycurl.io/docs/latest/quickstart.html)

    
    
    #!/bin/usr/env python
    import sys
    import pycurl
    
    c = pycurl.Curl()
    c.setopt(c.FOLLOWLOCATION, 1)
    c.setopt(c.URL, sys.argv[1])
    with open(sys.argv[2], 'w') as f:
        c.setopt(c.WRITEFUNCTION, f.write)
        c.perform()
    

Usage:

    
    
    $ chmod +x a.py 
    $ ./a.py "https://2.bp.blogspot.com/bO0q678cHRVZqTDclb33qGUXve_X1CRTgHMVz9NUgA=m22" output.mp4
    $ file output.mp4
    output.mp4: ISO Media, MP4 v2 [ISO 14496-14]
    

