From 2d613d3e53909bfc87b3b8cb13a53acf2b4a69ab Mon Sep 17 00:00:00 2001 From: Robert Goldmann <deadlocker@gmx.de> Date: Mon, 13 Apr 2020 17:44:59 +0200 Subject: [PATCH] Fixed #3 - continue downloading playlist if one video fails --- SaveMyPlaylist.py | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/SaveMyPlaylist.py b/SaveMyPlaylist.py index d3fa1fb..2b9cada 100644 --- a/SaveMyPlaylist.py +++ b/SaveMyPlaylist.py @@ -102,7 +102,6 @@ class SaveMyPlaylist: response = request.execute() items = [] - logger.info('Found {} videos in playlist'.format(len(response['items']))) for item in response['items']: snippet = item['snippet'] title = snippet['title'] @@ -134,22 +133,25 @@ class SaveMyPlaylist: logger.info('Skipping {}/{}: "{}" as it already exists'.format(idx + 1, len(self._items), fileName)) continue - logger.info('Downloading {}/{}: "{}"'.format(idx + 1, len(self._items), fileName)) - newVideos.append(item) - - ydl_opts = { - 'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]', - 'merge_output_format': 'mp4', - 'outtmpl': os.path.join(destinationFolder, fileName), - 'logger': MyLogger(), - 'progress_hooks': [my_hook] - } - - if debug: - continue - - with youtube_dl.YoutubeDL(ydl_opts) as ydl: - ydl.download(['https://www.youtube.com/watch?v={}'.format(item[self.VIDEO_ID])]) + try: + logger.info('Downloading {}/{}: "{}"'.format(idx + 1, len(self._items), fileName)) + newVideos.append(item) + + ydl_opts = { + 'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]', + 'merge_output_format': 'mp4', + 'outtmpl': os.path.join(destinationFolder, fileName), + 'logger': MyLogger(), + 'progress_hooks': [my_hook] + } + + if debug: + continue + + with youtube_dl.YoutubeDL(ydl_opts) as ydl: + ydl.download(['https://www.youtube.com/watch?v={}'.format(item[self.VIDEO_ID])]) + except Exception as e: + logger.error(f'Error while downloading video "{fileName}" with ID: "{item[self.VIDEO_ID]}"', exc_info=e) logger.info('>>> Finished Downloading') logger.info('Downloaded {} new videos'.format(len(newVideos))) -- GitLab