Advertisement
Guest User

Untitled

a guest
Jan 25th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. def download_files(playlist):
  2.     open_text_file = open(playlist + '.txt', 'r')
  3.     read_text_file = open_text_file.read().split('\n')
  4.     for i in read_text_file:
  5.         link = api_vk.audio.search(q=i)
  6.         sleep(1)
  7.         if len(i) == 0:
  8.             print "File name is empty. Skipped."
  9.             continue
  10.         elif link[0] == 0:
  11.             print i + " not found. Skipped."
  12.             continue
  13.         elif os.path.isfile(i + ".mp3"):
  14.             print i + " is exists. Skipped."
  15.             continue
  16.         else:
  17.             link = api_vk.audio.search(q=i, auto_complete=1, sort=2, count=1)[1]['url']
  18.             downloaded_file = urllib.URLopener()
  19.             downloaded_file.retrieve(link, i + '.mp3')
  20.             sleep(3)
  21.     print "\nAll files are downloaded.\nGood bye!"
  22.     sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement