import re from pyrogram import filters, Client, ContinuePropagation from pyrogram.types import Message, CallbackQuery from defs.bilibili import b23_extract, create_video, create_audio from defs.bilibili_download import go_download, audio_download from defs.glover import bili_auth_user from init import bot @bot.on_message( filters.incoming & filters.text & filters.user(bili_auth_user) & filters.command(["download"]) ) async def bili_download_resolve(_: Client, message: Message): if "b23.tv" in message.text: message.text = await b23_extract(message.text) p = re.compile(r"av(\d{1,12})|BV(1[A-Za-z0-9]{2}4.1.7[A-Za-z0-9]{2})") video_number = p.search(message.text) if video_number: video_number = video_number[0] else: await message.reply("未找到视频 BV 号或 AV 号") raise ContinuePropagation p_ = re.compile(r"p=(\d{1,3})") p_num = p_.search(message.text) p_num = int(p_num[0][2:]) if p_num else 0 video = create_video(video_number) m = await message.reply("开始获取视频数据", quote=True) bot.loop.create_task(go_download(video, p_num, m)) @bot.on_message(filters.incoming & filters.text & filters.regex(r"audio/au(\d{1,12})")) async def bili_audio_download_resolve(_: Client, message: Message): p = re.compile(r"au(\d{1,12})") audio_number = p.search(message.text) if audio_number: audio_number = audio_number[0] else: raise ContinuePropagation audio = create_audio(audio_number) m = await message.reply("开始获取音频数据", quote=True) bot.loop.create_task(audio_download(audio, m)) @bot.on_callback_query(filters.regex(r"^download_(.*)$")) async def bili_download_resolve_cb(_: Client, callback_query: CallbackQuery): if not callback_query.from_user: await callback_query.answer("请私聊机器人") return if callback_query.from_user.id not in bili_auth_user: await callback_query.answer("你没有权限使用此功能") return video_number = callback_query.matches[0].group(1) video = create_video(video_number) m = await callback_query.message.reply("开始获取视频数据", quote=True) bot.loop.create_task(go_download(video, 0, m)) await callback_query.answer("开始下载")