def encode(self): t = self.original if t.is_loaded(): return { u"id": unicode(Link.from_playlist(t)), u"status": u"", u"name": unicode(t.name(), "utf-8"), u"tracks": [simplify(x) for x in t], } else: return {u"id": u"unknown", u"status": u"", u"name": u"Loading...", u"tracks": []}
def getPlaylistByLink(self, link): """ Pass link as the string representation. This is a bit evil, there's no other way to do this, and if we list other people's playlists we'll need to do even more weird stuff. See http://getsatisfaction.com/spotify/topics/libspotify_does_not_provide_a_sp_link_as_playlist """ for p in self.mgr.ctr: l = str(Link.from_playlist(p)) if l == link: return p log.msg("Cannot find playlist for %s" % link, system="squeal.spot.service.Spotify")
def to_mopidy_playlist(cls, spotify_playlist): if not spotify_playlist.is_loaded(): return Playlist(name=u'[loading...]') # FIXME Replace this try-except with a check on the playlist type, # which is currently not supported by pyspotify, to avoid handling # playlist folder boundaries like normal playlists. try: return Playlist( uri=str(Link.from_playlist(spotify_playlist)), name=spotify_playlist.name().decode(ENCODING), tracks=[cls.to_mopidy_track(t) for t in spotify_playlist], ) except SpotifyError, e: logger.warning(u'Failed translating Spotify playlist ' '(probably a playlist folder boundary): %s', e)
def to_mopidy_playlist(cls, spotify_playlist): if not spotify_playlist.is_loaded(): return Playlist(name=u'[loading...]') if spotify_playlist.type() != 'playlist': return try: return Playlist( uri=str(Link.from_playlist(spotify_playlist)), name=spotify_playlist.name(), # FIXME if check on link is a hackish workaround for is_local tracks=[cls.to_mopidy_track(t) for t in spotify_playlist if str(Link.from_track(t, 0))], ) except SpotifyError, e: logger.warning(u'Failed translating Spotify playlist: %s', e)
def to_mopidy_playlist(cls, spotify_playlist): if not spotify_playlist.is_loaded(): return Playlist(name=u'[loading...]') if spotify_playlist.type() != 'playlist': return try: return Playlist( uri=str(Link.from_playlist(spotify_playlist)), name=spotify_playlist.name(), # FIXME if check on link is a hackish workaround for is_local tracks=[cls.to_mopidy_track(t) for t in spotify_playlist if str(Link.from_track(t, 0))], ) except SpotifyError, e: logger.warning(u'Failed translating Spotify playlist: %s', e)
def to_mopidy_playlist(spotify_playlist): if spotify_playlist is None or spotify_playlist.type() != 'playlist': return uri = str(Link.from_playlist(spotify_playlist)) if not spotify_playlist.is_loaded(): return Playlist(uri=uri, name='[loading...]') if not spotify_playlist.name(): # Other user's "starred" playlists isn't handled properly by pyspotify # See https://github.com/mopidy/pyspotify/issues/81 return return Playlist( uri=uri, name=spotify_playlist.name(), tracks=[ to_mopidy_track(spotify_track) for spotify_track in spotify_playlist if not spotify_track.is_local()])
def to_mopidy_playlist(cls, spotify_playlist): if not spotify_playlist.is_loaded(): return Playlist(name=u'[loading...]') # FIXME Replace this try-except with a check on the playlist type, # which is currently not supported by pyspotify, to avoid handling # playlist folder boundaries like normal playlists. try: return Playlist( uri=str(Link.from_playlist(spotify_playlist)), name=spotify_playlist.name(), # FIXME if check on link is a hackish workaround for is_local tracks=[ cls.to_mopidy_track(t) for t in spotify_playlist if str(Link.from_track(t, 0)) ], ) except SpotifyError, e: logger.info( u'Failed translating Spotify playlist ' '(probably a playlist folder boundary): %s', e)
def to_mopidy_playlist(spotify_playlist): if spotify_playlist is None or spotify_playlist.type() != 'playlist': return uri = str(Link.from_playlist(spotify_playlist)) if not spotify_playlist.is_loaded(): return Playlist(uri=uri, name='[loading...]') name = spotify_playlist.name() if not name: # Other user's "starred" playlists isn't handled properly by pyspotify # See https://github.com/mopidy/pyspotify/issues/81 return if spotify_playlist.owner().canonical_name() != settings.SPOTIFY_USERNAME: name += ' by ' + spotify_playlist.owner().canonical_name() return Playlist( uri=uri, name=name, tracks=[ to_mopidy_track(spotify_track) for spotify_track in spotify_playlist if not spotify_track.is_local()])
def do_list(self, line): """ List the playlists, or the contents of a playlist """ if not line: i = -1 for i, p in enumerate(self.jukebox.ctr): if p.is_loaded(): if Link.from_playlist(p).type() == Link.LINK_STARRED: name = "Starred by %s" % p.owner() else: name = p.name() print "%3d %s" % (i, name) else: print "%3d %s" % (i, "loading...") print "%3d Starred tracks" % (i + 1, ) else: try: p = int(line) except ValueError: print "that's not a number!" return if p < 0 or p > len(self.jukebox.ctr): print "That's out of range!" return print "Listing playlist #%d" % p if p < len(self.jukebox.ctr): playlist = self.jukebox.ctr[p] else: playlist = self.jukebox.starred for i, t in enumerate(playlist): if t.is_loaded(): print "%3d %s - %s [%s]" % ( i, t.artists()[0].name(), t.name(), self.pretty_duration(t.duration())) else: print "%3d %s" % (i, "loading...")
def do_list(self, line): """ List the playlists, or the contents of a playlist """ if not line: i = -1 for i, p in enumerate(self.jukebox.ctr): if p.is_loaded(): if Link.from_playlist(p).type() == Link.LINK_STARRED: name = "Starred by %s" % p.owner() else: name = p.name() print "%3d %s" % (i, name) else: print "%3d %s" % (i, "loading...") print "%3d Starred tracks" % (i + 1,) else: try: p = int(line) except ValueError: print "that's not a number!" return if p < 0 or p > len(self.jukebox.ctr): print "That's out of range!" return print "Listing playlist #%d" % p if p < len(self.jukebox.ctr): playlist = self.jukebox.ctr[p] else: playlist = self.jukebox.starred for i, t in enumerate(playlist): if t.is_loaded(): print "%3d %s - %s [%s]" % ( i, t.artists()[0].name(), t.name(), self.pretty_duration(t.duration())) else: print "%3d %s" % (i, "loading...")
def return_playlist(self): playlist_urn = Link.from_playlist(self.playlist) self.output_queue.put(str(playlist_urn)) self.clear_state() self.change_state(CQSTATE.READY)
def get_playlist(self, pid): for playlist in self.mgr.ctr: if unicode(Link.from_playlist(playlist)) == pid: return playlist
def _to_mopidy_playlist(self, spotify_playlist): return Playlist( uri=str(Link.from_playlist(spotify_playlist)), name=spotify_playlist.name().decode(ENCODING), tracks=[self._to_mopidy_track(t) for t in spotify_playlist], )