Advertisement
Guest User

Backup coverart

a guest
Jul 22nd, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. import httplib2
  2. import urllib2
  3. from bs4 import BeautifulSoup, SoupStrainer
  4.  
  5. def dl(url):
  6.  
  7.     file_name = url.split('/')[-1]
  8.     u = urllib2.urlopen(url)
  9.     f = open(file_name, 'wb')
  10.     meta = u.info()
  11.     file_size = int(meta.getheaders("Content-Length")[0])
  12.     print "Downloading: %s Bytes: %s" % (file_name, file_size)
  13.  
  14.     file_size_dl = 0
  15.     block_sz = 8192
  16.     while True:
  17.         buffer = u.read(block_sz)
  18.         if not buffer:
  19.             break
  20.  
  21.         file_size_dl += len(buffer)
  22.         f.write(buffer)
  23.         status = r"%10d  [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size)
  24.         status = status + chr(8)*(len(status)+1)
  25.         print status,
  26.  
  27.     f.close()
  28.  
  29. for i in range(2):
  30.     n = '%0*d' % (4, i+1)
  31.     print ("n: " + n)
  32.     http = httplib2.Http()
  33.     status, response = http.request('http://www.thecoverproject.net/view.php?cover_id=' + n)
  34.  
  35.     for link in BeautifulSoup(response,'html.parser').find_all('a'):
  36.         if link.get('href').startswith("/download_cover.php?"):
  37.             dl("http://www.thecoverproject.net" + link.get('href'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement