cr_sharat

Untitled

Jan 1st, 2016
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.66 KB | None | 0 0
  1. import urllib2
  2. import os
  3. # from dragline.http import Reques
  4. # url = "http://us-7.blastvideo.ws/user_box/brimstone/videos/DTBS207_xbox.mp4?start=0"
  5. currd = os.getcwd()
  6. headers = {
  7.             'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.',
  8.             'Accept-Encoding': 'gzip, deflate, sdch',
  9.             'Accept-Language': 'en-US,en;q=0.8',
  10.             'Cache-Control': 'no-cache',
  11.             'Connection': 'keep-alive',
  12.             'Host': '176.31.237.56',
  13.             'Pragma': 'no-cache',
  14.             'User-Agent': 'Mozilla/5.0',
  15.             'X-Requested-With': 'ShockwaveFlash/17.0.0.134'
  16.           }
  17.  
  18. def download(url,file_name):
  19. # file_name = url.split('/')[-1]
  20.     # request = urllib2.Request(url,headers=headers)
  21.     # print request
  22.     u = urllib2.urlopen(url)
  23.     f = open(currd +'/'+file_name, 'wb')
  24.     meta = u.info()
  25.     file_size = int(meta.getheaders("Content-Length")[0])
  26.     print "Downloading: %s Bytes: %s" % (file_name, file_size)
  27.  
  28.     file_size_dl = 0
  29.     block_sz = 8192
  30.     while True:
  31.         buffer = u.read(block_sz)
  32.         if not buffer:
  33.             break
  34.  
  35.         file_size_dl += len(buffer)
  36.         f.write(buffer)
  37.         status = r"%10d  [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size)
  38.         status = status + chr(8)*(len(status)+1)
  39.         print status,
  40.  
  41.     f.close()
  42.  
  43. if __name__ == '__main__':
  44.     urls =  [{
  45.               "name":"Goosebumps.mp4",
  46.               "url":"http://sharesix.com/f/0orLvQ6"
  47.               }]
  48.     for i in urls:
  49.         try:
  50.             download(i['url'],i['name'])
  51.         except:
  52.             print "Error in",i['url'][0],i['name']
Add Comment
Please, Sign In to add comment