-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathptube_lib.py
More file actions
44 lines (31 loc) · 974 Bytes
/
ptube_lib.py
File metadata and controls
44 lines (31 loc) · 974 Bytes
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
from pytube import YouTube
from pytube import Playlist
import re
flags = [" -p", " -d"]
download_destination = 'downloads/'
def format(command: str) -> str:
if any(word in command for word in flags):
for flag in flags:
command = re.sub(flag, "", command)
return command
def download(link:str):
global not_found_links
try:
YouTube(link).streams.filter(progressive=True, file_extension='mp4').order_by(
'resolution').desc().first().download(download_destination)
except:
if link not in flags:
print(link, "was not found")
def download_playlist(p_list: str):
playlist = Playlist(p_list)
for video in playlist.videos:
download(video)
def doc_download(command:str):
while True:
try:
links = open(command, "r").readlines()
break
except:
print(command, "was not found")
for link in links:
download(link)