From 23b2d5ae20e356521fb0ecdc01f0e7326943a35e Mon Sep 17 00:00:00 2001 From: Uyanide Date: Thu, 26 Mar 2026 02:32:45 +0100 Subject: [PATCH] fix: URL decoding in local fetcher --- README.md | 2 +- lrcfetch/cli.py | 22 ++++++++++++---------- lrcfetch/fetchers/local.py | 3 ++- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 2902157..9f68cdd 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # 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 diff --git a/lrcfetch/cli.py b/lrcfetch/cli.py index 8d8a3e3..c47a57b 100644 --- a/lrcfetch/cli.py +++ b/lrcfetch/cli.py @@ -18,13 +18,21 @@ app = typer.Typer( manager = LrcManager() +# Global state set by the app callback +_player: Optional[str] = None + @app.callback() def main( 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: enable_debug() + _player = player # ------------------------------------------------------------------ @@ -37,9 +45,6 @@ def fetch( method: Optional[str] = typer.Option( 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( 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.""" - track = get_current_track(player) + track = get_current_track(_player) if not track: logger.error("No active playing track found.") @@ -134,16 +139,13 @@ def export( method: Optional[str] = typer.Option( 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."), overwrite: bool = typer.Option( False, "--overwrite", "-f", help="Overwrite existing file." ), ): """Export lyrics of the current track to a .lrc file.""" - track = get_current_track(player) + track = get_current_track(_player) if not track: logger.error("No active playing track found.") raise typer.Exit(1) @@ -207,7 +209,7 @@ def cache( return if clear_current: - track = get_current_track() + track = get_current_track(_player) if not track: logger.error("No active playing track found.") raise typer.Exit(1) @@ -235,7 +237,7 @@ def cache( return if query: - track = get_current_track() + track = get_current_track(_player) if not track: logger.error("No active playing track found.") raise typer.Exit(1) diff --git a/lrcfetch/fetchers/local.py b/lrcfetch/fetchers/local.py index 6c87ef9..31c34e3 100644 --- a/lrcfetch/fetchers/local.py +++ b/lrcfetch/fetchers/local.py @@ -7,6 +7,7 @@ Priority: import os from typing import Optional +from urllib.parse import unquote from loguru import logger from lrcfetch.models import TrackMeta, LyricResult, CacheStatus from lrcfetch.fetchers.base import BaseFetcher @@ -25,7 +26,7 @@ class LocalFetcher(BaseFetcher): if not track.is_local or not track.url: return None - file_path = track.url.replace("file://", "", 1) + file_path = unquote(track.url.replace("file://", "", 1)) if not os.path.exists(file_path): logger.debug(f"Local: file does not exist: {file_path}") return None