nonebot-plugin-bittorrents 1.1.0__tar.gz → 1.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nonebot-plugin-bittorrents
3
- Version: 1.1.0
3
+ Version: 1.1.2
4
4
  Summary: 适配NoneBot的磁力搜索插件,通过机器人帮你寻找电影、软件或者学习资料
5
5
  Author: NightDust981989
6
6
  License-Expression: MIT
@@ -8,13 +8,10 @@ Project-URL: homepage, https://github.com/NightDust981989/nonebot-plugin-BitTorr
8
8
  Project-URL: repository, https://github.com/NightDust981989/nonebot-plugin-BitTorrents
9
9
  Description-Content-Type: text/markdown
10
10
  License-File: LICENSE
11
- Requires-Dist: httpx
12
- Requires-Dist: beautifulsoup4
13
- Requires-Dist: lxml
14
- Requires-Dist: pydantic
15
- Requires-Dist: pydantic-settings
16
- Requires-Dist: nonebot2
17
- Requires-Dist: nonebot-adapter-onebot
11
+ Requires-Dist: httpx>=0.23.0
12
+ Requires-Dist: beautifulsoup4>=4.11.0
13
+ Requires-Dist: lxml>=4.9.0
14
+ Requires-Dist: nonebot2>=2.3.0
18
15
  Dynamic: license-file
19
16
 
20
17
  # NoneBot 磁力搜索插件
@@ -8,6 +8,7 @@ __plugin_meta__ = PluginMetadata(
8
8
  type="application",
9
9
  homepage="https://github.com/NightDust981989/nonebot-plugin-BitTorrents",
10
10
  config=Config,
11
+ supported_adapters=None,
11
12
  )
12
13
 
13
14
  from . import main
@@ -11,9 +11,11 @@ from nonebot.adapters import Message
11
11
  from nonebot.params import CommandArg
12
12
 
13
13
  try:
14
- from pydantic import BaseSettings
14
+ from pydantic import BaseModel
15
+ from nonebot import get_plugin_config
15
16
  except ImportError:
16
- from pydantic_settings import BaseSettings
17
+ from pydantic import BaseSettings as BaseModel
18
+ from nonebot import get_driver
17
19
 
18
20
  # ========== 1. 配置映射类(从配置文件读取参数) ==========
19
21
  @dataclass
@@ -91,26 +93,34 @@ class MagnetSearchService:
91
93
  self.client: httpx.AsyncClient = None
92
94
 
93
95
  async def _init_client(self):
94
- """初始化客户端:使用配置文件的超时时间"""
95
- headers = {
96
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
97
- "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
98
- "Accept-Language": "zh-CN,zh;q=0.9",
99
- "Origin": self.config.base_url,
100
- "Content-Type": "application/x-www-form-urlencoded",
101
- "Referer": self.config.base_url
102
- }
103
-
104
- self.client = httpx.AsyncClient(
105
- headers=headers,
106
- cookies=self.config.captcha_cookies,
107
- timeout=self.config.request_timeout, # 从配置读取超时时间
108
- follow_redirects=False, # 关闭自动重定向
109
- verify=False
110
- )
96
+ """初始化客户端"""
97
+ if self.client is None:
98
+ headers = {
99
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
100
+ "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
101
+ "Accept-Language": "zh-CN,zh;q=0.9",
102
+ "Origin": self.config.base_url,
103
+ "Content-Type": "application/x-www-form-urlencoded",
104
+ "Referer": self.config.base_url
105
+ }
106
+
107
+ self.client = httpx.AsyncClient(
108
+ headers=headers,
109
+ cookies=self.config.captcha_cookies,
110
+ timeout=self.config.request_timeout, # 从配置读取超时时间
111
+ follow_redirects=False, # 关闭自动重定向
112
+ verify=False
113
+ )
114
+
115
+ async def close_client(self):
116
+ """关闭客户端"""
117
+ if self.client:
118
+ await self.client.aclose()
119
+ self.client = None
111
120
 
112
121
  async def search(self, keyword: str, sort_param: str = "") -> List[str]:
113
122
  """搜索逻辑:使用配置文件的站点/接口/结果数"""
123
+ # 确保客户端已初始化
114
124
  await self._init_client()
115
125
  results = []
116
126
 
@@ -215,28 +225,24 @@ class MagnetSearchService:
215
225
  except Exception as e:
216
226
  print(f"搜索异常:{str(e)}")
217
227
  results = [f"搜索失败:{str(e)[:50]}"]
218
- finally:
219
- if self.client:
220
- await self.client.aclose()
221
228
 
222
229
  return results
223
230
 
224
- # ========== 4. 初始化配置和服务 ==========
225
- # 从 nonebot 配置中获取参数,如果不存在则使用默认值
226
- from nonebot import get_driver
227
-
228
- class Config(BaseSettings):
231
+ # ========== 4. 配置类定义 ==========
232
+ class Config(BaseModel):
229
233
  magnet_base_url: str = "https://clg2.clgapp1.xyz"
230
234
  magnet_search_path: str = "/cllj.php"
231
235
  magnet_max_results: int = 3
232
236
  magnet_request_timeout: int = 15
233
237
 
234
- class Config:
235
- extra = "allow"
236
-
237
- driver = get_driver()
238
- global_config = driver.config
239
- plugin_config = Config(**global_config.dict())
238
+ try:
239
+ plugin_config = get_plugin_config(Config)
240
+ except:
241
+ # 兜底
242
+ from nonebot import get_driver
243
+ driver = get_driver()
244
+ global_config = driver.config
245
+ plugin_config = Config(**global_config.dict())
240
246
 
241
247
  # 初始化配置类
242
248
  magnet_config = MagnetConfig(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nonebot-plugin-bittorrents
3
- Version: 1.1.0
3
+ Version: 1.1.2
4
4
  Summary: 适配NoneBot的磁力搜索插件,通过机器人帮你寻找电影、软件或者学习资料
5
5
  Author: NightDust981989
6
6
  License-Expression: MIT
@@ -8,13 +8,10 @@ Project-URL: homepage, https://github.com/NightDust981989/nonebot-plugin-BitTorr
8
8
  Project-URL: repository, https://github.com/NightDust981989/nonebot-plugin-BitTorrents
9
9
  Description-Content-Type: text/markdown
10
10
  License-File: LICENSE
11
- Requires-Dist: httpx
12
- Requires-Dist: beautifulsoup4
13
- Requires-Dist: lxml
14
- Requires-Dist: pydantic
15
- Requires-Dist: pydantic-settings
16
- Requires-Dist: nonebot2
17
- Requires-Dist: nonebot-adapter-onebot
11
+ Requires-Dist: httpx>=0.23.0
12
+ Requires-Dist: beautifulsoup4>=4.11.0
13
+ Requires-Dist: lxml>=4.9.0
14
+ Requires-Dist: nonebot2>=2.3.0
18
15
  Dynamic: license-file
19
16
 
20
17
  # NoneBot 磁力搜索插件
@@ -0,0 +1,4 @@
1
+ httpx>=0.23.0
2
+ beautifulsoup4>=4.11.0
3
+ lxml>=4.9.0
4
+ nonebot2>=2.3.0
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "nonebot-plugin-bittorrents"
3
- version = "1.1.0"
3
+ version = "1.1.2"
4
4
  description = "适配NoneBot的磁力搜索插件,通过机器人帮你寻找电影、软件或者学习资料"
5
5
  authors = [
6
6
  {name = "NightDust981989"}
@@ -8,13 +8,10 @@ authors = [
8
8
  license = "MIT"
9
9
  readme = "README.md"
10
10
  dependencies = [
11
- "httpx",
12
- "beautifulsoup4",
13
- "lxml",
14
- "pydantic",
15
- "pydantic-settings",
16
- "nonebot2",
17
- "nonebot-adapter-onebot"
11
+ "httpx>=0.23.0",
12
+ "beautifulsoup4>=4.11.0",
13
+ "lxml>=4.9.0",
14
+ "nonebot2>=2.3.0",
18
15
  ]
19
16
 
20
17
  [project.urls]
@@ -1,7 +0,0 @@
1
- httpx
2
- beautifulsoup4
3
- lxml
4
- pydantic
5
- pydantic-settings
6
- nonebot2
7
- nonebot-adapter-onebot