refactor: restructure plugins per MTSS standard, consolidate assets to res/
Per docs/plugin-audit-report.md (plugins normalized to Trigger(handlers) → Service(services) → Model(repository/models) + utils): - Split monolithic __init__.py into handlers/services/utils across dailywife, deer_pipe, dice, galgame_card, helldivers_tools, huoziyinshua, learning_chat, makeaquote, mc_server_status, ncm_saying, picfinder_take, picstatus, random_jm_code, regif, steam_info, video_analysis, group_tools - Move static assets under res/: deer_pipe font/img, makeaquote font, helldivers img/templates, huoziyinshua HuoZiYinShua - Add config.py + register_config_items to ncm_saying, random_jm_code, group_tools; learning_chat unified config bridge - Remove deprecated: voice_trans plugin, bf_bot/test.py, dead code in dailywife/deer_pipe, empty dirs, debug scripts under helldivers temp - Disable brash_general_supercredits_tools (stub comment only) - bot.py: optional stdout/stderr redirect to log file for Web log viewer, force ANSI colorize on non-TTY sinks - Move runtime data (jm_code.json) out of plugin dir into hexi/data - Docs: plugin-audit-report.md; README reflects removed plugins Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
"""群管理工具 —— 视频下载。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import re
|
||||
import time
|
||||
|
||||
from nonebot import logger, on_startswith, require
|
||||
from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent
|
||||
from nonebot_plugin_alconna import UniMessage
|
||||
|
||||
from ...constants import TEMP_DIR
|
||||
from ...services.video import download_video, get_video_info, local_video
|
||||
from ...utils.text import is_number
|
||||
|
||||
require("nonebot_plugin_alconna")
|
||||
|
||||
down_video = on_startswith("/video")
|
||||
|
||||
|
||||
@down_video.handle()
|
||||
async def down_video_handle(bot: Bot, ev: GroupMessageEvent):
|
||||
url = ev.message.extract_plain_text().removeprefix("/video").strip()
|
||||
if not url:
|
||||
return
|
||||
match = re.match(r"https?:/{2}w.+$", url)
|
||||
if not match:
|
||||
await UniMessage.text("参数不合法").send()
|
||||
return
|
||||
|
||||
timespan = int(time.time())
|
||||
filename = f"{timespan}"
|
||||
file = TEMP_DIR / f"{filename}.mp4"
|
||||
fileabs = str(file)
|
||||
cover = TEMP_DIR / f"{filename}.mp4.jpg"
|
||||
|
||||
TEMP_DIR.mkdir(parents=True, exist_ok=True)
|
||||
try:
|
||||
info = await asyncio.to_thread(get_video_info, url)
|
||||
match = re.search(r"MPEG-4 video(.*)s*Size:(.*)MiB", info)
|
||||
if not match:
|
||||
await UniMessage.text("参数不正确").send()
|
||||
return
|
||||
info_type = match.group(1).strip()
|
||||
if info_type != "(video/mp4)":
|
||||
await UniMessage.text("未找到视频信息").send()
|
||||
return
|
||||
info_size = match.group(2).strip()
|
||||
if not is_number(info_size):
|
||||
await UniMessage.text("无法获取视频大小").send()
|
||||
return
|
||||
size = float(info_size)
|
||||
if size >= 6.0:
|
||||
await UniMessage.text("视频体积过大").send()
|
||||
return
|
||||
await UniMessage.text("正在发送...").send()
|
||||
await asyncio.to_thread(download_video, url, TEMP_DIR, filename)
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
await UniMessage.text("获取视频失败了").send()
|
||||
file.unlink(missing_ok=True)
|
||||
cover.unlink(missing_ok=True)
|
||||
return
|
||||
|
||||
try:
|
||||
await local_video(f"file:///{fileabs}").send()
|
||||
except Exception:
|
||||
await UniMessage.text("发送失败了").send()
|
||||
file.unlink(missing_ok=True)
|
||||
cover.unlink(missing_ok=True)
|
||||
Reference in New Issue
Block a user