Advertisement
Guest User

Untitled

a guest
Jan 25th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 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.         else:
  14.             if os.path.isfile(i + ".mp3"):
  15.                 print i + " is exists. Skipped."
  16.                 continue
  17.             else:
  18.                 link = api_vk.audio.search(q=i, auto_complete=1, sort=2, count=1)[1]['url']
  19.                 downloaded_file = urllib.URLopener()
  20.                 downloaded_file.retrieve(link, i + '.mp3')
  21.                 sleep(3)
  22.     print "\nAll files are downloaded.\nGood bye!"
  23.     sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement