-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVideo Playlist downloader.py
49 lines (32 loc) · 1.2 KB
/
Video Playlist downloader.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
import pytube
import os
dirname = os.path.dirname(__file__)
yt_url = input("Link Here :")
playlist = pytube.Playlist(yt_url)
url_list = []
for url in playlist.video_urls:
url_list.append(url)
def on_progress(stream, chunk, bytes_remaining):
"""Callback function"""
total_size = stream.filesize
bytes_downloaded = total_size - bytes_remaining
pct_completed = bytes_downloaded / total_size * 100
print(f"Status: {round(pct_completed, 2)} %\r")
def completed_function(stream, file_path):
"""Callback function"""
print("download conmpleted \r")
print(f"downloaded : {file_path}. \r")
def startDownload(url):
yt = pytube.YouTube(url,
on_progress_callback=on_progress,
on_complete_callback=completed_function,
use_oauth=False,
allow_oauth_cache=True)
yt.streams\
.filter(progressive=True, file_extension='mp4')\
.order_by('resolution')\
.desc()\
.first()\
.download(f'{dirname}/download/videos')
for url in url_list:
startDownload(url)