M mopidy_multisonic/backend.py +8 -8
@@ 5,10 5,10 @@ from mopidy import backend
logger = logging.getLogger(__name__)
-from .library import Library
-from .playback import Playback
-from .httpclient import HttpClientConfig
-from .uri_parser import root_uri
+from . import library
+from . import playback
+from . import httpclient
+from . import uri_parser
def load_http_client_config(provider):
@@ 20,7 20,7 @@ def load_http_client_config(provider):
password=match.group(4)
url=match.group(5)
- return HttpClientConfig(
+ return httpclient.HttpClientConfig(
name=name,
url=protocol + "://" + url,
username=username,
@@ 40,6 40,6 @@ class MultisonicBackend(pykka.ThreadingA
self.audio = audio
self.http_client_configs = load_http_client_configs(self.config)
- self.library = Library(self)
- self.playback = Playback(audio, self)
- self.uri_schemes = [root_uri]
+ self.library = library.Library(self)
+ self.playback = playback.Playback(audio, self)
+ self.uri_schemes = [uri_parser.root_uri]
M mopidy_multisonic/browser.py +3 -36
@@ 3,6 3,7 @@ from .backend import logger
from . import uri_parser
from . import httpclient
from . import cache
+from . import lookup
top_root_dir = models.Ref.directory(
name="Multisonic",
@@ 135,40 136,6 @@ def browse_artist(http_client_config, ur
return albums
-def build_track_model(song, http_client_config):
- artists = [models.Artist(
- name=song["artist"],
- uri=uri_parser.build_artist(
- str(song["artistId"]),
- http_client_config.name
- )
- )]
- album = models.Album(
- uri=uri_parser.build_album(
- str(song["albumId"]),
- http_client_config.name
- ),
- name=song["album"],
- date=str(song["year"]),
- artists=artists
- )
-
- track = models.Track(
- uri=uri_parser.build_track(
- str(song["id"]),
- http_client_config.name
- ),
- name=song["title"],
- date=str(song["year"]),
- length=song["duration"]*1000,
- disc_no=song["discNumber"],
- track_no=song["track"],
- artists=artists,
- album=album,
- )
-
- return track
-
def build_track_ref(song, http_client_config):
return models.Ref.track(
name=song["title"],
@@ 190,7 157,7 @@ def browse_album(http_client_config, uri
for song in data["album"]["song"]:
tracks.append(build_track_ref(song, http_client_config))
- track = build_track_model(song, http_client_config)
+ track = lookup.build_track_model(song, http_client_config)
cache.hydrate_model(track.uri, [track])
return tracks
@@ 207,7 174,7 @@ def browse_playlist(http_client_config,
for song in data["playlist"]["entry"]:
tracks.append(build_track_ref(song, http_client_config))
- track = build_track_model(song, http_client_config)
+ track = lookup.build_track_model(song, http_client_config)
cache.hydrate_model(track.uri, [track])
return tracks
M mopidy_multisonic/lookup.py +17 -12
@@ 3,21 3,12 @@ from .backend import logger
from . import cache
from . import uri_parser
from . import httpclient
-from .browser import get_http_client_config
+from . import browser
def log_subsonic_error(error):
logger.error("Failed to lookup: " + str(error["code"]) + " : " + error["message"])
-def lookup_track(http_client_config, uri):
- id = uri_parser.get_id(uri)
-
- data = httpclient.get_track(http_client_config, id).json()
- data = data["subsonic-response"]
- if 'failed' == data["status"]:
- log_subsonic_error(data["error"])
- return []
-
- song = data["song"]
+def build_track_model(song, http_client_config):
artists = [models.Artist(
name=song["artist"],
uri=uri_parser.build_artist(
@@ 49,6 40,20 @@ def lookup_track(http_client_config, uri
album=album,
)
+ return track
+
+def lookup_track(http_client_config, uri):
+ id = uri_parser.get_id(uri)
+
+ data = httpclient.get_track(http_client_config, id).json()
+ data = data["subsonic-response"]
+ if 'failed' == data["status"]:
+ log_subsonic_error(data["error"])
+ return []
+
+ song = data["song"]
+ track = build_track_model(song, http_client_config)
+
return [track]
def lookup_album(http_client_config, uri):
@@ 130,7 135,7 @@ def lookup_artist(http_client_config, ur
return tracks
def lookup(http_client_configs, uri):
- http_client_config = get_http_client_config(http_client_configs, uri)
+ http_client_config = browser.get_http_client_config(http_client_configs, uri)
tracks = cache.fetch_model(uri)
if tracks:
M mopidy_multisonic/playback.py +4 -4
@@ 1,7 1,7 @@
from mopidy import backend
from . import uri_parser
-from .httpclient import get_stream
-from .browser import get_http_client_config
+from . import httpclient
+from . import browser
class Playback(backend.PlaybackProvider):
def __init__(self, audio, backend):
@@ 12,7 12,7 @@ class Playback(backend.PlaybackProvider)
return self.backend.http_client_configs
def translate_uri(self, uri):
- http_client_config = get_http_client_config(self.get_http_client_configs(), uri)
+ http_client_config = browser.get_http_client_config(self.get_http_client_configs(), uri)
id = uri_parser.get_id(uri)
- return get_stream(http_client_config, str(id)).url
+ return httpclient.get_stream(http_client_config, str(id)).url