mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-02 02:00:01 +08:00
first_commit .gitignore
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
from nonebot import on_command
|
||||
from .data_source import get_bt_info
|
||||
from services.log import logger
|
||||
from nonebot.typing import T_State
|
||||
from nonebot.adapters import Bot
|
||||
from nonebot.adapters.cqhttp import PrivateMessageEvent
|
||||
from util.utils import get_message_text
|
||||
from nonebot.adapters.cqhttp.permission import PRIVATE
|
||||
from util.utils import UserExistLimiter
|
||||
|
||||
__plugin_name__ = '磁力搜索'
|
||||
__plugin_usage__ = r"""
|
||||
* 请各位使用后不要转发 *
|
||||
* 有时可能搜不到,再试一次就行了 *
|
||||
参数: -U(时间) -H(热度) -S(大小)
|
||||
-V(仅视频) -P(仅图片) -A(仅压缩包)
|
||||
-R (R18懂的都懂)
|
||||
num(页数, 如果不知道页数请不要填,并且是倒叙,比如页数总数是29,你想查看第一页的内容, 就使用 bt 29 xxx)
|
||||
-按相关度检索(默认)
|
||||
bt [关键词]
|
||||
-按更新时间检索(参数不区分大小写,但要注意空格)
|
||||
bt -U [关键词]
|
||||
-搜索第10页数
|
||||
bt 10(倒着) [关键词]
|
||||
""".strip()
|
||||
|
||||
_ulmt = UserExistLimiter()
|
||||
|
||||
bt = on_command('bt', permission=PRIVATE, priority=5, block=True)
|
||||
|
||||
|
||||
@bt.args_parser
|
||||
async def _(bot: Bot, event: PrivateMessageEvent, state: T_State):
|
||||
if str(event.get_message()) in ['取消', '算了']:
|
||||
await bt.finish("已取消操作..", at_sender=True)
|
||||
msg = get_message_text(event.json())
|
||||
if not msg:
|
||||
await bt.reject('你想搜索什么呢?', at_sender=True)
|
||||
mp = msg.split(" ")
|
||||
if len(mp) > 1:
|
||||
args = ''
|
||||
for i in range(len(mp) - 1):
|
||||
args += mp[i] + ' '
|
||||
state['args'] = args
|
||||
state['bt'] = mp[1]
|
||||
else:
|
||||
state['bt'] = get_message_text(event.json())
|
||||
state['args'] = ''
|
||||
|
||||
|
||||
@bt.handle()
|
||||
async def _(bot: Bot, event: PrivateMessageEvent, state: T_State):
|
||||
if get_message_text(event.json()) in ['帮助'] or str(event.get_message()) == '':
|
||||
await bt.finish(__plugin_usage__)
|
||||
if _ulmt.check(event.user_id):
|
||||
await bt.finish('您有bt任务正在进行,请等待结束.', at_sender=True)
|
||||
mp = get_message_text(event.json()).split(" ")
|
||||
if len(mp) > 1:
|
||||
args = ''
|
||||
for i in range(len(mp) - 1):
|
||||
args += mp[i] + ' '
|
||||
state['args'] = args.strip()
|
||||
state['bt'] = mp[-1]
|
||||
else:
|
||||
state['bt'] = get_message_text(event.json())
|
||||
state['args'] = ''
|
||||
|
||||
|
||||
@bt.got('bt', prompt='虚空磁力?查什么GKD')
|
||||
async def _(bot: Bot, event: PrivateMessageEvent, state: T_State):
|
||||
_ulmt.set_True(event.user_id)
|
||||
keyword = state['bt']
|
||||
args = state['args']
|
||||
await bt.send('开始搜索....', at_sender=True)
|
||||
try:
|
||||
if args.find('-R') == -1 and args.find('-r') == -1:
|
||||
bt_report = await get_bt_info(keyword, args)
|
||||
else:
|
||||
bt_report = await get_bt_info(keyword, args, '0')
|
||||
if bt_report:
|
||||
if len(bt_report.split("\n")) < 2:
|
||||
await bt.finish(bt_report + '搜索失败了,再试一次也许能成', at_sender=True)
|
||||
else:
|
||||
await bt.send("如果有页数没资源请再试一次\n" + bt_report)
|
||||
logger.info(
|
||||
f"(USER {event.user_id}, GROUP {event.group_id if event.message_type != 'private' else 'private'})"
|
||||
f" 搜索bt {args} {keyword}")
|
||||
else:
|
||||
logger.error("没查询到资源")
|
||||
await bt.send("没有查询到资源(也有可能是超时,再试一次?)", at_sender=True)
|
||||
_ulmt.set_False(event.user_id)
|
||||
except Exception as e:
|
||||
_ulmt.set_False(event.user_id)
|
||||
await bt.send("bt出错啦,再试一次?", at_sender=True)
|
||||
logger.info(f'bt {keyword} 出错 e:{e}')
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,96 @@
|
||||
from util.user_agent import get_user_agent
|
||||
import aiohttp
|
||||
from lxml import etree
|
||||
from lxml.etree import Element
|
||||
from configs.config import MAXINFO_BT
|
||||
from urllib import parse
|
||||
from html import unescape
|
||||
from util.utils import get_local_proxy, is_number
|
||||
import time
|
||||
import platform
|
||||
if platform.system() == 'Windows':
|
||||
import asyncio
|
||||
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
||||
|
||||
|
||||
url = 'https://www.btmet.com/search.php'
|
||||
|
||||
|
||||
async def get_bt_info(keyword: str, args: str, r18: str = '1') -> str:
|
||||
cookiesDit = {
|
||||
'r18': r18
|
||||
}
|
||||
s_time = time.time()
|
||||
params = get_params(keyword, args)
|
||||
async with aiohttp.ClientSession(headers=get_user_agent(), cookies=cookiesDit) as session:
|
||||
async with session.get(url, proxy=get_local_proxy(), params=params, timeout=30) as response:
|
||||
html = etree.HTML(await response.text())
|
||||
print(response.url)
|
||||
num = html.xpath('//div[@id="wall"]//span/b/text()')[0]
|
||||
print(num)
|
||||
if num.find(",") != -1:
|
||||
num = num.split(',')[0]
|
||||
if num == '0':
|
||||
return "没有找到记录"
|
||||
|
||||
div_all = html.xpath('//div[@class="search-item"]')[1:]
|
||||
div_all = div_all[:MAXINFO_BT] if len(div_all) > MAXINFO_BT else div_all
|
||||
line_list = [await get_item_line(div) for div in div_all]
|
||||
clist = []
|
||||
for line in line_list:
|
||||
if line.strip() != '':
|
||||
clist.append(line)
|
||||
|
||||
return f"搜索 {keyword} 结果(共 {int(int(num.text) / 10) if int(num) % 10 == 0 else int(int(num) / 10) + 1} " \
|
||||
f"页)(耗时 {int(time.time() - s_time)} 秒):\n" + "\n\n".join(clist)
|
||||
|
||||
|
||||
async def get_item_line(div: Element) -> str:
|
||||
try:
|
||||
magent = div.xpath('./div[2]/a/@href')[0]
|
||||
size = div.xpath('./div[@class="f_left"]/div[@class="item-bar"]/span/b/font/text()')[0]
|
||||
type = div.xpath('./div[@class="f_left"]/div[@class="item-bar"]/span[@class="cpill blue-pill"]/text()')[0].strip()
|
||||
|
||||
title_doc = div.xpath('.//a[@class="smashTitle"]//text()')[0]
|
||||
title_code = title_doc[title_doc.find('("') + 2: title_doc.find('")')]
|
||||
title_xml_code = parse.unquote(title_code)
|
||||
title_xml = etree.HTML(unescape(title_xml_code))
|
||||
title = title_xml.xpath('string(.)')
|
||||
except Exception:
|
||||
return ''
|
||||
return "【{}】| {}\n【{}】| {}".format(type, title, size, magent)
|
||||
|
||||
|
||||
# https://www.btmet.com/search.php?q=%E9%92%A2%E9%93%81%E4%BE%A0&c=5&o=0&l=&p=2
|
||||
def get_params(keyword: str, args: str) -> dict:
|
||||
params = {
|
||||
'q': keyword,
|
||||
'c': '',
|
||||
'l': '',
|
||||
'o': 0,
|
||||
'p': ''
|
||||
}
|
||||
if not args:
|
||||
return params
|
||||
args = args.split(" ")
|
||||
for arg in args:
|
||||
if '-U' == arg.upper():
|
||||
params['o'] = 1
|
||||
if '-S' == arg.upper():
|
||||
params['o'] = 2
|
||||
if '-H' == arg.upper():
|
||||
params['o'] = 3
|
||||
if '-V' == arg.upper():
|
||||
params['c'] = 1
|
||||
if '-P' == arg.upper():
|
||||
params['c'] = 2
|
||||
if '-A' == arg.upper():
|
||||
params['c'] = 5
|
||||
if is_number(arg):
|
||||
params['p'] = arg
|
||||
return params
|
||||
|
||||
|
||||
# print(asyncio.get_event_loop().run_until_complete(get_bt_info('钢铁侠', '')))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user