javad_ubuntu
commited on
Commit
·
2f0400c
1
Parent(s):
d7b0e8f
Change: add progress bar for channel video downloading
Browse files- pytube/contrib/playlist.py +10 -1
pytube/contrib/playlist.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
"""Module to download a complete playlist from a youtube channel."""
|
|
|
2 |
import json
|
3 |
import logging
|
4 |
from collections.abc import Sequence
|
@@ -28,6 +29,14 @@ class Playlist(Sequence):
|
|
28 |
|
29 |
self._playlist_id = None
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
@property
|
32 |
def playlist_id(self):
|
33 |
"""Get the playlist id.
|
@@ -294,7 +303,7 @@ class Playlist(Sequence):
|
|
294 |
|
295 |
def videos_generator(self):
|
296 |
for url in self.video_urls:
|
297 |
-
yield YouTube(url)
|
298 |
|
299 |
@property
|
300 |
def videos(self) -> Iterable[YouTube]:
|
|
|
1 |
"""Module to download a complete playlist from a youtube channel."""
|
2 |
+
import sys
|
3 |
import json
|
4 |
import logging
|
5 |
from collections.abc import Sequence
|
|
|
29 |
|
30 |
self._playlist_id = None
|
31 |
|
32 |
+
def progress_callback(self, stream, chunk, bytes_remaining):
|
33 |
+
# print("Callback triggered!") # Add this line
|
34 |
+
total_size = stream.filesize
|
35 |
+
bytes_downloaded = total_size - bytes_remaining
|
36 |
+
percentage_of_completion = bytes_downloaded / total_size * 100
|
37 |
+
sys.stdout.write(f"\rDownloaded {percentage_of_completion:.2f}%")
|
38 |
+
sys.stdout.flush()
|
39 |
+
|
40 |
@property
|
41 |
def playlist_id(self):
|
42 |
"""Get the playlist id.
|
|
|
303 |
|
304 |
def videos_generator(self):
|
305 |
for url in self.video_urls:
|
306 |
+
yield YouTube(url, on_progress_callback = self.progress_callback)
|
307 |
|
308 |
@property
|
309 |
def videos(self) -> Iterable[YouTube]:
|