fix: URL decoding in local fetcher

This commit is contained in:
2026-03-26 02:32:45 +01:00
parent ec40fbcf13
commit 23b2d5ae20
3 changed files with 15 additions and 12 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
# lrcfetch # lrcfetch
A CLI tool for fetching LRC lyrics on Linux. Automatically detects the currently playing track via MPRIS/DBus and retrieves synced or plain lyrics from multiple sources. A CLI tool for fetching LRC lyrics on Linux. Automatically detects the currently playing track via MPRIS/DBus and retrieves synced (or plain with all time tags set to `[00:00.00]` if failed to find any synced) lyrics from multiple sources.
## Sources ## Sources
+12 -10
View File
@@ -18,13 +18,21 @@ app = typer.Typer(
manager = LrcManager() manager = LrcManager()
# Global state set by the app callback
_player: Optional[str] = None
@app.callback() @app.callback()
def main( def main(
debug: bool = typer.Option(False, "--debug", "-d", help="Enable debug logging."), debug: bool = typer.Option(False, "--debug", "-d", help="Enable debug logging."),
player: Optional[str] = typer.Option(
None, "--player", "-p", help="Target a specific MPRIS player using its DBus name or a portion thereof."
),
): ):
global _player
if debug: if debug:
enable_debug() enable_debug()
_player = player
# ------------------------------------------------------------------ # ------------------------------------------------------------------
@@ -37,9 +45,6 @@ def fetch(
method: Optional[str] = typer.Option( method: Optional[str] = typer.Option(
None, "--method", help="Force a specific source (local, spotify, lrclib, lrclib-search, netease)." None, "--method", help="Force a specific source (local, spotify, lrclib, lrclib-search, netease)."
), ),
player: Optional[str] = typer.Option(
None, "--player", "-p", help="Target a specific MPRIS player."
),
no_cache: bool = typer.Option( no_cache: bool = typer.Option(
False, "--no-cache", help="Bypass the cache for this request." False, "--no-cache", help="Bypass the cache for this request."
), ),
@@ -48,7 +53,7 @@ def fetch(
), ),
): ):
"""Fetch and print lyrics for the currently playing track.""" """Fetch and print lyrics for the currently playing track."""
track = get_current_track(player) track = get_current_track(_player)
if not track: if not track:
logger.error("No active playing track found.") logger.error("No active playing track found.")
@@ -134,16 +139,13 @@ def export(
method: Optional[str] = typer.Option( method: Optional[str] = typer.Option(
None, "--method", help="Force a specific source." None, "--method", help="Force a specific source."
), ),
player: Optional[str] = typer.Option(
None, "--player", "-p", help="Target a specific MPRIS player."
),
no_cache: bool = typer.Option(False, "--no-cache", help="Bypass cache."), no_cache: bool = typer.Option(False, "--no-cache", help="Bypass cache."),
overwrite: bool = typer.Option( overwrite: bool = typer.Option(
False, "--overwrite", "-f", help="Overwrite existing file." False, "--overwrite", "-f", help="Overwrite existing file."
), ),
): ):
"""Export lyrics of the current track to a .lrc file.""" """Export lyrics of the current track to a .lrc file."""
track = get_current_track(player) track = get_current_track(_player)
if not track: if not track:
logger.error("No active playing track found.") logger.error("No active playing track found.")
raise typer.Exit(1) raise typer.Exit(1)
@@ -207,7 +209,7 @@ def cache(
return return
if clear_current: if clear_current:
track = get_current_track() track = get_current_track(_player)
if not track: if not track:
logger.error("No active playing track found.") logger.error("No active playing track found.")
raise typer.Exit(1) raise typer.Exit(1)
@@ -235,7 +237,7 @@ def cache(
return return
if query: if query:
track = get_current_track() track = get_current_track(_player)
if not track: if not track:
logger.error("No active playing track found.") logger.error("No active playing track found.")
raise typer.Exit(1) raise typer.Exit(1)
+2 -1
View File
@@ -7,6 +7,7 @@ Priority:
import os import os
from typing import Optional from typing import Optional
from urllib.parse import unquote
from loguru import logger from loguru import logger
from lrcfetch.models import TrackMeta, LyricResult, CacheStatus from lrcfetch.models import TrackMeta, LyricResult, CacheStatus
from lrcfetch.fetchers.base import BaseFetcher from lrcfetch.fetchers.base import BaseFetcher
@@ -25,7 +26,7 @@ class LocalFetcher(BaseFetcher):
if not track.is_local or not track.url: if not track.is_local or not track.url:
return None return None
file_path = track.url.replace("file://", "", 1) file_path = unquote(track.url.replace("file://", "", 1))
if not os.path.exists(file_path): if not os.path.exists(file_path):
logger.debug(f"Local: file does not exist: {file_path}") logger.debug(f"Local: file does not exist: {file_path}")
return None return None