update wbtop

This commit is contained in:
HibiKier 2022-05-21 23:34:48 +08:00
parent 82902e0cde
commit c511ef50a2
5 changed files with 174 additions and 178 deletions

View File

@ -254,6 +254,7 @@ __Docker 最新版本由 [Sakuracio](https://github.com/Sakuracio) 提供__
* 修复了多连开箱无法指定武器箱 * 修复了多连开箱无法指定武器箱
* 修复识番链接无法正确获取 * 修复识番链接无法正确获取
* 新增真寻入群时即刻刷新权限 * 新增真寻入群时即刻刷新权限
* 提高了微博热搜截图的等待时间
### 2022/5/19 ### 2022/5/19

View File

@ -60,8 +60,8 @@ async def _(event: MessageEvent, arg: Message = CommandArg()):
img = await AsyncPlaywright.screenshot( img = await AsyncPlaywright.screenshot(
url, url,
f"{IMAGE_PATH}/temp/wbtop_{event.user_id}.png", f"{IMAGE_PATH}/temp/wbtop_{event.user_id}.png",
"#pl_feedlist_index", "#pl_feed_main",
wait_time=5 wait_time=12
) )
if img: if img:
await wbtop.send(img) await wbtop.send(img)

View File

@ -1,171 +1,166 @@
from nonebot import on_message # from nonebot import on_message
from services.log import logger # from services.log import logger
from nonebot.adapters.onebot.v11 import GroupMessageEvent # from nonebot.adapters.onebot.v11 import GroupMessageEvent
from utils.utils import get_message_json, get_local_proxy, is_number, get_message_text # from utils.utils import get_message_json, get_local_proxy, is_number, get_message_text
from nonebot.adapters.onebot.v11.permission import GROUP # from nonebot.adapters.onebot.v11.permission import GROUP
from bilibili_api import video # from utils.message_builder import image
from utils.message_builder import image # from nonebot.adapters.onebot.v11.exception import ActionFailed
from nonebot.adapters.onebot.v11.exception import ActionFailed # from utils.image_utils import BuildImage
from utils.image_utils import BuildImage # from utils.browser import get_browser
from utils.browser import get_browser # from configs.path_config import IMAGE_PATH
from configs.path_config import IMAGE_PATH # from utils.http_utils import AsyncHttpx
from utils.http_utils import AsyncHttpx # from configs.config import Config
from configs.config import Config # from utils.user_agent import get_user_agent
from utils.user_agent import get_user_agent # import aiohttp
import aiohttp # import asyncio
import asyncio # import time
import time # import ujson as json
from bilibili_api import settings #
import ujson as json #
# __zx_plugin_name__ = "B站转发解析"
# __plugin_usage__ = """
__zx_plugin_name__ = "B站转发解析" # usage
__plugin_usage__ = """ # B站转发解析解析b站分享信息支持bvbilibili链接b站手机端转发卡片cvb23.tv且5分钟内不解析相同url
usage # """.strip()
B站转发解析解析b站分享信息支持bvbilibili链接b站手机端转发卡片cvb23.tv且5分钟内不解析相同url # __plugin_des__ = "B站转发解析"
""".strip() # __plugin_type__ = ("其他",)
__plugin_des__ = "B站转发解析" # __plugin_version__ = 0.1
__plugin_type__ = ("其他",) # __plugin_author__ = "HibiKier"
__plugin_version__ = 0.1 # __plugin_task__ = {"bilibili_parse": "b站转发解析"}
__plugin_author__ = "HibiKier" # Config.add_plugin_config(
__plugin_task__ = {"bilibili_parse": "b站转发解析"} # "_task",
Config.add_plugin_config( # "DEFAULT_BILIBILI_PARSE",
"_task", # True,
"DEFAULT_BILIBILI_PARSE", # help_="被动 B站转发解析 进群默认开关状态",
True, # default_value=True,
help_="被动 B站转发解析 进群默认开关状态",
default_value=True,
)
if get_local_proxy():
settings.proxy = get_local_proxy()
parse_bilibili_json = on_message(priority=1, permission=GROUP, block=False)
_tmp = {}
@parse_bilibili_json.handle()
async def _(event: GroupMessageEvent):
vd_info = None
url = None
if get_message_json(event.json()):
try:
data = json.loads(get_message_json(event.json())[0]["data"])
except (IndexError, KeyError):
data = None
if data:
# 转发视频
if data.get("desc") == "哔哩哔哩":
async with aiohttp.ClientSession(
headers=get_user_agent()
) as session:
async with session.get(
data["meta"]["detail_1"]["qqdocurl"],
proxy=get_local_proxy(),
timeout=7,
) as response:
url = str(response.url).split("?")[0]
bvid = url.split("/")[-1]
vd_info = await video.Video(bvid=bvid).get_info()
# response = await AsyncHttpx.get(
# data["meta"]["detail_1"]["qqdocurl"], timeout=7
# ) # )
#
#
# parse_bilibili_json = on_message(priority=1, permission=GROUP, block=False)
#
# _tmp = {}
#
#
# @parse_bilibili_json.handle()
# async def _(event: GroupMessageEvent):
# vd_info = None
# url = None
# if get_message_json(event.json()):
# try:
# data = json.loads(get_message_json(event.json())[0]["data"])
# except (IndexError, KeyError):
# data = None
# if data:
# # 转发视频
# if data.get("desc") == "哔哩哔哩":
# async with aiohttp.ClientSession(
# headers=get_user_agent()
# ) as session:
# async with session.get(
# data["meta"]["detail_1"]["qqdocurl"],
# proxy=get_local_proxy(),
# timeout=7,
# ) as response:
# url = str(response.url).split("?")[0] # url = str(response.url).split("?")[0]
# bvid = url.split("/")[-1] # bvid = url.split("/")[-1]
# vd_info = await video.Video(bvid=bvid).get_info() # vd_info = await video.Video(bvid=bvid).get_info()
# 转发专栏 # # response = await AsyncHttpx.get(
if ( # # data["meta"]["detail_1"]["qqdocurl"], timeout=7
data.get("meta") # # )
and data["meta"].get("news") # # url = str(response.url).split("?")[0]
and data["meta"]["news"].get("desc") == "哔哩哔哩专栏" # # bvid = url.split("/")[-1]
): # # vd_info = await video.Video(bvid=bvid).get_info()
url = data["meta"]["news"]["jumpUrl"] # # 转发专栏
page = None # if (
try: # data.get("meta")
browser = await get_browser() # and data["meta"].get("news")
if not browser: # and data["meta"]["news"].get("desc") == "哔哩哔哩专栏"
return # ):
page = await browser.new_page( # url = data["meta"]["news"]["jumpUrl"]
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" # page = None
" (KHTML, like Gecko) Chrome/93.0.4530.0 Safari/537.36" # try:
) # browser = await get_browser()
await page.goto(url, wait_until="networkidle", timeout=10000) # if not browser:
await page.set_viewport_size({"width": 2560, "height": 1080}) # return
await page.click("#app > div") # page = await browser.new_page(
div = await page.query_selector("#app > div") # user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
await div.screenshot( # " (KHTML, like Gecko) Chrome/93.0.4530.0 Safari/537.36"
path=f"{IMAGE_PATH}/temp/cv_{event.user_id}.png", # )
timeout=100000, # await page.goto(url, wait_until="networkidle", timeout=10000)
) # await page.set_viewport_size({"width": 2560, "height": 1080})
await asyncio.get_event_loop().run_in_executor( # await page.click("#app > div")
None, resize, f"{IMAGE_PATH}/temp/cv_{event.user_id}.png" # div = await page.query_selector("#app > div")
) # await div.screenshot(
await parse_bilibili_json.send( # path=f"{IMAGE_PATH}/temp/cv_{event.user_id}.png",
"[[_task|bilibili_parse]]" + image(f"cv_{event.user_id}.png", "temp") # timeout=100000,
) # )
await page.close() # await asyncio.get_event_loop().run_in_executor(
logger.info( # None, resize, f"{IMAGE_PATH}/temp/cv_{event.user_id}.png"
f"USER {event.user_id} GROUP {event.group_id} 解析bilibili转发 {url}" # )
) # await parse_bilibili_json.send(
except Exception as e: # "[[_task|bilibili_parse]]" + image(f"cv_{event.user_id}.png", "temp")
logger.error(f"尝试解析bilibili专栏 {url} 失败 {type(e)}{e}") # )
if page: # await page.close()
await page.close() # logger.info(
return # f"USER {event.user_id} GROUP {event.group_id} 解析bilibili转发 {url}"
# BV # )
if msg := get_message_text(event.json()): # except Exception as e:
if "BV" in msg: # logger.error(f"尝试解析bilibili专栏 {url} 失败 {type(e)}{e}")
index = msg.find("BV") # if page:
if len(msg[index + 2 :]) >= 10: # await page.close()
msg = msg[index : index + 12] # return
url = f"https://www.bilibili.com/video/{msg}" # # BV
vd_info = await video.Video(bvid=msg).get_info() # if msg := get_message_text(event.json()):
elif "av" in msg: # if "BV" in msg:
index = msg.find("av") # index = msg.find("BV")
if len(msg[index + 2 :]) >= 9: # if len(msg[index + 2 :]) >= 10:
msg = msg[index + 2 : index + 11] # msg = msg[index : index + 12]
if is_number(msg): # url = f"https://www.bilibili.com/video/{msg}"
url = f"https://www.bilibili.com/video/{msg}" # vd_info = await video.Video(bvid=msg).get_info()
vd_info = await video.Video(aid=int(msg)).get_info() # elif "av" in msg:
elif "https://b23.tv" in msg: # index = msg.find("av")
url = "https://" + msg[msg.find("b23.tv") : msg.find("b23.tv") + 13] # if len(msg[index + 2 :]) >= 9:
res = await AsyncHttpx.get(url, timeout=7) # msg = msg[index + 2 : index + 11]
url = str(res.url).split("?")[0] # if is_number(msg):
bvid = url.split("/")[-1] # url = f"https://www.bilibili.com/video/{msg}"
vd_info = await video.Video(bvid=bvid).get_info() # vd_info = await video.Video(aid=int(msg)).get_info()
if vd_info: # elif "https://b23.tv" in msg:
if ( # url = "https://" + msg[msg.find("b23.tv") : msg.find("b23.tv") + 13]
url in _tmp.keys() and time.time() - _tmp[url] > 30 # res = await AsyncHttpx.get(url, timeout=7)
) or url not in _tmp.keys(): # url = str(res.url).split("?")[0]
_tmp[url] = time.time() # bvid = url.split("/")[-1]
aid = vd_info["aid"] # vd_info = await video.Video(bvid=bvid).get_info()
title = vd_info["title"] # if vd_info:
author = vd_info["owner"]["name"] # if (
reply = vd_info["stat"]["reply"] # 回复 # url in _tmp.keys() and time.time() - _tmp[url] > 30
favorite = vd_info["stat"]["favorite"] # 收藏 # ) or url not in _tmp.keys():
coin = vd_info["stat"]["coin"] # 投币 # _tmp[url] = time.time()
# like = vd_info['stat']['like'] # 点赞 # aid = vd_info["aid"]
# danmu = vd_info['stat']['danmaku'] # 弹幕 # title = vd_info["title"]
date = time.strftime("%Y-%m-%d", time.localtime(vd_info["ctime"])) # author = vd_info["owner"]["name"]
try: # reply = vd_info["stat"]["reply"] # 回复
await parse_bilibili_json.send( # favorite = vd_info["stat"]["favorite"] # 收藏
"[[_task|bilibili_parse]]" + # coin = vd_info["stat"]["coin"] # 投币
image(vd_info["pic"]) + f"\nav{aid}\n标题:{title}\n" # # like = vd_info['stat']['like'] # 点赞
f"UP{author}\n" # # danmu = vd_info['stat']['danmaku'] # 弹幕
f"上传日期:{date}\n" # date = time.strftime("%Y-%m-%d", time.localtime(vd_info["ctime"]))
f"回复:{reply},收藏:{favorite},投币:{coin}\n" # try:
f"{url}" # await parse_bilibili_json.send(
) # "[[_task|bilibili_parse]]" +
except ActionFailed: # image(vd_info["pic"]) + f"\nav{aid}\n标题{title}\n"
logger.warning(f"{event.group_id} 发送bilibili解析失败") # f"UP{author}\n"
else: # f"上传日期:{date}\n"
logger.info( # f"回复:{reply},收藏:{favorite},投币:{coin}\n"
f"USER {event.user_id} GROUP {event.group_id} 解析bilibili转发 {url}" # f"{url}"
) # )
# except ActionFailed:
# logger.warning(f"{event.group_id} 发送bilibili解析失败")
def resize(path: str): # else:
A = BuildImage(0, 0, background=path, ratio=0.5) # logger.info(
A.save(path) # f"USER {event.user_id} GROUP {event.group_id} 解析bilibili转发 {url}"
# )
#
#
# def resize(path: str):
# A = BuildImage(0, 0, background=path, ratio=0.5)
# A.save(path)

View File

@ -12,7 +12,7 @@ __plugin_usage__ = """
usage usage
普普通通的查天气吧 普普通通的查天气吧
指令 指令
[城市]天气/天气[城市] [城市]天气
""".strip() """.strip()
__plugin_des__ = "出门要看看天气,不要忘了带伞" __plugin_des__ = "出门要看看天气,不要忘了带伞"
__plugin_cmd__ = ["[城市]天气/天气[城市]"] __plugin_cmd__ = ["[城市]天气/天气[城市]"]
@ -27,13 +27,13 @@ __plugin_settings__ = {
} }
weather = on_regex(r".{0,10}?(.*)的?天气.*?.{0,10}", priority=5, block=True) weather = on_regex(r".{0,10}?(.*)的?天气.{0,10}", priority=5, block=True)
@weather.handle() @weather.handle()
async def _(event: MessageEvent, reg_group: Tuple[Any, ...] = RegexGroup()): async def _(event: MessageEvent, reg_group: Tuple[Any, ...] = RegexGroup()):
msg = reg_group[0] msg = reg_group[0]
if msg[-1] != "": if msg and msg[-1] != "":
msg += "" msg += ""
city = "" city = ""
if msg: if msg:

View File

@ -327,14 +327,14 @@ class AsyncPlaywright:
await page.set_viewport_size(viewport_size) await page.set_viewport_size(viewport_size)
if isinstance(element, str): if isinstance(element, str):
if wait_time: if wait_time:
card = await page.wait_for_selector(element, timeout=wait_time) card = await page.wait_for_selector(element, timeout=wait_time * 1000)
else: else:
card = await page.query_selector(element) card = await page.query_selector(element)
else: else:
card = page card = page
for e in element: for e in element:
if wait_time: if wait_time:
card = await card.wait_for_selector(e, timeout=wait_time) card = await card.wait_for_selector(e, timeout=wait_time * 1000)
else: else:
card = await card.query_selector(e) card = await card.query_selector(e)
await card.screenshot(path=path, timeout=timeout, type=type_) await card.screenshot(path=path, timeout=timeout, type=type_)