diff --git a/tubearchivist/home/src/index/video.py b/tubearchivist/home/src/index/video.py index cc8d65b7..48c3eeb4 100644 --- a/tubearchivist/home/src/index/video.py +++ b/tubearchivist/home/src/index/video.py @@ -426,17 +426,20 @@ class YoutubeVideo(YouTubeItem, YoutubeSubtitle): self.video_overwrites = video_overwrites self.es_path = f"{self.index_name}/_doc/{youtube_id}" - def build_json(self): + def build_json(self, youtube_meta_overwrite=False, media_path=False): """build json dict of video""" self.get_from_youtube() - if not self.youtube_meta: + if not self.youtube_meta and not youtube_meta_overwrite: return + if not self.youtube_meta: + self.youtube_meta = youtube_meta_overwrite + self._process_youtube_meta() self._add_channel() self._add_stats() self.add_file_path() - self.add_player() + self.add_player(media_path) if self.config["downloads"]["integrate_ryd"]: self._get_ryd_stats() @@ -518,8 +521,28 @@ class YoutubeVideo(YouTubeItem, YoutubeSubtitle): raise FileNotFoundError - def add_player(self): + def add_player(self, media_path=False): """add player information for new videos""" + vid_path = self._get_vid_path(media_path) + + duration_handler = DurationConverter() + duration = duration_handler.get_sec(vid_path) + duration_str = duration_handler.get_str(duration) + self.json_data.update( + { + "player": { + "watched": False, + "duration": duration, + "duration_str": duration_str, + } + } + ) + + def _get_vid_path(self, media_path=False): + """get path of media file""" + if media_path: + return media_path + try: # when indexing from download task vid_path = self.build_dl_cache_path() @@ -535,18 +558,7 @@ class YoutubeVideo(YouTubeItem, YoutubeSubtitle): else: raise FileNotFoundError("could not find video file") from err - duration_handler = DurationConverter() - duration = duration_handler.get_sec(vid_path) - duration_str = duration_handler.get_str(duration) - self.json_data.update( - { - "player": { - "watched": False, - "duration": duration, - "duration_str": duration_str, - } - } - ) + return vid_path def add_file_path(self): """build media_url for where file will be located"""