Skip to content

Instantly share code, notes, and snippets.

@thekindlyone
Created February 7, 2016 15:01
Show Gist options
  • Save thekindlyone/4f025f504a49d62719cc to your computer and use it in GitHub Desktop.
Save thekindlyone/4f025f504a49d62719cc to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# coding: utf-8
import re
import requests
import sys
import subprocess
def download(furl,title):
wget = subprocess.Popen(['wget','-c','-O',title, furl])
wget.wait()
return wget.returncode
def main():
if len(sys.argv)<2:
print 'url missing'
sys.exit()
else:
url=sys.argv[1]
template='http://bitcast-b.bitgravity.com/ndtvod/23372/ndtv/{}'.format
# title=re.search('(.+?)-\d+',url.rsplit('/',1)[-1]).group(1)+'.mp4'
r=requests.get(url)
vid_id=re.search("__id = '(\d+)'",r.content).group(1)
title=re.search('<meta property="og:title" content="(.+?)"/>',r.content).group(1)+'.mp4'
fn=re.search(" __filename='(.+?)'",r.content).group(1)
furl=template(fn)
result = download(furl, title)
if result==0:
print title,'downloaded'
else:
print 'Failed'
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment