mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-05 20:00:04 +08:00
update 0.0.6.2
This commit is contained in:
Regular → Executable
+1
-4
@@ -7,7 +7,6 @@ from nonebot.adapters.cqhttp import PrivateMessageEvent
|
||||
from utils.utils import get_message_text
|
||||
from nonebot.adapters.cqhttp.permission import PRIVATE
|
||||
from asyncio.exceptions import TimeoutError
|
||||
from aiohttp.client_exceptions import ServerDisconnectedError
|
||||
|
||||
__zx_plugin_name__ = "磁力搜索"
|
||||
__plugin_usage__ = """
|
||||
@@ -89,11 +88,9 @@ async def _(bot: Bot, event: PrivateMessageEvent, state: T_State):
|
||||
send_flag = True
|
||||
except TimeoutError:
|
||||
await bt.finish(f"搜索 {keyword} 超时...")
|
||||
except ServerDisconnectedError:
|
||||
await bt.finish(f"搜索 {keyword} 连接失败")
|
||||
except Exception as e:
|
||||
await bt.finish(f"bt 其他未知错误..")
|
||||
logger.error(f"bt 错误 e:{e}")
|
||||
logger.error(f"bt 错误 {type(e)}:{e}")
|
||||
if not send_flag:
|
||||
await bt.send(f"{keyword} 未搜索到...")
|
||||
logger.info(f"USER {event.user_id} BT搜索 {keyword} 第 {page} 页")
|
||||
|
||||
Regular → Executable
+35
-34
@@ -1,8 +1,6 @@
|
||||
from utils.user_agent import get_user_agent
|
||||
import aiohttp
|
||||
from utils.http_utils import AsyncHttpx
|
||||
from configs.config import Config
|
||||
from bs4 import BeautifulSoup
|
||||
from utils.utils import get_local_proxy
|
||||
import platform
|
||||
|
||||
if platform.system() == "Windows":
|
||||
@@ -15,36 +13,39 @@ url = "http://www.eclzz.world"
|
||||
|
||||
|
||||
async def get_bt_info(keyword: str, page: str):
|
||||
async with aiohttp.ClientSession(headers=get_user_agent()) as session:
|
||||
async with session.get(
|
||||
f"{url}/s/{keyword}_rel_{page}.html", proxy=get_local_proxy(), timeout=5
|
||||
) as response:
|
||||
text = await response.text()
|
||||
if text.find("大约0条结果") != -1:
|
||||
return
|
||||
soup = BeautifulSoup(text, "lxml")
|
||||
item_lst = soup.find_all("div", {"class": "search-item"})
|
||||
bt_max_num = Config.get_config("bt", "BT_MAX_NUM")
|
||||
bt_max_num = bt_max_num if bt_max_num < len(item_lst) else len(item_lst)
|
||||
for item in item_lst[:bt_max_num]:
|
||||
divs = item.find_all("div")
|
||||
title = (
|
||||
str(divs[0].find("a").text)
|
||||
.replace("<em>", "")
|
||||
.replace("</em>", "")
|
||||
.strip()
|
||||
)
|
||||
spans = divs[2].find_all("span")
|
||||
itype = spans[0].text
|
||||
create_time = spans[1].find("b").text
|
||||
file_size = spans[2].find("b").text
|
||||
link = await get_download_link(divs[0].find("a")["href"], session)
|
||||
yield title, itype, create_time, file_size, link
|
||||
"""
|
||||
获取资源信息
|
||||
:param keyword: 关键词
|
||||
:param page: 页数
|
||||
"""
|
||||
text = (await AsyncHttpx.get(f"{url}/s/{keyword}_rel_{page}.html", timeout=5)).text
|
||||
if text.find("大约0条结果") != -1:
|
||||
return
|
||||
soup = BeautifulSoup(text, "lxml")
|
||||
item_lst = soup.find_all("div", {"class": "search-item"})
|
||||
bt_max_num = Config.get_config("bt", "BT_MAX_NUM")
|
||||
bt_max_num = bt_max_num if bt_max_num < len(item_lst) else len(item_lst)
|
||||
for item in item_lst[:bt_max_num]:
|
||||
divs = item.find_all("div")
|
||||
title = (
|
||||
str(divs[0].find("a").text)
|
||||
.replace("<em>", "")
|
||||
.replace("</em>", "")
|
||||
.strip()
|
||||
)
|
||||
spans = divs[2].find_all("span")
|
||||
itype = spans[0].text
|
||||
create_time = spans[1].find("b").text
|
||||
file_size = spans[2].find("b").text
|
||||
link = await get_download_link(divs[0].find("a")["href"])
|
||||
yield title, itype, create_time, file_size, link
|
||||
|
||||
|
||||
async def get_download_link(_url: str, session) -> str:
|
||||
async with session.get(
|
||||
f"{url}{_url}", proxy=get_local_proxy(), timeout=30
|
||||
) as response:
|
||||
soup = BeautifulSoup(await response.text(), "lxml")
|
||||
return soup.find("a", {"id": "down-url"})["href"]
|
||||
async def get_download_link(_url: str) -> str:
|
||||
"""
|
||||
获取资源下载地址
|
||||
:param _url: 链接
|
||||
"""
|
||||
text = (await AsyncHttpx.get(f"{url}{_url}")).text
|
||||
soup = BeautifulSoup(text, "lxml")
|
||||
return soup.find("a", {"id": "down-url"})["href"]
|
||||
|
||||
Reference in New Issue
Block a user