Ametrin

VkVideoDownload

Sep 12th, 2014
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. import re
  2. from urllib.request import urlopen
  3.  
  4. def findLink(txt):
  5.     template = re.compile(r"(?:https?:\\\\\\\/\\\\\\\/)(?:[\w\.]+)\.(?:[a-z]{2,6}\.?)(?:\\\\\\\/[\w\.]*)*(?:\.mp4)")
  6.     return re.findall(template, txt)
  7.  
  8. txt = urlopen(str(input("Введите ссылку на видео: "))).read().decode("cp1251")
  9. numList = ["240", "360", "480", "720"]
  10. videoList = findLink(txt)
  11. print("Выберите качество видео: ")
  12. for i in range(len(videoList)):
  13.     videoList[i] = re.sub(r"\\\\\\\/", "/", videoList[i])
  14.     print(i+1, ": ", numList[i])
  15. num = int(input())
  16. fileName = input("Введите имя сохраняемого файла (можете оставить пустым): ")
  17. print("Загружаем...")
  18. video = urlopen(videoList[num-1]).read()
  19. if fileName == "":
  20.     fileName = numList[num-1]+".mp4"
  21. else:
  22.     if not fileName.endswith(".mp4"):
  23.         fileName += ".mp4"
  24. f = open(fileName, "wb")
  25. f.write(video)
  26. f.close()
  27. print("Готово :)")
Add Comment
Please, Sign In to add comment