Skip to content

Commit bc9bab8

Browse files
committed
added a progress bar.
1 parent 7940371 commit bc9bab8

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed
30.6 MB
Binary file not shown.

downloader.py

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,48 @@
33

44
print(f" ==========================\n Python YouTube Downloader \n​==========================\n")
55

6-
# videoURL = str(input("Enter Video Link : "))
7-
videoURL = 'https://www.youtube.com/watch?v=5cCaU6T1yFE'
8-
6+
videoURL = str(input("Enter Video Link : "))
7+
# videoURL = 'https://www.youtube.com/watch?v=5cCaU6T1yFE'
8+
9+
# Progress bar shows when a video is downloading
10+
def download_loading_bar(d):
11+
if d['status'] == 'downloading':
12+
# Get the download percentage as a float
13+
percentage = float(d['_percent_str'].replace('%', ''))
14+
# Calculate how many # symbols to print
15+
num_symbols = int(percentage / 5)
16+
# Print the loading bar with the percentage and ETA, using \r and end=''
17+
print(f"\rLoading: [{'#' * num_symbols}{'-' * (20 - num_symbols)}] {d['_percent_str']} {d['_eta_str']}", end='')
18+
19+
920
ydl_opts = {
1021
"quiet": True,
11-
'outtmpl': "%(title)s_%(id)s.%(ext)s"
22+
'outtmpl': "%(title)s_%(id)s.%(ext)s",
23+
24+
'progress_hooks': [download_loading_bar],
25+
'no_color': True,
1226
}
1327

1428
print("Fetching the info...")
1529

1630
with YoutubeDL( ydl_opts ) as ydl:
1731
vidInfo = ydl.extract_info(videoURL, download=False)
1832

19-
print("\n🔹 Title:", vidInfo.get('title', None))
20-
print("🔹 Duration:", vidInfo.get('duration', None))
21-
print("🔹 Size:", vidInfo.get('filesize_approx', None) // 1048576, "MB")
33+
vidTitle = vidInfo.get('title', None)
34+
vidDuration = vidInfo.get('duration', None)
35+
vidSize = vidInfo.get('filesize_approx', None) // 1048576
2236

23-
print("Downloading...")
37+
print("\n🔹 Title:", vidTitle)
38+
print("🔹 Duration:", vidDuration)
39+
print("🔹 Size:", vidSize , "MB")
2440

25-
ydl.download(videoURL)
41+
print("\nDownloading...")
2642

27-
print("Video is Downloaded Successfully!")
43+
ydl.download(['https://www.youtube.com/watch?v=BxUS1K7xu30'])
2844

45+
print("Downloaded Successfully! \n ")
2946

30-
3147

32-
33-
# usrChosenFormat = input("Enter Your Format number: ")
48+
3449

35-
# ydl = YoutubeDL({'format': usrChosenFormat})
36-
# ydl.download([videoURL])
50+

0 commit comments

Comments
 (0)