mirror of
https://github.com/JefferyHcool/BiliNote.git
synced 2026-06-19 14:40:12 +08:00
fix: address Copilot review suggestions
- Remove unused Tuple import - Validate /pN suffix p >= 1 - Reuse resolve_bilibili_short_url in fetch_subtitles - Deduplicate short URL resolution
This commit is contained in:
@@ -21,7 +21,7 @@ import requests
|
||||
from app.models.transcriber_model import TranscriptResult, TranscriptSegment
|
||||
from app.services.cookie_manager import CookieConfigManager
|
||||
from app.utils.logger import get_logger
|
||||
from app.utils.url_parser import extract_video_id, extract_bilibili_p_number
|
||||
from app.utils.url_parser import extract_video_id, extract_bilibili_p_number, resolve_bilibili_short_url
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
@@ -126,6 +126,10 @@ class BilibiliSubtitleFetcher:
|
||||
return None
|
||||
|
||||
def fetch_subtitles(self, video_url: str) -> Optional[TranscriptResult]:
|
||||
# 统一 resolve 短链,避免 extract_video_id 和 extract_bilibili_p_number 各 resolve 一次
|
||||
if "b23.tv" in video_url:
|
||||
video_url = resolve_bilibili_short_url(video_url) or video_url
|
||||
|
||||
bvid = extract_video_id(video_url, "bilibili")
|
||||
if not bvid:
|
||||
logger.info("无法从 URL 提取 BV id")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import re
|
||||
from typing import Optional, Tuple
|
||||
from typing import Optional
|
||||
import requests
|
||||
|
||||
|
||||
@@ -76,6 +76,8 @@ def extract_bilibili_p_number(url: str) -> Optional[int]:
|
||||
# 匹配 /pN 尾缀形式(较少见)
|
||||
match = re.search(r'/p(\d+)(?:/?$|\?|&)', url)
|
||||
if match:
|
||||
return int(match.group(1))
|
||||
p_val = int(match.group(1))
|
||||
if p_val >= 1:
|
||||
return p_val
|
||||
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user