From e804dd1aec4a326bb9782d137b789bde188d67e6 Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 19 Dec 2022 14:59:07 +0700 Subject: [PATCH] continue indexing if comment indexing failes, #383 --- .../home/src/download/yt_dlp_handler.py | 3 ++- tubearchivist/home/src/index/comments.py | 21 ++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/tubearchivist/home/src/download/yt_dlp_handler.py b/tubearchivist/home/src/download/yt_dlp_handler.py index c1d5ddde..c6d415cd 100644 --- a/tubearchivist/home/src/download/yt_dlp_handler.py +++ b/tubearchivist/home/src/download/yt_dlp_handler.py @@ -150,7 +150,8 @@ class DownloadPostProcess: for idx, video_id in enumerate(self.download.videos): comment = Comments(video_id, config=self.download.config) comment.build_json(notify=(idx, total_videos)) - comment.upload_comments() + if comment.json_data: + comment.upload_comments() key = "message:download" message = { diff --git a/tubearchivist/home/src/index/comments.py b/tubearchivist/home/src/index/comments.py index 944a1d91..14cb1a54 100644 --- a/tubearchivist/home/src/index/comments.py +++ b/tubearchivist/home/src/index/comments.py @@ -33,10 +33,10 @@ class Comments: self._send_notification(notify) comments_raw, channel_id = self.get_yt_comments() - if comments_raw: - self.format_comments(comments_raw) - else: - self.comments_format = [] + if not comments_raw and not channel_id: + return + + self.format_comments(comments_raw) self.json_data = { "youtube_id": self.youtube_id, @@ -96,6 +96,9 @@ class Comments: """get comments from youtube""" yt_obs = self.build_yt_obs() info_json = YtWrap(yt_obs).extract(self.youtube_id) + if not info_json: + return False, False + comments_raw = info_json.get("comments") channel_id = info_json.get("channel_id") return comments_raw, channel_id @@ -104,9 +107,10 @@ class Comments: """process comments to match format""" comments = [] - for comment in comments_raw: - cleaned_comment = self.clean_comment(comment) - comments.append(cleaned_comment) + if comments_raw: + for comment in comments_raw: + cleaned_comment = self.clean_comment(comment) + comments.append(cleaned_comment) self.comments_format = comments @@ -169,6 +173,9 @@ class Comments: return self.build_json() + if not self.json_data: + return + es_comments = self.get_es_comments() if not self.comments_format: