-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyt-dl.py
32 lines (25 loc) · 890 Bytes
/
yt-dl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import os
import sys
def download_video():
# first argument is the file itself
if len(sys.argv) < 2:
print('No YouTube link provided')
filename = get_filename(sys.argv[0])
print('Usage: ' + filename + ' [YouTube link]')
return
if (sys.argv[1] == 'help' or sys.argv[1] == '-h'):
filename = get_filename(sys.argv[0])
print('Usage: ' + filename + ' [YouTube link]')
return
link = sys.argv[1]
output_file = "%USERPROFILE%\Downloads\%(title)s.%(ext)s"
command = str('youtube-dl -o ' + output_file + ' ' + link + ' --extract-audio --audio-format mp3 --audio-quality 256K')
os.system(command)
def get_filename(path):
if path.rfind('\\') == -1:
filename = path
else:
last_occurence = path.rfind('\\')
filename = path[last_occurence + 1:]
return filename
download_video()