mirror of
https://github.com/JefferyHcool/BiliNote.git
synced 2026-07-12 16:11:34 +08:00
Merge branch 'master' into master
This commit is contained in:
@@ -42,4 +42,37 @@ async def sys_health():
|
||||
|
||||
@router.get("/sys_check")
|
||||
async def sys_check():
|
||||
return R.success()
|
||||
return R.success()
|
||||
|
||||
|
||||
@router.get("/deploy_status")
|
||||
async def deploy_status():
|
||||
"""返回部署监控所需的所有状态信息"""
|
||||
import torch
|
||||
import os
|
||||
|
||||
# CUDA 状态
|
||||
cuda_available = torch.cuda.is_available()
|
||||
cuda_info = {
|
||||
"available": cuda_available,
|
||||
"version": torch.version.cuda if cuda_available else None,
|
||||
"gpu_name": torch.cuda.get_device_name(0) if cuda_available else None,
|
||||
}
|
||||
|
||||
# Whisper 模型状态
|
||||
model_size = os.getenv("WHISPER_MODEL_SIZE", "base")
|
||||
transcriber_type = os.getenv("TRANSCRIBER_TYPE", "fast-whisper")
|
||||
|
||||
# FFmpeg 状态
|
||||
try:
|
||||
ensure_ffmpeg_or_raise()
|
||||
ffmpeg_ok = True
|
||||
except:
|
||||
ffmpeg_ok = False
|
||||
|
||||
return R.success(data={
|
||||
"backend": {"status": "running", "port": int(os.getenv("BACKEND_PORT", 8483))},
|
||||
"cuda": cuda_info,
|
||||
"whisper": {"model_size": model_size, "transcriber_type": transcriber_type},
|
||||
"ffmpeg": {"available": ffmpeg_ok},
|
||||
})
|
||||
@@ -1,44 +1,9 @@
|
||||
import re
|
||||
|
||||
|
||||
import re
|
||||
|
||||
import re
|
||||
|
||||
|
||||
def prepend_source_link(markdown: str | None, source_url: str) -> str | None:
|
||||
"""
|
||||
在笔记开头添加来源链接;若首个非空行已包含来源链接,则更新该行并避免重复。
|
||||
"""
|
||||
if markdown is None:
|
||||
return None
|
||||
|
||||
source = (source_url or "").strip()
|
||||
if not source:
|
||||
return markdown
|
||||
|
||||
header = f"> 来源链接:{source}"
|
||||
lines = markdown.splitlines()
|
||||
first_non_empty_idx = None
|
||||
for idx, line in enumerate(lines):
|
||||
if line.strip():
|
||||
first_non_empty_idx = idx
|
||||
break
|
||||
|
||||
if first_non_empty_idx is not None:
|
||||
first_line = lines[first_non_empty_idx].strip()
|
||||
if first_line.startswith("> 来源链接:") or first_line.startswith("来源链接:"):
|
||||
lines[first_non_empty_idx] = header
|
||||
return "\n".join(lines)
|
||||
|
||||
if markdown.strip():
|
||||
return f"{header}\n\n{markdown}"
|
||||
return header
|
||||
|
||||
|
||||
def replace_content_markers(markdown: str, video_id: str, platform: str = 'bilibili') -> str:
|
||||
"""
|
||||
替换 *Content-04:16*、Content-04:16 或 Content-[04:16] 为超链接,跳转到对应平台视频的时间位置
|
||||
替换 *Content-04:16*、Content-04:16 或 Content-[04:16] 为超链接
|
||||
目标格式:- [04:16](https://www.bilibili.com/video/BVxxx?t=256#t=04:16)
|
||||
"""
|
||||
# 匹配三种形式:*Content-04:16*、Content-04:16、Content-[04:16]
|
||||
pattern = r"(?:\*?)Content-(?:\[(\d{2}):(\d{2})\]|(\d{2}):(\d{2}))"
|
||||
@@ -49,18 +14,28 @@ def replace_content_markers(markdown: str, video_id: str, platform: str = 'bilib
|
||||
mm = match.group(1) or match.group(3)
|
||||
ss = match.group(2) or match.group(4)
|
||||
total_seconds = int(mm) * 60 + int(ss)
|
||||
time_str = f"{mm}:{ss}"
|
||||
|
||||
if platform == 'bilibili':
|
||||
parsed_video_id = safe_video_id.replace("_p", "?p=")
|
||||
url = f"https://www.bilibili.com/video/{parsed_video_id}&t={total_seconds}"
|
||||
# 处理多 P 情况,如果是 BV123_p3 转换为 BV123?p=3
|
||||
actual_video_id = video_id.replace("_p", "?p=")
|
||||
|
||||
# 判断连接符是 ? 还是 & (如果 video_id 里已经有了 ?p=,则时间参数用 &t=)
|
||||
connector = "&t=" if "?" in actual_video_id else "?t="
|
||||
|
||||
# 拼接最终 URL,并在末尾加上 #t=MM:SS 锚点
|
||||
url = f"https://www.bilibili.com/video/{actual_video_id}{connector}{total_seconds}#t={time_str}"
|
||||
return f"- [{time_str}]({url})"
|
||||
|
||||
elif platform == 'youtube':
|
||||
url = f"https://www.youtube.com/watch?v={safe_video_id}&t={total_seconds}s"
|
||||
url = f"https://www.youtube.com/watch?v={video_id}&t={total_seconds}s"
|
||||
return f"- [{time_str}]({url})"
|
||||
|
||||
elif platform == 'douyin':
|
||||
url = f"https://www.douyin.com/video/{safe_video_id}"
|
||||
return f"[原片 @ {mm}:{ss}]({url})"
|
||||
url = f"https://www.douyin.com/video/{video_id}"
|
||||
return f"[原片 @ {time_str}]({url})"
|
||||
|
||||
else:
|
||||
return f"({mm}:{ss})"
|
||||
return f"({time_str})"
|
||||
|
||||
return f"[原片 @ {mm}:{ss}]({url})"
|
||||
|
||||
return re.sub(pattern, replacer, markdown)
|
||||
return re.sub(pattern, replacer, markdown)
|
||||
Reference in New Issue
Block a user