mirror of
https://github.com/Xtao-Labs/iShotaBot.git
synced 2024-11-21 14:48:23 +00:00
✨ 支持群组内显示下载按钮
This commit is contained in:
parent
9e1d5cedaa
commit
8f0ab8746f
@ -9,6 +9,7 @@ import aiofiles
|
||||
from bilibili_api import HEADERS
|
||||
from bilibili_api.video import Video, VideoDownloadURLDataDetecter, VideoQuality
|
||||
from httpx import AsyncClient, Response
|
||||
from pyrogram.enums import ParseMode
|
||||
from pyrogram.types import Message
|
||||
|
||||
from defs.request import cache_dir
|
||||
@ -203,10 +204,9 @@ async def get_video_height_width(path: str) -> Tuple[int, int]:
|
||||
return int(video_height), int(video_width)
|
||||
|
||||
|
||||
async def take_screenshot(v: Video) -> Optional[BytesIO]:
|
||||
async def take_screenshot(info: Dict) -> Optional[BytesIO]:
|
||||
"""获取视频封面"""
|
||||
try:
|
||||
info = await v.get_info()
|
||||
pic_get = (await request.get(info["pic"])).content
|
||||
pic = BytesIO(pic_get)
|
||||
pic.name = "screenshot.jpg"
|
||||
@ -291,11 +291,19 @@ async def go_upload(v: Video, p_num: int, m: Message):
|
||||
try:
|
||||
video_duration = await get_video_duration(video_path)
|
||||
video_height, video_width = await get_video_height_width(video_path)
|
||||
video_jpg = await take_screenshot(v)
|
||||
try:
|
||||
info = await v.get_info()
|
||||
video_jpg = await take_screenshot(info)
|
||||
caption = f"<b>{info['title']}</b>\n\n{info['desc']}\n\nhttps://b23.tv/{v.get_bvid()}"
|
||||
except Exception:
|
||||
video_jpg = None
|
||||
caption = f"https://b23.tv/{v.get_bvid()}"
|
||||
logger.info(f"Uploading {video_path}")
|
||||
await bot.send_video(
|
||||
chat_id=m.chat.id,
|
||||
video=str(video_path),
|
||||
caption=caption,
|
||||
parse_mode=ParseMode.HTML,
|
||||
duration=int(video_duration),
|
||||
width=video_width,
|
||||
height=video_height,
|
||||
|
@ -25,4 +25,4 @@ def gen_button(data: List) -> InlineKeyboardMarkup:
|
||||
buttons_callback.append(
|
||||
InlineKeyboardButton(text=button.name, callback_data=button.data)
|
||||
)
|
||||
return InlineKeyboardMarkup(inline_keyboard=[buttons_callback, buttons_url])
|
||||
return InlineKeyboardMarkup(inline_keyboard=[buttons_url, buttons_callback])
|
||||
|
@ -12,6 +12,7 @@ from defs.bilibili import (
|
||||
check_and_refresh_credential,
|
||||
)
|
||||
from defs.button import gen_button, Button
|
||||
from defs.glover import bili_auth_user
|
||||
from init import bot
|
||||
from scheduler import scheduler
|
||||
|
||||
@ -35,12 +36,13 @@ async def bili_resolve(_: Client, message: Message):
|
||||
video_info = await video_info_get(video_number) if video_number else None
|
||||
if video_info:
|
||||
image = await binfo_image_create(video_info)
|
||||
buttons = [Button(0, "Link", "https://b23.tv/" + video_info["bvid"])]
|
||||
if message.from_user and message.from_user.id in bili_auth_user:
|
||||
buttons.append(Button(1, "Download", "download_" + video_info["bvid"]))
|
||||
await message.reply_photo(
|
||||
image,
|
||||
quote=True,
|
||||
reply_markup=gen_button(
|
||||
[Button(0, "Link", "https://b23.tv/" + video_info["bvid"])]
|
||||
),
|
||||
reply_markup=gen_button(buttons),
|
||||
)
|
||||
raise ContinuePropagation
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
import re
|
||||
|
||||
from pyrogram import filters, Client, ContinuePropagation
|
||||
from pyrogram.types import Message
|
||||
from pyrogram.types import Message, CallbackQuery
|
||||
|
||||
from defs.bilibili import b23_extract, video_info_get, create_video
|
||||
from defs.bilibili import b23_extract, create_video
|
||||
from defs.bilibili_download import go_download
|
||||
from defs.glover import bili_auth_user
|
||||
from init import bot
|
||||
@ -11,7 +11,7 @@ from init import bot
|
||||
|
||||
@bot.on_message(
|
||||
filters.incoming
|
||||
& filters.private
|
||||
& filters.text
|
||||
& filters.user(bili_auth_user)
|
||||
& filters.command(["download"])
|
||||
)
|
||||
@ -31,3 +31,18 @@ async def bili_download_resolve(_: Client, message: Message):
|
||||
video = create_video(video_number)
|
||||
m = await message.reply("开始获取视频数据", quote=True)
|
||||
bot.loop.create_task(go_download(video, p_num, 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("开始下载")
|
||||
|
Loading…
Reference in New Issue
Block a user