diff --git a/SaveMyPlaylist.py b/SaveMyPlaylist.py index d3fa1fb06f01bbe725564d54ee103c558126121d..2b9cada16f7fb0b430a985c9464aae5267f76216 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)))