-
Notifications
You must be signed in to change notification settings - Fork 0
/
video2mp4.py
66 lines (58 loc) · 1.64 KB
/
video2mp4.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
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
import yt_dlp
import sys
# Define default path
path = r"./"
# Define download rate limit in byte
ratelimit = 5000000
# Define download format
format = "best[ext=mp4]"
# Get url as argument
try:
url = sys.argv[1]
except:
sys.exit("Usage: python3 thisfile.py URL")
# Download all videos of a channel
if url.startswith(
(
"https://www.youtube.com/c/",
"https://www.youtube.com/channel/",
"https://www.youtube.com/user/",
)
):
ydl_opts = {
"ignoreerrors": True,
"abort_on_unavailable_fragments": True,
"format": format,
"outtmpl": path
+ "\\Channels\%(uploader)s\%(title)s ## %(uploader)s ## %(id)s.%(ext)s",
"ratelimit": ratelimit,
}
# Download all videos in a playlist
elif url.startswith("https://www.youtube.com/playlist"):
ydl_opts = {
"ignoreerrors": True,
"abort_on_unavailable_fragments": True,
"format": format,
"outtmpl": path
+ "\\Playlists\%(playlist_uploader)s ## %(playlist)s\%(title)s ## %(uploader)s ## %(id)s.%(ext)s",
"ratelimit": ratelimit,
}
# Download single video from url
elif url.startswith(
(
"https://www.youtube.com/watch",
"https://www.twitch.tv/",
"https://clips.twitch.tv/",
)
):
ydl_opts = {
"ignoreerrors": True,
"abort_on_unavailable_fragments": True,
"format": format,
"outtmpl": path + "\\Videos\%(title)s ## %(uploader)s ## %(id)s.%(ext)s",
"ratelimit": ratelimit,
}
# Downloads depending on the options set above
if ydl_opts is not None:
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download(url)