Loading

download.py

  1. from youtube_dl import YoutubeDL
  2. import sys
  3. import logging
  4. import os
  5.  
  6. if len(sys.argv) <= 1:
  7.     logging.error("No url specified")
  8.     exit()
  9.  
  10. url = sys.argv[1]
  11.  
  12. print(url)
  13.  
  14. with YoutubeDL({
  15.         'format': "bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio",
  16.         'outtmpl': '%(title)s.%(ext)s',
  17.         'writesubtitles': True,
  18.         'allsubtitles': True,
  19.         'noplaylist': True,
  20.         'geo_bypass': True,
  21.     }) as ydl:
  22.     info_dict = ydl.extract_info(url, download=True)
  23.     fn = ydl.prepare_filename(info_dict)
  24.  
  25. if os.path.exists(fn):
  26.     print("fn:\"" + fn + "\"")
  27. elif os.path.exists(os.path.splitext(fn)[0] + '.mkv'):
  28.     print("fn:\"" + os.path.splitext(fn)[0] + '.mkv' + "\"")
  29. else:
  30.     print("Error: file doesn't exist")

Comments