]> Arthur Taft Gitweb - yt-dlp-wrapper.git/blob - universal/yt-dlp-wrapper.py
6d931dcadc730b573074553d9f309fe9ea2a7bb0
[yt-dlp-wrapper.git] / universal / yt-dlp-wrapper.py
1 import argparse
2 from pathlib import Path
3 from subprocess import run
4 from directories import Directories
5
6 dirs = Directories()
7
8 project_home = dirs.get_home()
9 audio_dir = dirs.get_audio_dir()
10 video_dir = dirs.get_video_dir()
11
12 audio_title = Path.joinpath(audio_dir, '%(title)s.%(ext)s')
13 video_title = Path.joinpath(video_dir, '%(title)s.%(ext)s')
14
15 batch_dl_file = Path.joinpath(project_home, 'batch_dl.txt')
16 requirements = Path.joinpath(project_home, 'requirements.txt')
17
18 parser = argparse.ArgumentParser(description='A wrapper script to yt-dlp')
19
20 parser.add_argument('--batch', '-b', type=bool, help='Perform batch download')
21
22 args = parser.parse_args()
23
24 def batch_convert():
25     format = str(input('Audio or Video?: ')).lower()
26
27     match format:
28         case "audio":
29             run(['yt-dlp', '-x', '-f', 'ba', '--audio-format', 'mp3', '-o', f'{audio_title}', '-a', f'{batch_dl_file}'])
30         case "video":
31             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}'])
32         case _:
33             print("Response must be 'Audio' or 'Video'!")
34
35 def normal_convert():
36     downloads_complete = False
37     while downloads_complete != True: # type: ignore
38         format = str(input('Audio or Video?: ')).lower()
39
40         url = str(input('Enter URL here: '))
41
42         val = False
43
44         match format:
45             case "audio":
46                 run(['yt-dlp', '-x', '-f', 'ba', '--audio-format', 'mp3', '-o', f'{audio_title}', f'{url}'])   
47                 while val != True:
48                     do_continue = str(input("Do you want to convert another file? (y/n): ")).lower()
49                     match do_continue:
50                         case "y":
51                             val = True
52                         case "n":
53                             downloads_complete = True
54                             val = True
55                         case _:
56                             print("Answer must be Y or N!")
57             case "video":
58                 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}'])
59                 while val != True:
60                     do_continue = str(input("Do you want to convert another file? (y/n): ")).lower()
61                     match do_continue:
62                         case "y":
63                             val = True
64                         case "n":
65                             downloads_complete = True
66                             val = True
67                         case _:
68                             print("Answer must be Y or N!")
69             case _:
70                 print("Response must be 'Audio' or 'Video'!")
71
72 run(['pip', 'install', '--update', '-r', f'{requirements}'])
73
74 if not audio_dir.exists():
75     audio_dir.mkdir()
76
77 if not video_dir.exists():
78     video_dir.mkdir()
79
80 if args.batch == True:
81     batch_convert()
82 else:
83     normal_convert()