From b70cbfa0a87a521df4a1eb370f0e82b016a0166b Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 8 Aug 2022 14:52:33 +0700 Subject: [PATCH] convert thumbnail to jpg for manual import --- tubearchivist/home/src/index/filesystem.py | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tubearchivist/home/src/index/filesystem.py b/tubearchivist/home/src/index/filesystem.py index f961d48b..4d79e88b 100644 --- a/tubearchivist/home/src/index/filesystem.py +++ b/tubearchivist/home/src/index/filesystem.py @@ -19,6 +19,9 @@ from home.src.index.video import index_new_video from home.src.ta.config import AppConfig from home.src.ta.helper import clean_string, ignore_filelist from home.src.ta.ta_redis import RedisArchivist +from PIL import Image, ImageFile + +ImageFile.LOAD_TRUNCATED_IMAGES = True class FilesystemScanner: @@ -248,6 +251,7 @@ class ImportFolderScanner: for current_video in self.to_import: self._detect_youtube_id(current_video) self._dump_thumb(current_video) + self._convert_thumb(current_video) self._convert_video(current_video) def _detect_youtube_id(self, current_video): @@ -360,6 +364,25 @@ class ImportFolderScanner: return False + def _convert_thumb(self, current_video): + """convert all thumbnails to jpg""" + if not current_video["thumb"]: + return + + thumb_file = current_video["thumb"] + thumb_path = os.path.join(self.CACHE_DIR, "import", thumb_file) + + base_path, ext = os.path.splitext(thumb_path) + if ext == ".jpg": + return + + new_path = f"{base_path}.jpg" + img_raw = Image.open(thumb_path) + img_raw.convert("RGB").save(new_path) + + os.remove(thumb_path) + current_video["thumb"] = new_path + @staticmethod def _get_streams(media_path): """return all streams from media_path"""