diff --git a/mpdscrobble/__init__.py b/mpdscrobble/__init__.py index c2c2d63..1bba22b 100644 --- a/mpdscrobble/__init__.py +++ b/mpdscrobble/__init__.py @@ -5,6 +5,6 @@ A simple Last.fm scrobbler for MPD. """ -__version__ = "0.3.2" +__version__ = "0.3.3" name = "mpdscrobble" diff --git a/mpdscrobble/__main__.py b/mpdscrobble/__main__.py index c349837..aec5fd6 100644 --- a/mpdscrobble/__main__.py +++ b/mpdscrobble/__main__.py @@ -10,6 +10,7 @@ from .utils import ( read_config, create_networks, + get_mpdscrobble_config ) from .mpdscrobble import MPDScrobbleMPDConnection, MPDScrobbleTrack, MPDScrobbleNetwork @@ -28,11 +29,12 @@ def loop( current_song = client.mpdscrobble_currentsong() if current_song and cached_song: logger.debug( - f"Current: {current_song.debug()}\nCached: {cached_song.debug()}" + "Current: %s\nCached: %s", current_song.debug(), cached_song.debug() ) if cached_song != current_song: if cached_song.percentage > constants.SCROBBLE_PERCENTAGE: if not args.dry_run: + logger.info("Sending scrobble for %s.", current_song) networks.mpdscrobble_scrobble(cached_song) else: logger.warning("Dry-run mode enabled.") @@ -40,6 +42,7 @@ def loop( if not current_song and cached_song: if cached_song.percentage > constants.SCROBBLE_PERCENTAGE: if not args.dry_run: + logger.info("Sending scrobble for %s. Detected stopped playback.", current_song) networks.mpdscrobble_scrobble(cached_song) else: logger.warning("Dry-run mode enabled") @@ -58,13 +61,7 @@ def main(): networks = create_networks(config) - host = constants.DEFAULT_HOST - port = constants.DEFAULT_PORT - if "mpdscrobble" in config: - if "host" in config["mpdscrobble"]: - host = config["mpdscrobble"]["host"] - if "port" in config["mpdscrobble"]: - port = config["mpdscrobble"]["port"] + host, port = get_mpdscrobble_config(config) client = MPDScrobbleMPDConnection() client.mpdscrobble_connect(host, port) diff --git a/mpdscrobble/utils.py b/mpdscrobble/utils.py index 58778e3..5e1f92f 100644 --- a/mpdscrobble/utils.py +++ b/mpdscrobble/utils.py @@ -2,6 +2,7 @@ import configparser import os +from mpdscrobble import constants from .mpdscrobble import ( MPDScrobbleLastFMNetwork, MPDScrobbleMalojaNetwork, @@ -19,6 +20,17 @@ def read_config(config_file: str) -> configparser.ConfigParser: return config +def get_mpdscrobble_config(config: configparser.ConfigParser) -> tuple[str, int]: + host = constants.DEFAULT_HOST + port = constants.DEFAULT_PORT + if "mpdscrobble" in config: + if "host" in config["mpdscrobble"]: + host = config["mpdscrobble"]["host"] + if "port" in config["mpdscrobble"]: + port = int(config["mpdscrobble"]["port"]) + return host, port + + def create_networks(config: configparser.ConfigParser) -> MPDScrobbleNetwork: networks = [] for i in config.sections():