fix: normalize time tags in fetched lrc (why [00:17:06]?)

This commit is contained in:
2026-03-25 11:16:03 +01:00
parent 6e50352934
commit b9fa6c6705
4 changed files with 65 additions and 57 deletions
+3 -22
View File
@@ -5,34 +5,15 @@ Priority:
2. Embedded lyrics in audio metadata (FLAC, MP3 USLT/SYLT tags)
"""
import re
import os
from typing import Optional
from loguru import logger
from lrcfetch.models import TrackMeta, LyricResult, CacheStatus
from lrcfetch.fetchers.base import BaseFetcher
from lrcfetch.lrc import detect_sync_status
from mutagen._file import File
from mutagen.flac import FLAC
# Matches LRC time tags like [00:12.34] or [01:23.456]
_LRC_TIME_TAG_RE = re.compile(r"\[\d{2}:\d{2}\.\d{2,3}\]")
# Matches time tags that are all zeros
_ZERO_TIME_TAG_RE = re.compile(r"^\[00:00\.0{2,3}\]$")
def _detect_sync_status(text: str) -> CacheStatus:
"""Determine whether lyrics text contains meaningful LRC time tags.
Returns UNSYNCED if no tags exist or all tags are [00:00.00].
"""
tags = _LRC_TIME_TAG_RE.findall(text)
if not tags:
return CacheStatus.SUCCESS_UNSYNCED
for tag in tags:
if not _ZERO_TIME_TAG_RE.match(tag):
return CacheStatus.SUCCESS_SYNCED
return CacheStatus.SUCCESS_UNSYNCED
class LocalFetcher(BaseFetcher):
@property
@@ -58,7 +39,7 @@ class LocalFetcher(BaseFetcher):
with open(lrc_path, "r", encoding="utf-8") as f:
content = f.read().strip()
if content:
status = _detect_sync_status(content)
status = detect_sync_status(content)
logger.info(f"Local: found .lrc sidecar ({status.value})")
return LyricResult(
status=status, lyrics=content, source=self.source_name
@@ -83,7 +64,7 @@ class LocalFetcher(BaseFetcher):
break
if lyrics:
status = _detect_sync_status(lyrics)
status = detect_sync_status(lyrics)
logger.info(f"Local: found embedded lyrics ({status.value})")
return LyricResult(
status=status,