From b52aa4daba9ac8b86403b14b90414f8d0cbc3cf6 Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 1 Mar 2023 13:45:01 +0700 Subject: [PATCH] fix media_url change in reindex, #424 --- tubearchivist/home/src/index/reindex.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tubearchivist/home/src/index/reindex.py b/tubearchivist/home/src/index/reindex.py index 6371d27a..54205c48 100644 --- a/tubearchivist/home/src/index/reindex.py +++ b/tubearchivist/home/src/index/reindex.py @@ -259,6 +259,7 @@ class Reindex(ReindexBase): video.get_from_es() player = video.json_data["player"] date_downloaded = video.json_data["date_downloaded"] + media_url = video.json_data["media_url"] channel_dict = video.json_data["channel"] playlist = video.json_data.get("playlist") subtitles = video.json_data.get("subtitles") @@ -280,6 +281,8 @@ class Reindex(ReindexBase): video.json_data["playlist"] = playlist video.upload_to_es() + if media_url != video.json_data["media_url"]: + self._rename_media_file(media_url, video.json_data["media_url"]) thumb_handler = ThumbManager(youtube_id) thumb_handler.delete_video_thumb() @@ -289,6 +292,14 @@ class Reindex(ReindexBase): return + def _rename_media_file(self, media_url_is, media_url_should): + """handle title change""" + print(f"[reindex] fix media_url {media_url_is} to {media_url_should}") + videos = self.config["application"]["videos"] + old_path = os.path.join(videos, media_url_is) + new_path = os.path.join(videos, media_url_should) + os.rename(old_path, new_path) + @staticmethod def _reindex_single_channel(channel_id): """refresh channel data and sync to videos"""