From 14dcb73d06b33d90b163eefba9a72adc0dbb0411 Mon Sep 17 00:00:00 2001 From: zhuweitung Date: Mon, 12 May 2025 10:09:36 +0800 Subject: [PATCH] =?UTF-8?q?fix(scrap):=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=95=B4=E7=90=86=E7=94=B5=E5=BD=B1=E3=80=81=E7=94=B5=E8=A7=86?= =?UTF-8?q?=E5=89=A7=E4=B8=BB=E6=B5=B7=E6=8A=A5=E4=B8=8D=E4=B8=BA=E5=8E=9F?= =?UTF-8?q?=E5=A7=8B=E8=AF=AD=E7=A7=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chain/media.py | 18 +++++++----------- app/modules/themoviedb/scraper.py | 27 ++++++++++++++++++--------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/app/chain/media.py b/app/chain/media.py index 1fcc0e84..b4a3ef7a 100644 --- a/app/chain/media.py +++ b/app/chain/media.py @@ -449,23 +449,19 @@ class MediaChain(ChainBase, metaclass=Singleton): # 生成目录内图片文件 if init_folder: # 图片 - for attr_name, attr_value in vars(mediainfo).items(): - if attr_value \ - and attr_name.endswith("_path") \ - and attr_value \ - and isinstance(attr_value, str) \ - and attr_value.startswith("http"): - image_name = attr_name.replace("_path", "") + Path(attr_value).suffix - image_path = filepath / image_name + image_dict = self.metadata_img(mediainfo=mediainfo) + if image_dict: + for image_name, image_url in image_dict.items(): + image_path = filepath.with_name(image_name) if overwrite or not self.storagechain.get_file_item(storage=fileitem.storage, path=image_path): # 下载图片 - content = __download_image(_url=attr_value) + content = __download_image(image_url) # 写入图片到当前目录 if content: __save_file(_fileitem=fileitem, _path=image_path, _content=content) - else: - logger.info(f"已存在图片文件:{image_path}") + else: + logger.info(f"已存在图片文件:{image_path}") else: # 电视剧 if fileitem.type == "file": diff --git a/app/modules/themoviedb/scraper.py b/app/modules/themoviedb/scraper.py index 64684978..c89fecaa 100644 --- a/app/modules/themoviedb/scraper.py +++ b/app/modules/themoviedb/scraper.py @@ -101,15 +101,24 @@ class TmdbScraper: return images else: # 主媒体图片 - for attr_name, attr_value in vars(mediainfo).items(): - if attr_value \ - and attr_name.endswith("_path") \ - and attr_value \ - and isinstance(attr_value, str) \ - and attr_value.startswith("http"): - image_name = attr_name.replace("_path", "") + Path(attr_value).suffix - images[image_name] = attr_value - return images + _mediainfo = self.original_tmdb(mediainfo).get_info(mediainfo.type, mediainfo.tmdb_id) + if _mediainfo: + for attr_name, attr_value in _mediainfo.items(): + if attr_name.endswith("_path") and attr_value is not None: + image_url = f"https://{settings.TMDB_IMAGE_DOMAIN}/t/p/original{attr_value}" + image_name = attr_name.replace("_path", "") + Path(image_url).suffix + images[image_name] = image_url + return images + else: + for attr_name, attr_value in vars(mediainfo).items(): + if attr_value \ + and attr_name.endswith("_path") \ + and attr_value \ + and isinstance(attr_value, str) \ + and attr_value.startswith("http"): + image_name = attr_name.replace("_path", "") + Path(attr_value).suffix + images[image_name] = attr_value + return images @staticmethod def get_season_poster(seasoninfo: dict, season: int) -> Tuple[str, str]: