From 414b6821230c39ddd6e070a88764ec1d13129e31 Mon Sep 17 00:00:00 2001 From: Andrea Mistrali Date: Mon, 22 Feb 2021 11:19:23 +0100 Subject: [PATCH] Add strip_path to mpdstats --- beetsplug/mpdstats.py | 10 +++++++++- docs/plugins/mpdstats.rst | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/beetsplug/mpdstats.py b/beetsplug/mpdstats.py index 599aa7631..3daa08fe2 100644 --- a/beetsplug/mpdstats.py +++ b/beetsplug/mpdstats.py @@ -53,6 +53,9 @@ class MPDClientWrapper(object): self.music_directory = ( mpd_config['music_directory'].as_str()) + self.strip_path = ( + mpd_config['strip_path'].as_str()) + if sys.version_info < (3, 0): # On Python 2, use_unicode will enable the utf-8 mode for # python-mpd2 @@ -118,12 +121,16 @@ class MPDClientWrapper(object): """Return the path to the currently playing song, along with its songid. Prefixes paths with the music_directory, to get the absolute path. + In some cases, we need to remove the local path from MPD server, + we replace 'strip_path' with ''. + `strip_path` defaults to ''. """ result = None entry = self.get('currentsong') if 'file' in entry: if not is_url(entry['file']): - result = os.path.join(self.music_directory, entry['file']) + file = entry['file'].replace(self.strip_path, '') + result = os.path.join(self.music_directory, file) else: result = entry['file'] return result, entry.get('id') @@ -334,6 +341,7 @@ class MPDStatsPlugin(plugins.BeetsPlugin): super(MPDStatsPlugin, self).__init__() mpd_config.add({ 'music_directory': config['directory'].as_filename(), + 'strip_path': u'', 'rating': True, 'rating_mix': 0.75, 'host': os.environ.get('MPD_HOST', u'localhost'), diff --git a/docs/plugins/mpdstats.rst b/docs/plugins/mpdstats.rst index de9b2ca59..33b3aa43a 100644 --- a/docs/plugins/mpdstats.rst +++ b/docs/plugins/mpdstats.rst @@ -53,6 +53,9 @@ configuration file. The available options are: - **music_directory**: If your MPD library is at a different location from the beets library (e.g., because one is mounted on a NFS share), specify the path here. +- **strip_path**: If your MPD library contains local path, specify the part to remove + here. Combining this with **music_directory** you can mangle MPD path to match the + **beets library** one. Default: The beets library directory. - **rating**: Enable rating updates. Default: ``yes``.