diff --git a/src/mpd_now_playable/mpd/listener.py b/src/mpd_now_playable/mpd/listener.py index bceaaf3..1743bbb 100644 --- a/src/mpd_now_playable/mpd/listener.py +++ b/src/mpd_now_playable/mpd/listener.py @@ -11,7 +11,7 @@ from ..config.model import MpdConfig from ..player import Player from ..song import Artwork, PlaybackState, Song, to_artwork, to_brainz from ..song_receiver import Receiver -from ..tools.types import convert_if_exists, un_maybe_plural +from ..tools.types import option_fmap, un_maybe_plural from .artwork_cache import MpdArtworkCache from .types import CurrentSongResponse, StatusResponse @@ -30,8 +30,8 @@ def mpd_current_to_song( album_artist=un_maybe_plural(current.get("albumartist")), composer=un_maybe_plural(current.get("composer")), genre=un_maybe_plural(current.get("genre")), - track=convert_if_exists(current.get("track"), int), - disc=convert_if_exists(current.get("disc"), int), + track=option_fmap(int, current.get("track")), + disc=option_fmap(int, current.get("disc")), duration=float(status["duration"]), elapsed=float(status["elapsed"]), musicbrainz=to_brainz(current), diff --git a/src/mpd_now_playable/tools/types.py b/src/mpd_now_playable/tools/types.py index da62c90..deb18ad 100644 --- a/src/mpd_now_playable/tools/types.py +++ b/src/mpd_now_playable/tools/types.py @@ -5,7 +5,6 @@ __all__ = ( "AnyExceptList", "MaybePlural", "option_fmap", - "convert_if_exists", "un_maybe_plural", ) @@ -45,12 +44,6 @@ def option_fmap(f: Callable[[U], V], value: U | None) -> V | None: return f(value) -def convert_if_exists(value: str | None, converter: Callable[[str], U]) -> U | None: - if value is None: - return None - return converter(value) - - T = TypeVar("T", bound=AnyExceptList) MaybePlural: TypeAlias = list[T] | T