fix ide warnings

This commit is contained in:
jxxghp
2025-03-09 18:35:52 +08:00
parent 87ce266b14
commit 71c29ea5e7
15 changed files with 70 additions and 66 deletions

View File

@@ -3,7 +3,7 @@ import re
import traceback
from datetime import datetime
from pathlib import Path
from typing import List, Optional, Union, Dict, Generator, Tuple
from typing import List, Optional, Union, Dict, Generator, Tuple, Any
from requests import Response
@@ -13,6 +13,7 @@ from app.log import logger
from app.schemas.types import MediaType
from app.utils.http import RequestUtils
from app.utils.url import UrlUtils
from schemas import MediaServerItem
class Emby:
@@ -545,7 +546,7 @@ class Emby:
return False
return False
def refresh_library_by_items(self, items: List[schemas.RefreshMediaItem]) -> bool:
def refresh_library_by_items(self, items: List[schemas.RefreshMediaItem]) -> Optional[bool]:
"""
按类型、名称、年份来刷新媒体库
:param items: 已识别的需要刷新媒体库的媒体信息列表
@@ -668,8 +669,8 @@ class Emby:
logger.error(f"连接/Users/{self.user}/Items/{itemid}出错:" + str(e))
return None
def get_items(self, parent: Union[str, int], start_index: int = 0, limit: Optional[int] = -1) \
-> Optional[Generator]:
def get_items(self, parent: Union[str, int], start_index: int = 0,
limit: Optional[int] = -1) -> Generator[MediaServerItem | None | Any, Any, None]:
"""
获取媒体服务器项目列表,支持分页和不分页逻辑,默认不分页获取所有数据

View File

@@ -201,12 +201,12 @@ class Alist(StorageBase, metaclass=Singleton):
if resp is None:
logging.warning(f"请求获取目录 {fileitem.path} 的文件列表失败无法连接alist服务")
return
return None
if resp.status_code != 200:
logging.warning(
f"请求获取目录 {fileitem.path} 的文件列表失败,状态码:{resp.status_code}"
)
return
return None
result = resp.json()
@@ -214,7 +214,7 @@ class Alist(StorageBase, metaclass=Singleton):
logging.warning(
f'获取目录 {fileitem.path} 的文件列表失败,错误信息:{result["message"]}'
)
return
return None
return [
schemas.FileItem(
@@ -259,15 +259,15 @@ class Alist(StorageBase, metaclass=Singleton):
"""
if resp is None:
logging.warning(f"请求创建目录 {path} 失败无法连接alist服务")
return
return None
if resp.status_code != 200:
logging.warning(f"请求创建目录 {path} 失败,状态码:{resp.status_code}")
return
return None
result = resp.json()
if result["code"] != 200:
logging.warning(f'创建目录 {path} 失败,错误信息:{result["message"]}')
return
return None
return self.get_item(path)
@@ -349,15 +349,15 @@ class Alist(StorageBase, metaclass=Singleton):
"""
if resp is None:
logging.warning(f"请求获取文件 {path} 失败无法连接alist服务")
return
return None
if resp.status_code != 200:
logging.warning(f"请求获取文件 {path} 失败,状态码:{resp.status_code}")
return
return None
result = resp.json()
if result["code"] != 200:
logging.debug(f'获取文件 {path} 失败,错误信息:{result["message"]}')
return
return None
return schemas.FileItem(
storage=self.schema.value,
@@ -513,15 +513,15 @@ class Alist(StorageBase, metaclass=Singleton):
"""
if not resp:
logging.warning(f"请求获取文件 {path} 失败无法连接alist服务")
return
return None
if resp.status_code != 200:
logging.warning(f"请求获取文件 {path} 失败,状态码:{resp.status_code}")
return
return None
result = resp.json()
if result["code"] != 200:
logging.warning(f'获取文件 {path} 失败,错误信息:{result["message"]}')
return
return None
if result["data"]["raw_url"]:
download_url = result["data"]["raw_url"]
@@ -569,7 +569,7 @@ class Alist(StorageBase, metaclass=Singleton):
if resp.status_code != 200:
logging.warning(f"请求上传文件 {path} 失败,状态码:{resp.status_code}")
return
return None
new_item = self.get_item(Path(fileitem.path) / path.name)
if new_item and new_name and new_name != path.name:

View File

@@ -259,7 +259,7 @@ class FilterModule(_ModuleBase):
return None if not matched else torrent
def __match_group(self, torrent: TorrentInfo, rule_group: Union[list, str]) -> bool:
def __match_group(self, torrent: TorrentInfo, rule_group: Union[list, str]) -> Optional[bool]:
"""
判断种子是否匹配规则组
"""

View File

@@ -54,7 +54,7 @@ class IptSiteUserInfo(SiteParserBase):
def _parse_user_torrent_seeding_info(self, html_text: str, multi_page: bool = False) -> Optional[str]:
html = etree.HTML(html_text)
if not StringUtils.is_valid_html_element(html):
return
return None
# seeding start
seeding_end_pos = 3
if html.xpath('//tr/td[text() = "Leechers"]'):

View File

@@ -65,7 +65,7 @@ class TNodeSiteUserInfo(SiteParserBase):
"""
seeding_info = json.loads(html_text)
if seeding_info.get("status") != 200:
return
return None
torrents = seeding_info.get("data", {}).get("torrents", [])

View File

@@ -1,6 +1,6 @@
import json
from datetime import datetime
from typing import List, Union, Optional, Dict, Generator, Tuple
from typing import List, Union, Optional, Dict, Generator, Tuple, Any
from requests import Response
@@ -10,6 +10,7 @@ from app.log import logger
from app.schemas import MediaType
from app.utils.http import RequestUtils
from app.utils.url import UrlUtils
from schemas import MediaServerItem
class Jellyfin:
@@ -548,7 +549,7 @@ class Jellyfin:
logger.error(f"连接Items/Id/Ancestors出错" + str(e))
return None
def refresh_root_library(self) -> bool:
def refresh_root_library(self) -> Optional[bool]:
"""
通知Jellyfin刷新整个媒体库
"""
@@ -762,7 +763,7 @@ class Jellyfin:
return None
def get_items(self, parent: Union[str, int], start_index: int = 0, limit: Optional[int] = -1) \
-> Optional[Generator]:
-> Generator[MediaServerItem | None | Any, Any, None]:
"""
获取媒体服务器项目列表,支持分页和不分页逻辑,默认不分页获取所有数据

View File

@@ -14,6 +14,7 @@ from app.log import logger
from app.schemas import MediaType
from app.utils.http import RequestUtils
from app.utils.url import UrlUtils
from schemas import MediaServerItem
class Plex:
@@ -367,7 +368,7 @@ class Plex:
return False
return self._plex.library.update()
def refresh_library_by_items(self, items: List[schemas.RefreshMediaItem]) -> bool:
def refresh_library_by_items(self, items: List[schemas.RefreshMediaItem]) -> Optional[bool]:
"""
按路径刷新媒体库 item: target_path
"""
@@ -512,7 +513,7 @@ class Plex:
)
def get_items(self, parent: Union[str, int], start_index: int = 0, limit: Optional[int] = -1) \
-> Optional[Generator]:
-> Generator[MediaServerItem | None, Any, None]:
"""
获取媒体服务器项目列表,支持分页和不分页逻辑,默认不分页获取所有数据
@@ -855,7 +856,7 @@ class Plex:
:param kwargs: 其他请求参数如headers, cookies, proxies等
"""
if not self._session:
return
return None
try:
url = UrlUtils.adapt_request_url(host=self._host, endpoint=endpoint)
kwargs.setdefault("headers", self.__get_request_headers())