local: Add local/library config value
- Updated library provider to support missing library - Added config value to select local library provider - Updated tests to use library config value
This commit is contained in:
parent
e065f349db
commit
d93d3e6fcd
@ -35,6 +35,11 @@ Configuration values
|
|||||||
|
|
||||||
If the local extension should be enabled or not.
|
If the local extension should be enabled or not.
|
||||||
|
|
||||||
|
.. confval:: local/library
|
||||||
|
|
||||||
|
Local library provider to use, change this if you want to use a third party
|
||||||
|
library for local files.
|
||||||
|
|
||||||
.. confval:: local/media_dir
|
.. confval:: local/media_dir
|
||||||
|
|
||||||
Path to directory with local media files.
|
Path to directory with local media files.
|
||||||
|
|||||||
@ -21,6 +21,7 @@ class Extension(ext.Extension):
|
|||||||
|
|
||||||
def get_config_schema(self):
|
def get_config_schema(self):
|
||||||
schema = super(Extension, self).get_config_schema()
|
schema = super(Extension, self).get_config_schema()
|
||||||
|
schema['library'] = config.String()
|
||||||
schema['media_dir'] = config.Path()
|
schema['media_dir'] = config.Path()
|
||||||
schema['data_dir'] = config.Path()
|
schema['data_dir'] = config.Path()
|
||||||
schema['playlists_dir'] = config.Path()
|
schema['playlists_dir'] = config.Path()
|
||||||
@ -30,9 +31,14 @@ class Extension(ext.Extension):
|
|||||||
schema['excluded_file_extensions'] = config.List(optional=True)
|
schema['excluded_file_extensions'] = config.List(optional=True)
|
||||||
return schema
|
return schema
|
||||||
|
|
||||||
def get_backend_classes(self):
|
def setup(self, registry):
|
||||||
from .actor import LocalBackend
|
from .actor import LocalBackend
|
||||||
return [LocalBackend]
|
from .json import JsonLibrary
|
||||||
|
|
||||||
|
LocalBackend.libraries = registry['local:library']
|
||||||
|
|
||||||
|
registry.add('backend', LocalBackend)
|
||||||
|
registry.add('local:library', JsonLibrary)
|
||||||
|
|
||||||
def get_command(self):
|
def get_command(self):
|
||||||
from .commands import LocalCommand
|
from .commands import LocalCommand
|
||||||
|
|||||||
@ -8,7 +8,6 @@ import pykka
|
|||||||
from mopidy.backends import base
|
from mopidy.backends import base
|
||||||
from mopidy.utils import encoding, path
|
from mopidy.utils import encoding, path
|
||||||
|
|
||||||
from .json import JsonLibrary
|
|
||||||
from .library import LocalLibraryProvider
|
from .library import LocalLibraryProvider
|
||||||
from .playback import LocalPlaybackProvider
|
from .playback import LocalPlaybackProvider
|
||||||
from .playlists import LocalPlaylistsProvider
|
from .playlists import LocalPlaylistsProvider
|
||||||
@ -18,6 +17,7 @@ logger = logging.getLogger('mopidy.backends.local')
|
|||||||
|
|
||||||
class LocalBackend(pykka.ThreadingActor, base.Backend):
|
class LocalBackend(pykka.ThreadingActor, base.Backend):
|
||||||
uri_schemes = ['local']
|
uri_schemes = ['local']
|
||||||
|
libraries = []
|
||||||
|
|
||||||
def __init__(self, config, audio):
|
def __init__(self, config, audio):
|
||||||
super(LocalBackend, self).__init__()
|
super(LocalBackend, self).__init__()
|
||||||
@ -26,8 +26,15 @@ class LocalBackend(pykka.ThreadingActor, base.Backend):
|
|||||||
|
|
||||||
self.check_dirs_and_files()
|
self.check_dirs_and_files()
|
||||||
|
|
||||||
# TODO: move to getting this from registry
|
libraries = dict((l.name, l) for l in self.libraries)
|
||||||
library = JsonLibrary(config)
|
library_name = config['local']['library']
|
||||||
|
|
||||||
|
if library_name in libraries:
|
||||||
|
library = libraries[library_name](config)
|
||||||
|
logger.debug('Using %s as the local library', library_name)
|
||||||
|
else:
|
||||||
|
library = None
|
||||||
|
logger.warning('Local library %s not found', library_name)
|
||||||
|
|
||||||
self.playback = LocalPlaybackProvider(audio=audio, backend=self)
|
self.playback = LocalPlaybackProvider(audio=audio, backend=self)
|
||||||
self.playlists = LocalPlaylistsProvider(backend=self)
|
self.playlists = LocalPlaylistsProvider(backend=self)
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
[local]
|
[local]
|
||||||
enabled = true
|
enabled = true
|
||||||
|
library = json
|
||||||
media_dir = $XDG_MUSIC_DIR
|
media_dir = $XDG_MUSIC_DIR
|
||||||
data_dir = $XDG_DATA_DIR/mopidy/local
|
data_dir = $XDG_DATA_DIR/mopidy/local
|
||||||
playlists_dir = $XDG_DATA_DIR/mopidy/local/playlists
|
playlists_dir = $XDG_DATA_DIR/mopidy/local/playlists
|
||||||
|
|||||||
@ -15,15 +15,23 @@ class LocalLibraryProvider(base.BaseLibraryProvider):
|
|||||||
self.refresh()
|
self.refresh()
|
||||||
|
|
||||||
def refresh(self, uri=None):
|
def refresh(self, uri=None):
|
||||||
|
if not self._library:
|
||||||
|
return 0
|
||||||
num_tracks = self._library.load()
|
num_tracks = self._library.load()
|
||||||
logger.info('Loaded %d local tracks using %s',
|
logger.info('Loaded %d local tracks using %s',
|
||||||
num_tracks, self._library.name)
|
num_tracks, self._library.name)
|
||||||
|
|
||||||
def lookup(self, uri):
|
def lookup(self, uri):
|
||||||
|
if not self._library:
|
||||||
|
return []
|
||||||
return self._library.lookup(uri)
|
return self._library.lookup(uri)
|
||||||
|
|
||||||
def find_exact(self, query=None, uris=None):
|
def find_exact(self, query=None, uris=None):
|
||||||
|
if not self._library:
|
||||||
|
return None
|
||||||
return self._library.search(query=query, uris=uris, exact=True)
|
return self._library.search(query=query, uris=uris, exact=True)
|
||||||
|
|
||||||
def search(self, query=None, uris=None):
|
def search(self, query=None, uris=None):
|
||||||
|
if not self._library:
|
||||||
|
return None
|
||||||
return self._library.search(query=query, uris=uris, exact=False)
|
return self._library.search(query=query, uris=uris, exact=False)
|
||||||
|
|||||||
@ -69,9 +69,6 @@ class Extension(object):
|
|||||||
for frontend_class in self.get_frontend_classes():
|
for frontend_class in self.get_frontend_classes():
|
||||||
registry.add('frontend', frontend_class)
|
registry.add('frontend', frontend_class)
|
||||||
|
|
||||||
for library_updater in self.get_library_updaters():
|
|
||||||
registry.add('local:library', library_updater)
|
|
||||||
|
|
||||||
self.register_gstreamer_elements()
|
self.register_gstreamer_elements()
|
||||||
|
|
||||||
def get_frontend_classes(self):
|
def get_frontend_classes(self):
|
||||||
@ -92,6 +89,7 @@ class Extension(object):
|
|||||||
"""
|
"""
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
# TODO: remove
|
||||||
def get_library_updaters(self):
|
def get_library_updaters(self):
|
||||||
"""List of library updater classes
|
"""List of library updater classes
|
||||||
|
|
||||||
|
|||||||
@ -19,6 +19,7 @@ class LocalBackendEventsTest(unittest.TestCase):
|
|||||||
'media_dir': path_to_data_dir(''),
|
'media_dir': path_to_data_dir(''),
|
||||||
'data_dir': path_to_data_dir(''),
|
'data_dir': path_to_data_dir(''),
|
||||||
'playlists_dir': b'',
|
'playlists_dir': b'',
|
||||||
|
'library': 'json',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import unittest
|
|||||||
import pykka
|
import pykka
|
||||||
|
|
||||||
from mopidy import core
|
from mopidy import core
|
||||||
from mopidy.backends.local import actor
|
from mopidy.backends.local import actor, json
|
||||||
from mopidy.models import Track, Album, Artist
|
from mopidy.models import Track, Album, Artist
|
||||||
|
|
||||||
from tests import path_to_data_dir
|
from tests import path_to_data_dir
|
||||||
@ -63,10 +63,12 @@ class LocalLibraryProviderTest(unittest.TestCase):
|
|||||||
'media_dir': path_to_data_dir(''),
|
'media_dir': path_to_data_dir(''),
|
||||||
'data_dir': path_to_data_dir(''),
|
'data_dir': path_to_data_dir(''),
|
||||||
'playlists_dir': b'',
|
'playlists_dir': b'',
|
||||||
|
'library': 'json',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
actor.LocalBackend.libraries = [json.JsonLibrary]
|
||||||
self.backend = actor.LocalBackend.start(
|
self.backend = actor.LocalBackend.start(
|
||||||
config=self.config, audio=None).proxy()
|
config=self.config, audio=None).proxy()
|
||||||
self.core = core.Core(backends=[self.backend])
|
self.core = core.Core(backends=[self.backend])
|
||||||
@ -74,6 +76,7 @@ class LocalLibraryProviderTest(unittest.TestCase):
|
|||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
pykka.ActorRegistry.stop_all()
|
pykka.ActorRegistry.stop_all()
|
||||||
|
actor.LocalBackend.libraries = []
|
||||||
|
|
||||||
def test_refresh(self):
|
def test_refresh(self):
|
||||||
self.library.refresh()
|
self.library.refresh()
|
||||||
|
|||||||
@ -24,6 +24,7 @@ class LocalPlaybackProviderTest(unittest.TestCase):
|
|||||||
'media_dir': path_to_data_dir(''),
|
'media_dir': path_to_data_dir(''),
|
||||||
'data_dir': path_to_data_dir(''),
|
'data_dir': path_to_data_dir(''),
|
||||||
'playlists_dir': b'',
|
'playlists_dir': b'',
|
||||||
|
'library': 'json',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -21,6 +21,7 @@ class LocalPlaylistsProviderTest(unittest.TestCase):
|
|||||||
'local': {
|
'local': {
|
||||||
'media_dir': path_to_data_dir(''),
|
'media_dir': path_to_data_dir(''),
|
||||||
'data_dir': path_to_data_dir(''),
|
'data_dir': path_to_data_dir(''),
|
||||||
|
'library': 'json',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,6 +20,7 @@ class LocalTracklistProviderTest(unittest.TestCase):
|
|||||||
'media_dir': path_to_data_dir(''),
|
'media_dir': path_to_data_dir(''),
|
||||||
'data_dir': path_to_data_dir(''),
|
'data_dir': path_to_data_dir(''),
|
||||||
'playlists_dir': b'',
|
'playlists_dir': b'',
|
||||||
|
'library': 'json',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tracks = [
|
tracks = [
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user