From 23650657cd615e0958dd72ba23ca88118c9e7152 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Tue, 7 Jan 2025 14:20:31 +0800 Subject: [PATCH] add noqa fix #3670 --- app/api/servcookie.py | 2 +- app/chain/__init__.py | 2 +- app/chain/site.py | 4 ++-- app/chain/subscribe.py | 13 ++++++++----- app/core/event.py | 2 +- app/db/__init__.py | 2 +- app/db/init.py | 2 +- app/db/message_oper.py | 2 +- app/log.py | 2 +- app/modules/douban/douban_cache.py | 2 +- app/modules/douban/scraper.py | 2 +- app/modules/emby/emby.py | 2 +- app/modules/filemanager/storages/alipan.py | 4 ++-- app/modules/themoviedb/scraper.py | 2 +- app/schemas/file.py | 2 +- app/schemas/transfer.py | 1 - app/utils/string.py | 2 +- 17 files changed, 25 insertions(+), 23 deletions(-) diff --git a/app/api/servcookie.py b/app/api/servcookie.py index 30242b12..4361db33 100644 --- a/app/api/servcookie.py +++ b/app/api/servcookie.py @@ -19,7 +19,7 @@ class GzipRequest(Request): body = await super().body() if "gzip" in self.headers.getlist("Content-Encoding"): body = gzip.decompress(body) - self._body = body + self._body = body # noqa return self._body diff --git a/app/chain/__init__.py b/app/chain/__init__.py index aad8af6e..c63979cc 100644 --- a/app/chain/__init__.py +++ b/app/chain/__init__.py @@ -62,7 +62,7 @@ class ChainBase(metaclass=ABCMeta): """ try: with open(settings.TEMP_PATH / filename, 'wb') as f: - pickle.dump(cache, f) + pickle.dump(cache, f) # noqa except Exception as err: logger.error(f"保存缓存 {filename} 出错:{str(err)}") finally: diff --git a/app/chain/site.py b/app/chain/site.py index bde4d776..6047fd84 100644 --- a/app/chain/site.py +++ b/app/chain/site.py @@ -96,7 +96,7 @@ class SiteChain(ChainBase): )) return userdata - def refresh_userdatas(self) -> Dict[str, SiteUserData]: + def refresh_userdatas(self) -> Optional[Dict[str, SiteUserData]]: """ 刷新所有站点的用户数据 """ @@ -105,7 +105,7 @@ class SiteChain(ChainBase): result = {} for site in sites: if global_vars.is_system_stopped: - return + return None if site.get("is_active"): userdata = self.refresh_userdata(site) if userdata: diff --git a/app/chain/subscribe.py b/app/chain/subscribe.py index e2da7762..9cf51a65 100644 --- a/app/chain/subscribe.py +++ b/app/chain/subscribe.py @@ -6,6 +6,8 @@ import time from datetime import datetime from typing import Dict, List, Optional, Union, Tuple +from cachetools import TTLCache + from app.chain import ChainBase from app.chain.download import DownloadChain from app.chain.media import MediaChain @@ -508,7 +510,7 @@ class SubscribeChain(ChainBase, metaclass=Singleton): return # 记录重新识别过的种子 - _recognize_cached = [] + _recognize_cached = TTLCache(maxsize=1024, ttl=6 * 3600) with self._rlock: logger.debug(f"match lock acquired at {datetime.now()}") @@ -572,14 +574,15 @@ class SubscribeChain(ChainBase, metaclass=Singleton): # 有自定义识别词时,需要判断是否需要重新识别 if subscribe.custom_words: + custom_words_list = subscribe.custom_words.split("\n") _, apply_words = WordsMatcher().prepare(torrent_info.title, - custom_words=subscribe.custom_words.split("\n")) + custom_words=custom_words_list) if apply_words: logger.info( f'{torrent_info.site_name} - {torrent_info.title} 因订阅存在自定义识别词,重新识别元数据...') # 重新识别元数据 torrent_meta = MetaInfo(title=torrent_info.title, subtitle=torrent_info.description, - custom_words=subscribe.custom_words) + custom_words=custom_words_list) # 媒体信息需要重新识别 torrent_mediainfo = None @@ -588,8 +591,8 @@ class SubscribeChain(ChainBase, metaclass=Singleton): or (not torrent_mediainfo.tmdb_id and not torrent_mediainfo.douban_id): # 避免重复处理 _cache_key = f"{torrent_meta.org_string}_{torrent_info.description}" - if _cache_key not in _recognize_cached: - _recognize_cached.append(_cache_key) + if not _recognize_cached.get(_cache_key): + _recognize_cached[_cache_key] = True # 重新识别媒体信息 torrent_mediainfo = self.recognize_media(meta=torrent_meta) if torrent_mediainfo: diff --git a/app/core/event.py b/app/core/event.py index 666224d0..b29c1bad 100644 --- a/app/core/event.py +++ b/app/core/event.py @@ -293,7 +293,7 @@ class EventManager(metaclass=Singleton): # 对于类实例(实现了 __call__ 方法) if not inspect.isfunction(handler) and hasattr(handler, "__call__"): - handler_cls = handler.__class__ + handler_cls = handler.__class__ # noqa return cls.__get_handler_identifier(handler_cls) # 对于未绑定方法、静态方法、类方法,使用 __qualname__ 提取类信息 diff --git a/app/db/__init__.py b/app/db/__init__.py index 5812066c..e9807d33 100644 --- a/app/db/__init__.py +++ b/app/db/__init__.py @@ -225,7 +225,7 @@ class Base: return list(result) def to_dict(self): - return {c.name: getattr(self, c.name, None) for c in self.__table__.columns} + return {c.name: getattr(self, c.name, None) for c in self.__table__.columns} # noqa @declared_attr def __tablename__(self) -> str: diff --git a/app/db/init.py b/app/db/init.py index abc595e7..d4f838a6 100644 --- a/app/db/init.py +++ b/app/db/init.py @@ -11,7 +11,7 @@ def init_db(): 初始化数据库 """ # 全量建表 - Base.metadata.create_all(bind=Engine) + Base.metadata.create_all(bind=Engine) # noqa def update_db(): diff --git a/app/db/message_oper.py b/app/db/message_oper.py index a328654a..12dbe095 100644 --- a/app/db/message_oper.py +++ b/app/db/message_oper.py @@ -57,7 +57,7 @@ class MessageOper(DbOper): # 从kwargs中去掉Message中没有的字段 for k in list(kwargs.keys()): - if k not in Message.__table__.columns.keys(): + if k not in Message.__table__.columns.keys(): # noqa kwargs.pop(k) Message(**kwargs).create(self._db) diff --git a/app/log.py b/app/log.py index 3cf3b9fc..47cb88da 100644 --- a/app/log.py +++ b/app/log.py @@ -111,7 +111,7 @@ class LoggerManager: plugin_name = None try: - frame = sys._getframe(3) + frame = sys._getframe(3) # noqa except (AttributeError, ValueError): # 如果无法获取帧,返回默认值 return "log.py", None diff --git a/app/modules/douban/douban_cache.py b/app/modules/douban/douban_cache.py index 8d3efa9b..fd4c6add 100644 --- a/app/modules/douban/douban_cache.py +++ b/app/modules/douban/douban_cache.py @@ -179,7 +179,7 @@ class DoubanCache(metaclass=Singleton): return with open(self._meta_path, 'wb') as f: - pickle.dump(new_meta_data, f, pickle.HIGHEST_PROTOCOL) + pickle.dump(new_meta_data, f, pickle.HIGHEST_PROTOCOL) # noqa def _random_sample(self, new_meta_data: dict) -> bool: """ diff --git a/app/modules/douban/scraper.py b/app/modules/douban/scraper.py index b1b628c1..476f6af1 100644 --- a/app/modules/douban/scraper.py +++ b/app/modules/douban/scraper.py @@ -28,7 +28,7 @@ class DoubanScraper: # 电视剧元数据文件 doc = self.__gen_tv_nfo_file(mediainfo=mediainfo) if doc: - return doc.toprettyxml(indent=" ", encoding="utf-8") + return doc.toprettyxml(indent=" ", encoding="utf-8") # noqa return None diff --git a/app/modules/emby/emby.py b/app/modules/emby/emby.py index 7662be57..e963c1e9 100644 --- a/app/modules/emby/emby.py +++ b/app/modules/emby/emby.py @@ -391,7 +391,7 @@ class Emby: year: str = None, tmdb_id: int = None, season: int = None - ) -> Tuple[Optional[str], Optional[Dict[int, List[Dict[int, list]]]]]: + ) -> Tuple[Optional[str], Optional[Dict[int, List[int]]]]: """ 根据标题和年份和季,返回Emby中的剧集列表 :param item_id: Emby中的ID diff --git a/app/modules/filemanager/storages/alipan.py b/app/modules/filemanager/storages/alipan.py index c85168aa..cbe82bb4 100644 --- a/app/modules/filemanager/storages/alipan.py +++ b/app/modules/filemanager/storages/alipan.py @@ -71,7 +71,7 @@ class AliPan(StorageBase, metaclass=Singleton): refresh_token = self.__auth_params.get("refreshToken") if refresh_token: try: - self.aligo = Aligo(refresh_token=refresh_token, show=show_qrcode, use_aria2=self._has_aria2c, + self.aligo = Aligo(refresh_token=refresh_token, show=show_qrcode, use_aria2=self._has_aria2c, # noqa name="MoviePilot V2", level=logging.ERROR, re_login=False) except Exception as err: logger.error(f"初始化阿里云盘失败:{str(err)}") @@ -327,7 +327,7 @@ class AliPan(StorageBase, metaclass=Singleton): return None item = self.aligo.get_file_by_path(path=str(path)) if item: - return self.__get_fileitem(item, parent=path.parent) + return self.__get_fileitem(item, parent=str(path.parent)) return None def delete(self, fileitem: schemas.FileItem) -> bool: diff --git a/app/modules/themoviedb/scraper.py b/app/modules/themoviedb/scraper.py index 2590d4ac..bb79f80b 100644 --- a/app/modules/themoviedb/scraper.py +++ b/app/modules/themoviedb/scraper.py @@ -45,7 +45,7 @@ class TmdbScraper: # 电视剧元数据文件 doc = self.__gen_tv_nfo_file(mediainfo=mediainfo) if doc: - return doc.toprettyxml(indent=" ", encoding="utf-8") + return doc.toprettyxml(indent=" ", encoding="utf-8") # noqa return None diff --git a/app/schemas/file.py b/app/schemas/file.py index 4e941e3d..2fb7bb27 100644 --- a/app/schemas/file.py +++ b/app/schemas/file.py @@ -45,4 +45,4 @@ class StorageUsage(BaseModel): class StorageTransType(BaseModel): # 传输类型 - transtype: Optional[dict] = Field(default_factory=dict) + transtype: Optional[str] = None diff --git a/app/schemas/transfer.py b/app/schemas/transfer.py index be08a046..ea195529 100644 --- a/app/schemas/transfer.py +++ b/app/schemas/transfer.py @@ -6,7 +6,6 @@ from pydantic import BaseModel, Field from app.schemas import TmdbEpisode, DownloadHistory from app.schemas.file import FileItem from app.schemas.system import TransferDirectoryConf -from schemas import MediaInfo, MetaInfo class TransferTorrent(BaseModel): diff --git a/app/utils/string.py b/app/utils/string.py index f2b1e77e..be003532 100644 --- a/app/utils/string.py +++ b/app/utils/string.py @@ -227,7 +227,7 @@ class StringUtils: size = float(size) d = [(1024 - 1, 'K'), (1024 ** 2 - 1, 'M'), (1024 ** 3 - 1, 'G'), (1024 ** 4 - 1, 'T')] s = [x[0] for x in d] - index = bisect.bisect_left(s, size) - 1 + index = bisect.bisect_left(s, size) - 1 # noqa if index == -1: return str(size) + "B" else: