mirror of
https://github.com/JefferyHcool/BiliNote.git
synced 2026-05-06 20:42:52 +08:00
feat(frontend): 重构首页布局并添加生成历史组件
- 新增 History 组件用于展示生成历史记录 - 调整 HomeLayout 布局,增加 History 侧边栏 - 优化 NoteHistory 组件样式和布局- 更新首页样式,调整各个组件的位置和样式
This commit is contained in:
@@ -42,7 +42,9 @@ class YoutubeDownloader(Downloader, ABC):
|
||||
title = info.get("title")
|
||||
duration = info.get("duration", 0)
|
||||
cover_url = info.get("thumbnail")
|
||||
audio_path = os.path.join(output_dir, f"{video_id}.m4a")
|
||||
ext = info.get("ext", "m4a") # 兜底用 m4a
|
||||
audio_path = os.path.join(output_dir, f"{video_id}.{ext}")
|
||||
print('os.path.join(output_dir, f"{video_id}.{ext}")',os.path.join(output_dir, f"{video_id}.{ext}"))
|
||||
|
||||
return AudioDownloadResult(
|
||||
file_path=audio_path,
|
||||
|
||||
@@ -40,7 +40,7 @@ def generate_base_prompt(title, segment_text, tags, _format=None, style=None, ex
|
||||
# 添加额外内容
|
||||
if extras:
|
||||
prompt += f"\n{extras}"
|
||||
|
||||
print(prompt)
|
||||
return prompt
|
||||
|
||||
|
||||
|
||||
@@ -41,8 +41,10 @@ from events import transcription_finished
|
||||
|
||||
logger = get_logger(__name__)
|
||||
load_dotenv()
|
||||
BACKEND_BASE_URL = os.getenv("API_BASE_URL", "http://localhost:8000")
|
||||
api_path = os.getenv("API_BASE_URL", "http://localhost")
|
||||
BACKEND_PORT= os.getenv("BACKEND_PORT", 8000)
|
||||
|
||||
BACKEND_BASE_URL = f"{api_path}:{BACKEND_PORT}"
|
||||
output_dir = os.getenv('OUT_DIR')
|
||||
image_base_url = os.getenv('IMAGE_BASE_URL')
|
||||
logger.info("starting up")
|
||||
@@ -129,6 +131,7 @@ class NoteGenerator:
|
||||
"""
|
||||
matches = self.extract_screenshot_timestamps(markdown)
|
||||
new_markdown = markdown
|
||||
print(f"匹配到的截图:{matches}")
|
||||
logger.info(f"开始为笔记生成截图")
|
||||
try:
|
||||
for idx, (marker, ts) in enumerate(matches):
|
||||
@@ -137,6 +140,7 @@ class NoteGenerator:
|
||||
image_url = f"{BACKEND_BASE_URL.rstrip('/')}/{image_relative_path.lstrip('/')}"
|
||||
replacement = f""
|
||||
new_markdown = new_markdown.replace(marker, replacement, 1)
|
||||
print(f"替换后的 markdown:{new_markdown}")
|
||||
|
||||
return new_markdown
|
||||
except Exception as e:
|
||||
@@ -214,7 +218,7 @@ class NoteGenerator:
|
||||
)
|
||||
_path=audio.raw_info.get('path')
|
||||
with open(audio_cache_path, "w", encoding="utf-8") as f:
|
||||
json.dump(audio.__dict__, f, ensure_ascii=False, indent=2)
|
||||
json.dump(asdict(audio), f, ensure_ascii=False, indent=2)
|
||||
logger.info(f"音频下载并缓存成功,task_id={task_id}")
|
||||
except Exception as e:
|
||||
logger.error(f"❌ 下载音频失败,task_id={task_id},错误信息:{e}")
|
||||
@@ -226,13 +230,19 @@ class NoteGenerator:
|
||||
self.update_task_status(task_id, TaskStatus.TRANSCRIBING)
|
||||
if os.path.exists(transcript_cache_path):
|
||||
logger.info(f"检测到已有转写缓存,直接读取,task_id={task_id}")
|
||||
with open(transcript_cache_path, "r", encoding="utf-8") as f:
|
||||
transcript_data = json.load(f)
|
||||
transcript = TranscriptResult(
|
||||
language=transcript_data["language"],
|
||||
full_text=transcript_data["full_text"],
|
||||
segments=[TranscriptSegment(**seg) for seg in transcript_data["segments"]]
|
||||
)
|
||||
try:
|
||||
with open(transcript_cache_path, "r", encoding="utf-8") as f:
|
||||
transcript_data = json.load(f)
|
||||
transcript = TranscriptResult(
|
||||
language=transcript_data["language"],
|
||||
full_text=transcript_data["full_text"],
|
||||
segments=[TranscriptSegment(**seg) for seg in transcript_data["segments"]]
|
||||
)
|
||||
except (json.JSONDecodeError, KeyError) as e:
|
||||
logger.warning(f"⚠️ 读取转录缓存失败,重新转录,task_id={task_id},错误信息:{e}")
|
||||
transcript: TranscriptResult = self.transcriber.transcript(file_path=audio.file_path)
|
||||
with open(transcript_cache_path, "w", encoding="utf-8") as f:
|
||||
json.dump(asdict(transcript), f, ensure_ascii=False, indent=2)
|
||||
else:
|
||||
transcript: TranscriptResult = self.transcriber.transcript(file_path=audio.file_path)
|
||||
with open(transcript_cache_path, "w", encoding="utf-8") as f:
|
||||
|
||||
Reference in New Issue
Block a user