diff --git a/backend/appsettings/src/filesystem.py b/backend/appsettings/src/filesystem.py index f481d5c9..0a609289 100644 --- a/backend/appsettings/src/filesystem.py +++ b/backend/appsettings/src/filesystem.py @@ -8,7 +8,7 @@ import os from common.src.env_settings import EnvironmentSettings from common.src.es_connect import IndexPaginate from common.src.helper import ignore_filelist -from video.src.comments import CommentList +from video.src.comments import Comments from video.src.index import YoutubeVideo, index_new_video @@ -88,8 +88,5 @@ class Scanner: ) json_data = index_new_video(youtube_id) if json_data: + Comments(youtube_id).build_json(upload=True) YoutubeVideo(youtube_id).embed_metadata() - - comment_list = CommentList(task=self.task) - comment_list.add(video_ids=list(self.to_index)) - comment_list.index() diff --git a/backend/appsettings/src/manual.py b/backend/appsettings/src/manual.py index 6b67a010..3be2b52b 100644 --- a/backend/appsettings/src/manual.py +++ b/backend/appsettings/src/manual.py @@ -16,7 +16,7 @@ from common.src.env_settings import EnvironmentSettings from common.src.helper import ignore_filelist from download.src.thumbnails import ThumbManager from PIL import Image -from video.src.comments import CommentList +from video.src.comments import Comments from video.src.index import YoutubeVideo from yt_dlp.utils import ISO639Utils @@ -145,13 +145,9 @@ class ImportFolderScanner: print(f"manual import: {current_video}") ManualImport(current_video, config).run() + Comments(current_video["video_id"]).build_json(upload=True) YoutubeVideo(current_video["video_id"]).embed_metadata() - video_ids = [i["video_id"] for i in self.to_import] - comment_list = CommentList(task=self.task) - comment_list.add(video_ids=video_ids) - comment_list.index() - def _notify(self, idx, current_video): """send notification back to task""" filename = os.path.split(current_video["media"])[-1] diff --git a/backend/video/src/comments.py b/backend/video/src/comments.py index d72ead6c..368b5b0b 100644 --- a/backend/video/src/comments.py +++ b/backend/video/src/comments.py @@ -25,7 +25,7 @@ class Comments: self.is_activated = False self.comments_format = False - def build_json(self): + def build_json(self, upload: bool = False): """build json document for es""" print(f"{self.youtube_id}: get comments") self.check_config() @@ -44,6 +44,8 @@ class Comments: "comment_channel_id": channel_id, "comment_comments": self.comments_format, } + if upload: + self.upload_comments() def check_config(self): """read config if not attached""" diff --git a/backend/video/src/index.py b/backend/video/src/index.py index d62bf8c9..e039aaa8 100644 --- a/backend/video/src/index.py +++ b/backend/video/src/index.py @@ -424,14 +424,6 @@ class YoutubeVideo(YouTubeItem, YoutubeSubtitle): def embed_metadata(self): """embed metadata for video""" - if self.config["downloads"].get("add_metadata"): - self._embed_text_data() - - if self.config["downloads"].get("add_thumbnail"): - self._embed_artwork() - - def _embed_text_data(self): - print(f"{self.youtube_id}: embed metadata") if not self.json_data: self.get_from_es() @@ -439,6 +431,15 @@ class YoutubeVideo(YouTubeItem, YoutubeSubtitle): print(f"{self.youtube_id}: skip embed, video not indexed") return + if self.config["downloads"].get("add_metadata"): + self._embed_text_data() + + if self.config["downloads"].get("add_thumbnail"): + self._embed_artwork() + + def _embed_text_data(self): + """embed text metadata""" + print(f"{self.youtube_id}: embed metadata") video_base = EnvironmentSettings.MEDIA_DIR media_url = self.json_data.get("media_url") file_path = os.path.join(video_base, media_url) @@ -492,13 +493,6 @@ class YoutubeVideo(YouTubeItem, YoutubeSubtitle): def _embed_artwork(self): """embed artwork""" print(f"{self.youtube_id}: embed artwork") - if not self.json_data: - self.get_from_es() - - if not self.json_data: - print(f"{self.youtube_id}: skip embed, video not indexed") - return - ThumbManager(self.youtube_id).embed_video_art(self.json_data) diff --git a/backend/video/src/meta_embed.py b/backend/video/src/meta_embed.py index 1087929f..e3be281c 100644 --- a/backend/video/src/meta_embed.py +++ b/backend/video/src/meta_embed.py @@ -1,4 +1,8 @@ -"""bulk metadata embedding""" +""" +Functionality: +- bulk metadata embedding +- restore from embedded metadata +""" import json import os