Suppress exception while downloaiding Playlist
Browse filesThis commit adds an option to suppress exception when downloading a video in a playlist ( i.e Video Unavailable ). This way rest of the playlist still continues to be downloaded instead of breaking up in the middle of the download process
- .gitignore +3 -0
- pytube/contrib/playlist.py +23 -14
.gitignore
CHANGED
@@ -41,3 +41,6 @@ _templates
|
|
41 |
_autosummary
|
42 |
|
43 |
.pytest_cache*
|
|
|
|
|
|
|
|
41 |
_autosummary
|
42 |
|
43 |
.pytest_cache*
|
44 |
+
|
45 |
+
# IDE Files
|
46 |
+
.idea/
|
pytube/contrib/playlist.py
CHANGED
@@ -15,9 +15,10 @@ class Playlist(object):
|
|
15 |
playlist
|
16 |
"""
|
17 |
|
18 |
-
def __init__(self, url):
|
19 |
self.playlist_url = url
|
20 |
self.video_urls = []
|
|
|
21 |
|
22 |
def construct_playlist_url(self):
|
23 |
"""There are two kinds of playlist urls in YouTube. One that
|
@@ -116,17 +117,25 @@ class Playlist(object):
|
|
116 |
prefix_gen = self._path_num_prefix_generator(reverse_numbering)
|
117 |
|
118 |
for link in self.video_urls:
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
prefix = next(prefix_gen)
|
128 |
-
logger.debug('file prefix is: %s', prefix)
|
129 |
-
dl_stream.download(download_path, filename_prefix=prefix)
|
130 |
else:
|
131 |
-
|
132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
playlist
|
16 |
"""
|
17 |
|
18 |
+
def __init__(self, url, suppress_exception=False):
|
19 |
self.playlist_url = url
|
20 |
self.video_urls = []
|
21 |
+
self.suppress_exception = suppress_exception
|
22 |
|
23 |
def construct_playlist_url(self):
|
24 |
"""There are two kinds of playlist urls in YouTube. One that
|
|
|
117 |
prefix_gen = self._path_num_prefix_generator(reverse_numbering)
|
118 |
|
119 |
for link in self.video_urls:
|
120 |
+
try:
|
121 |
+
yt = YouTube(link)
|
122 |
+
except Exception as e:
|
123 |
+
logger.debug(e)
|
124 |
+
if not self.suppress_exception:
|
125 |
+
raise e
|
126 |
+
else:
|
127 |
+
logger.debug('Exception suppressed')
|
|
|
|
|
|
|
128 |
else:
|
129 |
+
# TODO: this should not be hardcoded to a single user's preference
|
130 |
+
dl_stream = yt.streams.filter(
|
131 |
+
progressive=True, subtype='mp4',
|
132 |
+
).order_by('resolution').desc().first()
|
133 |
+
|
134 |
+
logger.debug('download path: %s', download_path)
|
135 |
+
if prefix_number:
|
136 |
+
prefix = next(prefix_gen)
|
137 |
+
logger.debug('file prefix is: %s', prefix)
|
138 |
+
dl_stream.download(download_path, filename_prefix=prefix)
|
139 |
+
else:
|
140 |
+
dl_stream.download(download_path)
|
141 |
+
logger.debug('download complete')
|