-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
158 lines (152 loc) · 5.2 KB
/
main.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import sys
import os
import time
from pytube import YouTube
from pytube import Playlist
from pytube import Channel
from pytube.cli import on_progress
from sys import argv
link = ""
linkglobal = ""
linkplaylist = ""
def clean():
if os.name == "nt":
os.system("cls")
else:
os.system("clear")
def linkgathering():
try:
link = str(input("Enter the link of the video: "))
yt = YouTube(link)
except KeyboardInterrupt:
print("\nExiting...")
sys.exit()
except:
print("Link is not valid!")
print("\nExiting...")
sys.exit()
linkglobal = link
return linkglobal
def playlistlinkgathering():
try:
link = str(input("Enter the link of the playlist: "))
playlist = Playlist(link)
except KeyboardInterrupt:
print("\nExiting...")
sys.exit()
except:
print("Link is not valid!")
print("\nExiting...")
sys.exit()
linkplaylist = link
return linkplaylist
def maincommandhandler(linkglobal):
try:
command = str(input("youtube-dl> "))
if command == "help":
print("Commands:")
print("help - Displays this message")
print("download - Downloads the video")
print("exit - Exits the program")
print("link - Displays the current link")
print("link-change - Changes the current link")
print("clear - Clears the screen")
print("info - Displays info about the video")
maincommandhandler(linkglobal)
elif command == "download":
print("Downloading...")
yt = YouTube(linkglobal,on_progress_callback=on_progress)
yd = yt.streams.get_highest_resolution()
yd.download("./YTfolder")
print("\nDownloaded!")
maincommandhandler(linkglobal)
elif command == "exit":
print("Exiting...")
sys.exit()
elif command == "":
maincommandhandler(linkglobal)
elif command == "link":
print(linkglobal)
maincommandhandler(linkglobal)
elif command == "link-change":
clean()
linkglobal = linkgathering()
maincommandhandler(linkglobal)
clean()
elif command == "clear":
clean()
maincommandhandler(linkglobal)
elif command == "info":
yt = YouTube(linkglobal)
print("Link: ", linkglobal)
print("Title: ", yt.title)
print("Views: ", yt.views)
print("Length: ", yt.length)
print("Thumbnail URL: ", yt.thumbnail_url)
print("Description: ", yt.description)
maincommandhandler(linkglobal)
else:
print("Invalid command!")
maincommandhandler(linkglobal)
except KeyboardInterrupt:
print("\nExiting...")
sys.exit()
def maincommandhandlerplaylist(linkplaylist):
try:
command = str(input("youtube-dl (playlist mode)> "))
if command == "help":
print("Commands:")
print("help - Displays this message")
print("download - Downloads the video")
print("exit - Exits the program")
print("link - Displays the current link")
print("link-change - Changes the current link")
maincommandhandlerplaylist(linkplaylist)
elif command == "download":
print("Downloading...")
yt = Playlist(linkplaylist)
for video in yt.videos:
video.register_on_progress_callback(on_progress)
print("\nDownloading: ", video.title)
video.streams.get_highest_resolution().download("./YTfolder")
print("\nDownloaded!")
maincommandhandlerplaylist(linkplaylist)
elif command == "exit":
print("Exiting...")
sys.exit()
elif command == "":
maincommandhandlerplaylist(linkplaylist)
elif command == "link":
print(linkplaylist)
maincommandhandlerplaylist(linkplaylist)
elif command == "link-change":
clean()
linkplaylist = playlistlinkgathering()
maincommandhandlerplaylist(linkplaylist)
clean()
elif command == "clear":
clean()
maincommandhandlerplaylist(linkplaylist)
elif command == "info":
yt = Playlist(linkplaylist)
print("Link: ", linkplaylist)
print("Title: ", yt.title)
maincommandhandlerplaylist(linkplaylist)
else:
print("Invalid command!")
maincommandhandlerplaylist(linkplaylist)
except KeyboardInterrupt:
print("\nExiting...")
sys.exit()
print("Welcome to youtube-dl!")
playlistorvideo = str(input("Is it a playlist or a video? (playlist/video): "))
if playlistorvideo == "playlist":
playlistorvideo = "playlist"
linkplaylist = playlistlinkgathering()
elif playlistorvideo == "video":
playlistorvideo = "video"
linkglobal = linkgathering()
if playlistorvideo == "playlist":
maincommandhandlerplaylist(linkplaylist)
elif playlistorvideo == "video":
maincommandhandler(linkglobal)