update parse_bilibili

This commit is contained in:
yajiwa 2022-06-21 08:50:05 +08:00
parent a9a636c9ae
commit 9c56a81f65
2 changed files with 165 additions and 166 deletions

View File

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

View File

@ -39,7 +39,7 @@ dateparser = "^1.1.0"
cn2an = "^0.5.16" cn2an = "^0.5.16"
python-jose = "^3.3.0" python-jose = "^3.3.0"
python-multipart = "^0.0.5" python-multipart = "^0.0.5"
bilireq = "^0.1.2" bilireq = "^0.2.0"
emoji = "^1.7.0" emoji = "^1.7.0"
wordcloud = "^1.8.1" wordcloud = "^1.8.1"
rich = "^12.4.3" rich = "^12.4.3"