Python - download video from indirect url
<p>I have a link like this</p>

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

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

<p>(so the first link won't work in a couple of hours)</p>

<p>How can I download the video from the <em>googlevideo</em> site with Python?
I already tried youtube-dl because of <a href="http://stackoverflow.com/a/33818090/5635812">this</a> answer, but it isn't working for me.</p>

<p>The direct URL would already help me a lot!</p>

<p>You can use <a href="http://pycurl.io/docs/latest/quickstart.html" rel="nofollow">pycurl</a></p>

<pre><code>#!/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()
</code></pre>

<p>Usage:</p>

<pre><code>$ 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]
</code></pre>

python url video web-scraping