From 541a8d725d08237ddae7a230803c8a834c7bb593 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Fri, 4 Aug 2023 16:14:52 +0800 Subject: [PATCH] fix --- app/chain/__init__.py | 5 +++++ app/chain/message.py | 5 ----- app/chain/subscribe.py | 6 ++---- app/modules/themoviedb/__init__.py | 2 +- app/modules/themoviedb/scraper.py | 12 +----------- app/modules/themoviedb/tmdbv3api/objs/movie.py | 3 --- app/modules/themoviedb/tmdbv3api/objs/person.py | 2 -- 7 files changed, 9 insertions(+), 26 deletions(-) diff --git a/app/chain/__init__.py b/app/chain/__init__.py index 75bdb3a8..efcb308a 100644 --- a/app/chain/__init__.py +++ b/app/chain/__init__.py @@ -1,3 +1,4 @@ +import gc import pickle import traceback from abc import ABCMeta @@ -55,6 +56,10 @@ class ChainBase(metaclass=ABCMeta): pickle.dump(cache, f) except Exception as err: logger.error(f"保存缓存 {filename} 出错:{err}") + finally: + # 主动资源回收 + del cache + gc.collect() def run_module(self, method: str, *args, **kwargs) -> Any: """ diff --git a/app/chain/message.py b/app/chain/message.py index 553a851b..ab08f9d9 100644 --- a/app/chain/message.py +++ b/app/chain/message.py @@ -1,4 +1,3 @@ -import gc from typing import Any from app.chain.download import * @@ -316,9 +315,6 @@ class MessageChain(ChainBase): userid=userid, total=len(medias)) # 保存缓存 self.save_cache(user_cache, self._cache_file) - # 主动资源回收 - del user_cache - gc.collect() def __post_medias_message(self, channel: MessageChannel, title: str, items: list, userid: str, total: int): @@ -339,6 +335,5 @@ class MessageChain(ChainBase): self.post_torrents_message(Notification( channel=channel, title=f"【{title}】共找到{total}条相关资源,请回复对应数字下载(0: 自动选择 p: 上一页 n: 下一页)", - items=items, userid=userid ), torrents=items) diff --git a/app/chain/subscribe.py b/app/chain/subscribe.py index d30b7784..1d6061f9 100644 --- a/app/chain/subscribe.py +++ b/app/chain/subscribe.py @@ -1,6 +1,5 @@ import json import re -import gc from datetime import datetime from typing import Dict, List, Optional, Union, Tuple @@ -399,15 +398,14 @@ class SubscribeChain(ChainBase): # 如果超过了200条则移除最早的一条 if len(torrents_cache[domain]) > settings.CACHE_CONF.get('torrents'): torrents_cache[domain].pop(0) + # 回收资源 + del torrents else: logger.info(f'{indexer.get("name")} 获取到种子') # 从缓存中匹配订阅 self.__match(torrents_cache) # 保存缓存到本地 self.save_cache(torrents_cache, self._cache_file) - # 主动资源回收 - del torrents_cache - gc.collect() def __match(self, torrents_cache: Dict[str, List[Context]]): """ diff --git a/app/modules/themoviedb/__init__.py b/app/modules/themoviedb/__init__.py index 52e6ac96..46584e22 100644 --- a/app/modules/themoviedb/__init__.py +++ b/app/modules/themoviedb/__init__.py @@ -9,8 +9,8 @@ from app.log import logger from app.modules import _ModuleBase from app.modules.themoviedb.category import CategoryHelper from app.modules.themoviedb.scraper import TmdbScraper -from app.modules.themoviedb.tmdbapi import TmdbHelper from app.modules.themoviedb.tmdb_cache import TmdbCache +from app.modules.themoviedb.tmdbapi import TmdbHelper from app.schemas.types import MediaType, MediaImageType from app.utils.system import SystemUtils diff --git a/app/modules/themoviedb/scraper.py b/app/modules/themoviedb/scraper.py index 1afc2b02..41eff6f3 100644 --- a/app/modules/themoviedb/scraper.py +++ b/app/modules/themoviedb/scraper.py @@ -116,8 +116,6 @@ class TmdbScraper: """ 生成公共NFO """ - # TMDBINFO - tmdbinfo = mediainfo.tmdb_info # 添加时间 DomUtils.add_node(doc, root, "dateadded", time.strftime('%Y-%m-%d %H:%M:%S', @@ -160,19 +158,11 @@ class TmdbScraper: DomUtils.add_node(doc, xactor, "thumb", actor.get('image')) DomUtils.add_node(doc, xactor, "profile", actor.get('profile')) # 风格 - genres = tmdbinfo.get("genres") or [] + genres = mediainfo.genres or [] for genre in genres: DomUtils.add_node(doc, root, "genre", genre.get("name") or "") # 评分 DomUtils.add_node(doc, root, "rating", mediainfo.vote_average or "0") - # 评级 - if tmdbinfo.get("releases") and tmdbinfo.get("releases").get("countries"): - releases = [i for i in tmdbinfo.get("releases").get("countries") if - i.get("certification") and i.get("certification").strip()] - # 国内没有分级,所以沿用美国的分级 - us_release = next((c for c in releases if c.get("iso_3166_1") == "US"), None) - if us_release: - DomUtils.add_node(doc, root, "mpaa", us_release.get("certification") or "") return doc diff --git a/app/modules/themoviedb/tmdbv3api/objs/movie.py b/app/modules/themoviedb/tmdbv3api/objs/movie.py index e4571884..9e01e57c 100644 --- a/app/modules/themoviedb/tmdbv3api/objs/movie.py +++ b/app/modules/themoviedb/tmdbv3api/objs/movie.py @@ -1,7 +1,4 @@ -import warnings from ..tmdb import TMDb -from .find import Find -from .search import Search class Movie(TMDb): diff --git a/app/modules/themoviedb/tmdbv3api/objs/person.py b/app/modules/themoviedb/tmdbv3api/objs/person.py index 3e27b82b..a976bfe6 100644 --- a/app/modules/themoviedb/tmdbv3api/objs/person.py +++ b/app/modules/themoviedb/tmdbv3api/objs/person.py @@ -1,6 +1,4 @@ -import warnings from ..tmdb import TMDb -from .search import Search class Person(TMDb):