From: Arthur Taft Date: Fri, 22 Aug 2025 03:49:28 +0000 (-0600) Subject: create universal python script X-Git-Url: https://gitweb.arthurtaft.net/yt-dlp-wrapper.git/commitdiff_plain/bb6aae7d33e99afed7ffb1ed4bac64acfaa5e188?ds=sidebyside;hp=258367804065ef5b97546ea7665d97d05da9f856 create universal python script --- diff --git a/.gitignore b/.gitignore index 175161d..c8fbafe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,15 @@ +# Created by venv; see https://docs.python.org/3/library/venv.html + +bin/ +include/ +lib/ +lib64 +share/ +pyvenv.cfg windows/audio/ windows/video/ -windows/work/ - linux/audio/ -linux/video/ \ No newline at end of file +linux/video/ +universal/audio/ +universal/video/ +universal/__pycache__/ \ No newline at end of file diff --git a/universal/__init__.py b/universal/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/universal/directories.py b/universal/directories.py new file mode 100644 index 0000000..a27ef17 --- /dev/null +++ b/universal/directories.py @@ -0,0 +1,16 @@ +from pathlib import PurePath,Path + +class Directories(): + def __init__(self): + self.base_dir = Path.cwd() + self.audio_dir = Path.joinpath(self.base_dir, 'audio') + self.video_dir = Path.joinpath(self.base_dir, 'video') + + def get_home(self): + return self.base_dir + + def get_audio_dir(self): + return self.audio_dir + + def get_video_dir(self): + return self.video_dir \ No newline at end of file diff --git a/universal/requirements.txt b/universal/requirements.txt new file mode 100644 index 0000000..b1df116 --- /dev/null +++ b/universal/requirements.txt @@ -0,0 +1 @@ +yt-dlp diff --git a/universal/yt-dlp-wrapper.py b/universal/yt-dlp-wrapper.py new file mode 100644 index 0000000..66d66b0 --- /dev/null +++ b/universal/yt-dlp-wrapper.py @@ -0,0 +1,83 @@ +import argparse +from pathlib import Path +from subprocess import run +from directories import Directories + +dirs = Directories() + +project_home = dirs.get_home() +audio_dir = dirs.get_audio_dir() +video_dir = dirs.get_video_dir() + +audio_title = Path.joinpath(audio_dir, '%(title)s.%(ext)s') +video_title = Path.joinpath(video_dir, '%(title)s.%(ext)s') + +batch_dl_file = Path.joinpath(project_home, 'batch_dl.txt') +requirements = Path.joinpath(project_home, 'requirements.txt') + +parser = argparse.ArgumentParser(description='A wrapper script to yt-dlp') + +parser.add_argument('--batch', '-b', type=bool, help='Perform batch download') + +args = parser.parse_args() + +def batch_convert(): + format = str(input('Audio or Video?: ')).lower() + + match format: + case "audio": + run(['yt-dlp', '-x', '-f', '"ba"', '--audio-format', 'mp3', '-o', f'{audio_title}', '-a', f'{batch_dl_file}']) + case "video": + run(['yt-dlp', '-f', '"bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4] / bv*+ba/b"', '--sponsorblock-remove', 'sponsor,selfpromo,interaction', '-o', f'{video_title}', '-a', f'{batch_dl_file}']) + case _: + print("Response must be 'Audio' or 'Video'!") + +def normal_convert(): + downloads_complete = False + while downloads_complete != True: # type: ignore + format = str(input('Audio or Video?: ')).lower() + + url = str(input('Enter URL here: ')) + + val = False + + match format: + case "audio": + run(['yt-dlp', '-x', '-f', '"ba"', '--audio-format', 'mp3', '-o', f'{audio_title}', f'{url}']) + while val != True: + do_continue = str(input("Do you want to convert another file? (y/n): ")).lower() + match do_continue: + case "y": + val = True + case "n": + downloads_complete = True + val = True + case _: + print("Answer must be Y or N!") + case "video": + run(['yt-dlp', '-f', '"bv*[ext=mkv]+ba[ext=m4a]/b[ext=mkv] / bv*+ba/b"', '--sponsorblock-remove', 'sponsor,selfpromo,interaction', '-o', f'{video_title}', f'{url}']) + while val != True: + do_continue = str(input("Do you want to convert another file? (y/n): ")).lower() + match do_continue: + case "y": + val = True + case "n": + downloads_complete = True + val = True + case _: + print("Answer must be Y or N!") + case _: + print("Response must be 'Audio' or 'Video'!") + +run(['pip', 'install', '-r', f'{requirements}']) + +if not audio_dir.exists(): + audio_dir.mkdir() + +if not video_dir.exists(): + video_dir.mkdir() + +if args.batch == True: + batch_convert() +else: + normal_convert() \ No newline at end of file