Use spotify_uri_to_int in LibspotifyTranslator and DespotifyTranslator, making both stateless
This commit is contained in:
parent
e27438bcec
commit
b734948dcb
@ -8,6 +8,7 @@ from mopidy.backends import (BaseBackend, BaseCurrentPlaylistController,
|
|||||||
BaseLibraryController, BasePlaybackController,
|
BaseLibraryController, BasePlaybackController,
|
||||||
BaseStoredPlaylistsController)
|
BaseStoredPlaylistsController)
|
||||||
from mopidy.models import Artist, Album, Track, Playlist
|
from mopidy.models import Artist, Album, Track, Playlist
|
||||||
|
from mopidy.utils import spotify_uri_to_int
|
||||||
|
|
||||||
logger = logging.getLogger('mopidy.backends.despotify')
|
logger = logging.getLogger('mopidy.backends.despotify')
|
||||||
|
|
||||||
@ -114,15 +115,8 @@ class DespotifyStoredPlaylistsController(BaseStoredPlaylistsController):
|
|||||||
|
|
||||||
|
|
||||||
class DespotifyTranslator(object):
|
class DespotifyTranslator(object):
|
||||||
uri_to_id_map = {}
|
|
||||||
next_id = 0
|
|
||||||
|
|
||||||
def to_mopidy_id(self, spotify_uri):
|
def to_mopidy_id(self, spotify_uri):
|
||||||
if spotify_uri not in self.uri_to_id_map:
|
return spotify_uri_to_int(spotify_uri)
|
||||||
this_id = self.next_id
|
|
||||||
self.next_id += 1
|
|
||||||
self.uri_to_id_map[spotify_uri] = this_id
|
|
||||||
return self.uri_to_id_map[spotify_uri]
|
|
||||||
|
|
||||||
def to_mopidy_artist(self, spotify_artist):
|
def to_mopidy_artist(self, spotify_artist):
|
||||||
return Artist(
|
return Artist(
|
||||||
|
|||||||
@ -12,6 +12,7 @@ from mopidy.backends import (BaseBackend, BaseCurrentPlaylistController,
|
|||||||
BaseLibraryController, BasePlaybackController,
|
BaseLibraryController, BasePlaybackController,
|
||||||
BaseStoredPlaylistsController)
|
BaseStoredPlaylistsController)
|
||||||
from mopidy.models import Artist, Album, Track, Playlist
|
from mopidy.models import Artist, Album, Track, Playlist
|
||||||
|
from mopidy.utils import spotify_uri_to_int
|
||||||
|
|
||||||
logger = logging.getLogger('mopidy.backends.libspotify')
|
logger = logging.getLogger('mopidy.backends.libspotify')
|
||||||
|
|
||||||
@ -107,15 +108,8 @@ class LibspotifyStoredPlaylistsController(BaseStoredPlaylistsController):
|
|||||||
|
|
||||||
|
|
||||||
class LibspotifyTranslator(object):
|
class LibspotifyTranslator(object):
|
||||||
uri_to_id_map = {}
|
|
||||||
next_id = 0
|
|
||||||
|
|
||||||
def to_mopidy_id(self, spotify_uri):
|
def to_mopidy_id(self, spotify_uri):
|
||||||
if spotify_uri not in self.uri_to_id_map:
|
return spotify_uri_to_int(spotify_uri)
|
||||||
this_id = self.next_id
|
|
||||||
self.next_id += 1
|
|
||||||
self.uri_to_id_map[spotify_uri] = this_id
|
|
||||||
return self.uri_to_id_map[spotify_uri]
|
|
||||||
|
|
||||||
def to_mopidy_artist(self, spotify_artist):
|
def to_mopidy_artist(self, spotify_artist):
|
||||||
if not spotify_artist.is_loaded():
|
if not spotify_artist.is_loaded():
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user