diff --git a/package.v2.json b/package.v2.json index 35df35b..a7a3a89 100644 --- a/package.v2.json +++ b/package.v2.json @@ -3,11 +3,12 @@ "name": "首播试看", "description": "定时抓取RSS,只下载电视剧前N集,自动跳过合集和过大文件。", "labels": "订阅,RSS", - "version": "1.5.1", + "version": "1.5.2", "icon": "rss.png", "author": "Raymond38324", "level": 2, "history": { + "v1.5.2": "去除是否发送通知的配置", "v1.5.1": "修复NoneType错误,增强空值处理", "v1.5": "详情页新增清空历史按钮", "v1.4": "新增Complete/合集检测,新增单集大小上限过滤", diff --git a/plugins.v2/tvfirstwatch/__init__.py b/plugins.v2/tvfirstwatch/__init__.py index aa5489d..2a74dbb 100644 --- a/plugins.v2/tvfirstwatch/__init__.py +++ b/plugins.v2/tvfirstwatch/__init__.py @@ -60,7 +60,6 @@ class TvFirstWatch(_PluginBase): _enabled: bool = False _onlyonce: bool = False - _notify: bool = False _cron: str = "*/30 * * * *" _rss_urls: str = "" _max_episode: int = 2 @@ -76,18 +75,19 @@ class TvFirstWatch(_PluginBase): self.stop_service() if config: - self._enabled = config.get("enabled", False) - self._onlyonce = config.get("onlyonce", False) - self._notify = config.get("notify", False) + self._enabled = _to_bool(config.get("enabled", False), False) + self._onlyonce = _to_bool(config.get("onlyonce", False), False) self._cron = config.get("cron", "*/30 * * * *") or "*/30 * * * *" self._rss_urls = config.get("rss_urls", "") - self._max_episode = int(config.get("max_episode", 2)) + self._max_episode = _to_int(config.get("max_episode", 2), 2) self._whitelist = config.get("whitelist", "") self._blacklist = config.get("blacklist", "") self._save_path = config.get("save_path", "") - self._max_storage_gb = int(config.get("max_storage_gb", 0)) - self._default_size_gb = float(config.get("default_size_gb", 2.0)) - self._max_single_size_gb = float(config.get("max_single_size_gb", 10.0)) + self._max_storage_gb = _to_int(config.get("max_storage_gb", 0), 0) + self._default_size_gb = _to_float(config.get("default_size_gb", 2.0), 2.0) + self._max_single_size_gb = _to_float( + config.get("max_single_size_gb", 10.0), 10.0 + ) self._history_path = self.get_data_path() / "history.json" @@ -175,7 +175,6 @@ class TvFirstWatch(_PluginBase): "component": "VRow", "content": [ _col(4, _switch("enabled", "启用插件")), - _col(4, _switch("notify", "下载时通知")), _col(4, _switch("onlyonce", "立即运行一次")), ], }, @@ -303,7 +302,6 @@ class TvFirstWatch(_PluginBase): } ], { "enabled": False, - "notify": False, "onlyonce": False, "cron": "*/30 * * * *", "rss_urls": "", @@ -584,15 +582,6 @@ class TvFirstWatch(_PluginBase): } self._save_history(history) - if self._notify: - self.systemmessage.put( - f"📺 首播试看已推送下载\n" - f"剧名:{series_name}\n" - f"集号:{new_eps}\n" - f"大小:{size_str}\n" - f"标题:{title}" - ) - def _get_torrent_size(self, entry) -> Tuple[int, bool]: """ 获取种子大小。 @@ -760,7 +749,6 @@ class TvFirstWatch(_PluginBase): { "enabled": self._enabled, "onlyonce": self._onlyonce, - "notify": self._notify, "cron": self._cron, "rss_urls": self._rss_urls, "max_episode": self._max_episode, @@ -804,6 +792,36 @@ def _make_key(series_name: str, episode: int) -> str: return f"{norm}__ep{episode:03d}" +def _to_bool(value: Any, default: bool = False) -> bool: + if isinstance(value, bool): + return value + if value is None: + return default + if isinstance(value, (int, float)): + return value != 0 + if isinstance(value, str): + v = value.strip().lower() + if v in ("1", "true", "yes", "y", "on"): + return True + if v in ("0", "false", "no", "n", "off", ""): + return False + return default + + +def _to_int(value: Any, default: int) -> int: + try: + return int(value) + except (TypeError, ValueError): + return default + + +def _to_float(value: Any, default: float) -> float: + try: + return float(value) + except (TypeError, ValueError): + return default + + def _col(md: int, *children) -> dict: return { "component": "VCol",