Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # This calls yt-dlp with my preferred options.
- # Prevent creation of the __pycache__ directory.
- # SOURCE: https://github.com/pytest-dev/pytest/issues/200
- import sys
- sys.dont_write_bytecode = True
- # -----
- yt_dlp_path = r'C:\ProgramData\chocolatey\lib\yt-dlp\tools\x64\yt-dlp.exe'
- download_directory = 'E:\\'
- # -----
- def get_video_url():
- url = None
- while True:
- try:
- url = input(' Youtube URL: ')
- if not str_is_none_or_whitespace(url):
- break
- clear_console()
- except ValueError as e:
- print(e)
- return url
- def str_is_none_or_whitespace(input):
- return not input or input.isspace()
- import os
- def clear_console():
- os.system('cls' if os.name in ('nt', 'dos') else 'clear')
- import subprocess
- def main():
- url = get_video_url()
- # url = r'https://www.youtube.com/watch?v=ROS3OGABTWg'
- print()
- # subprocess.run([yt_dlp_path, '--list-formats', url])
- print(' Download Directory', download_directory)
- print()
- subprocess.run([yt_dlp_path, '-f', 'bestvideo+bestaudio', '--merge-output-format', 'mp4', '--output', '"%(title)s-%(id)s.%(ext)s"', url], cwd=download_directory)
- print()
- wait_for_any_keypress()
- # ----- Press any key to continue -----
- import sys
- def wait_for_any_keypress():
- if sys.platform == 'win32':
- import os
- os.system('pause')
- elif sys.platform in ('linux2', 'darwin'):
- print('Press any key to continue . . .')
- import termios
- import tty
- stdin_file_desc = sys.stdin.fileno()
- old_stdin_tty_attr = termios.tcgetattr(stdin_file_desc)
- try:
- tty.setraw(stdin_file_desc)
- sys.stdin.read(1)
- finally:
- termios.tcsetattr(stdin_file_desc, termios.TCSADRAIN, old_stdin_tty_attr)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement