mirror of
https://github.com/beetbox/beets.git
synced 2025-12-24 09:33:46 +01:00
commit
e9b930b7e2
3 changed files with 23 additions and 3 deletions
|
|
@ -50,8 +50,15 @@ class MPDClientWrapper(object):
|
|||
def __init__(self, log):
|
||||
self._log = log
|
||||
|
||||
self.music_directory = (
|
||||
mpd_config['music_directory'].as_str())
|
||||
self.music_directory = mpd_config['music_directory'].as_str()
|
||||
self.strip_path = mpd_config['strip_path'].as_str()
|
||||
|
||||
# Ensure strip_path end with '/'
|
||||
if not self.strip_path.endswith('/'):
|
||||
self.strip_path += '/'
|
||||
|
||||
self._log.debug('music_directory: {0}', self.music_directory)
|
||||
self._log.debug('strip_path: {0}', self.strip_path)
|
||||
|
||||
if sys.version_info < (3, 0):
|
||||
# On Python 2, use_unicode will enable the utf-8 mode for
|
||||
|
|
@ -118,14 +125,21 @@ 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']
|
||||
if file.startswith(self.strip_path):
|
||||
file = file[len(self.strip_path):]
|
||||
result = os.path.join(self.music_directory, file)
|
||||
else:
|
||||
result = entry['file']
|
||||
self._log.debug('returning: {0}', result)
|
||||
return result, entry.get('id')
|
||||
|
||||
def status(self):
|
||||
|
|
@ -334,6 +348,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'),
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ Changelog
|
|||
|
||||
New features:
|
||||
|
||||
* :doc:`/plugins/mpdstats`: Add strip_path option to help build the right local path
|
||||
from MPD information
|
||||
* Submitting acoustID information on tracks which already have a fingerprint
|
||||
:bug:`3834`
|
||||
* conversion uses par_map to parallelize conversion jobs in python3
|
||||
|
|
|
|||
|
|
@ -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``.
|
||||
|
|
|
|||
Loading…
Reference in a new issue