-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrob.py
More file actions
80 lines (63 loc) · 2.34 KB
/
rob.py
File metadata and controls
80 lines (63 loc) · 2.34 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import yt_dlp
import argparse
import os
import shutil
import sys
parser = argparse.ArgumentParser(description="rob - file and YouTube downloader")
parser.add_argument("url", nargs="?", help="File URL or YouTube video URL")
parser.add_argument("-q", "--quality", help="Video quality (e.g., 720, 480, best, worst)(to be used with -v)", default="best")
parser.add_argument("-f", "--file", help="Download a normal file instead of a video", action="store_true")
parser.add_argument("-v", "--video", help="Download a Youtube video", action="store_true")
parser.add_argument("-u", "--update", help="Updates rob", action="store_true")
args = parser.parse_args()
def has_ffmpeg():
return shutil.which("ffmpeg") is not None
####################
# File flag
####################
if args.file:
if not args.url:
print("no url provided")
sys.exit(1)
output_filename = args.url.split("/")[-1]
os.system(f'curl -L -o "{output_filename}" "{args.url}"')
print(f"file downloaded as: {output_filename}")
####################
# Video flag
####################
elif args.video:
if not args.url:
print("no url provided")
sys.exit(1)
ffmpeg_installed = has_ffmpeg()
if args.quality.isdigit():
if ffmpeg_installed:
format_string = f"bestvideo[height<={args.quality}]+bestaudio/best"
else:
format_string = f"best[height<={args.quality}]"
else:
format_string = args.quality if ffmpeg_installed else "best"
ydl_opts = {
"format": format_string,
"merge_output_format": "mp4",
"noplaylist": True
}
if not ffmpeg_installed:
print("ffmpeg not found — downloading single file without merging")
try:
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download([args.url])
except Exception as error:
print("download failed:", error)
####################
# Update rob flag
####################
elif args.update:
print("updating rob...")
os.system('curl -L -o rob-updater.bat https://github.com/HollowTechnology/rob/releases/latest/download/rob-installer.bat')
os.system('rob-updater.bat')
####################
# No flags
####################
else:
print("please provide a flag: -v for video, -f for file, or -u for update")