Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. import urllib.request
  2. import time
  3. import sys
  4.  
  5. def reporthook(count, block_size, total_size):
  6.     global start_time
  7.     if count == 0:
  8.         start_time = time.time()
  9.         return
  10.     duration = time.time() - start_time
  11.     progress_size = int(count * block_size)
  12.     speed = int(progress_size / (1024 * duration))
  13.     percent = int(count * block_size * 100 / total_size)
  14.     sys.stdout.write("\rСкачано: %d%% (%d MB), Скорость: %d KB/s, Прошло времени: %d сек" %
  15.                     (percent, progress_size / (1024 * 1024), speed, duration))
  16.     sys.stdout.flush()
  17.  
  18.  
  19. print('Beginning file download with urllib2...')
  20.  
  21. for x in range(1, 65):
  22.     if x < 10:
  23.         url = 'https://m1.audiokniga.club/uploads/books/book200/rus/reader103/192/00' + str(x) +'.mp3'
  24.     else:
  25.         url = 'https://m1.audiokniga.club/uploads/books/book200/rus/reader103/192/0' + str(x) +'.mp3'
  26.         pass
  27.     print(url)
  28.     urllib.request.urlretrieve(url, './0' + str(x) + '.mp3', reporthook)
  29.     print("downloaded " + str(x))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement