def getitem(sp_search, key): return spotify.SearchPlaylist( name=utils.to_unicode( lib.sp_search_playlist_name(self._sp_search, key)), uri=utils.to_unicode( lib.sp_search_playlist_uri(self._sp_search, key)), image_uri=utils.to_unicode( lib.sp_search_playlist_image_uri(self._sp_search, key)))
def getitem(sp_search, key): return spotify.SearchPlaylist( self._session, name=utils.to_unicode( lib.sp_search_playlist_name(self._sp_search, key)), uri=utils.to_unicode( lib.sp_search_playlist_uri(self._sp_search, key)), image_uri=utils.to_unicode( lib.sp_search_playlist_image_uri(self._sp_search, key)))
def log_message(sp_session, data): if not spotify._session_instance: return data = utils.to_unicode(data).strip() logger.debug('libspotify log message: %s', data) spotify._session_instance.emit( SessionEvent.LOG_MESSAGE, spotify._session_instance, data)
def track_message_changed(sp_playlist, index, message, userdata): logger.debug('Playlist track message changed') playlist = Playlist._cached(spotify._session_instance, sp_playlist, add_ref=True) playlist.emit(PlaylistEvent.TRACK_MESSAGE_CHANGED, playlist, int(index), utils.to_unicode(message))
def description_changed(sp_playlist, desc, userdata): logger.debug('Playlist description changed') playlist = Playlist._cached( spotify._session_instance, sp_playlist, add_ref=True) playlist.emit( PlaylistEvent.DESCRIPTION_CHANGED, playlist, utils.to_unicode(desc))
def biography(self): """A biography of the artist. Will always return an empty string if the artist browser isn't loaded. """ return utils.to_unicode( lib.sp_artistbrowse_biography(self._sp_artistbrowse))
def message_to_user(sp_session, data): if not spotify._session_instance: return data = utils.to_unicode(data).strip() logger.debug('Message to user: %s', data) spotify._session_instance.emit( SessionEvent.MESSAGE_TO_USER, spotify._session_instance, data)
def track_message_changed(sp_playlist, index, message, userdata): logger.debug('Playlist track message changed') playlist = Playlist._cached( spotify._session_instance, sp_playlist, add_ref=True) playlist.emit( PlaylistEvent.TRACK_MESSAGE_CHANGED, playlist, int(index), utils.to_unicode(message))
def description_changed(sp_playlist, desc, userdata): logger.debug('Playlist description changed') playlist = Playlist._cached(spotify._session_instance, sp_playlist, add_ref=True) playlist.emit(PlaylistEvent.DESCRIPTION_CHANGED, playlist, utils.to_unicode(desc))
def message_to_user(sp_session, data): if not spotify._session_instance: return data = utils.to_unicode(data).strip() logger.debug('Message to user: %s', data) spotify._session_instance.emit(SessionEvent.MESSAGE_TO_USER, spotify._session_instance, data)
def log_message(sp_session, data): if not spotify._session_instance: return data = utils.to_unicode(data).strip() logger.debug('libspotify log message: %s', data) spotify._session_instance.emit(SessionEvent.LOG_MESSAGE, spotify._session_instance, data)
def review(self): """A review of the album. Will always return an empty string if the album browser isn't loaded. """ return utils.to_unicode( lib.sp_albumbrowse_review(self._sp_albumbrowse))
def name(self): """The album's name. Will always return :class:`None` if the album isn't loaded. """ name = utils.to_unicode(lib.sp_album_name(self._sp_album)) return name if name else None
def name(self): """The artist's name. Will always return :class:`None` if the artist isn't loaded. """ name = utils.to_unicode(lib.sp_artist_name(self._sp_artist)) return name if name else None
def review(self): """A review of the album. Will always return an empty string if the album browser isn't loaded. """ return utils.to_unicode(lib.sp_albumbrowse_review( self._sp_albumbrowse))
def query(self): """The search query. Will always return :class:`None` if the search isn't loaded. """ spotify.Error.maybe_raise(self.error) query = utils.to_unicode(lib.sp_search_query(self._sp_search)) return query if query else None
def get_libspotify_build_id(): """Get the build ID of the wrapped libspotify library. >>> import spotify >>> spotify.get_libspotify_build_id() u'12.1.51.g86c92b43 Release Linux-x86_64 ' """ return utils.to_unicode(lib.sp_build_id())
def name(self): """The track's name. Will always return :class:`None` if the track isn't loaded. """ spotify.Error.maybe_raise(self.error) name = utils.to_unicode(lib.sp_track_name(self._sp_track)) return name if name else None
def proxy(self): """URL to the proxy server that should be used. Defaults to :class:`None`. The format is protocol://host:port where protocol is http/https/socks4/socks5. """ return utils.to_unicode(self._sp_session_config.proxy) or None
def name(self): """The playlist's name. Assigning to :attr:`name` will rename the playlist. Will always return :class:`None` if the playlist isn't loaded. """ name = utils.to_unicode(lib.sp_playlist_name(self._sp_playlist)) return name if name else None
def did_you_mean(self): """The search's "did you mean" query or :class:`None` if no such suggestion exists. Will always return :class:`None` if the search isn't loaded. """ spotify.Error.maybe_raise(self.error) did_you_mean = utils.to_unicode( lib.sp_search_did_you_mean(self._sp_search)) return did_you_mean if did_you_mean else None
def name(self): """The track's name. Will always return :class:`None` if the track isn't loaded. """ spotify.Error.maybe_raise(self.error, ignores=[spotify.ErrorType.IS_LOADING]) if not self.is_loaded: return None return utils.to_unicode(lib.sp_track_name(self._sp_track))
def name(self): """The track's name. Will always return :class:`None` if the track isn't loaded. """ spotify.Error.maybe_raise( self.error, ignores=[spotify.ErrorType.IS_LOADING]) if not self.is_loaded: return None return utils.to_unicode(lib.sp_track_name(self._sp_track))
def subscribers(self): """The canonical usernames of up to 500 of the subscribers of the playlist. May be empty until you call :meth:`update_subscribers` and the :attr:`~PlaylistEvent.SUBSCRIBERS_CHANGED` event is emitted from the playlist. """ sp_subscribers = ffi.gc(lib.sp_playlist_subscribers(self._sp_playlist), lib.sp_playlist_subscribers_free) # The ``subscribers`` field is ``char *[1]`` according to the struct, # so we must cast it to ``char **`` to be able to access more than the # first subscriber. subscribers = ffi.cast('char **', sp_subscribers.subscribers) usernames = [] for i in range(sp_subscribers.count): usernames.append(utils.to_unicode(subscribers[i])) return usernames
def subscribers(self): """The canonical usernames of up to 500 of the subscribers of the playlist. May be empty until you call :meth:`update_subscribers` and the :attr:`~PlaylistEvent.SUBSCRIBERS_CHANGED` event is emitted from the playlist. """ sp_subscribers = ffi.gc( lib.sp_playlist_subscribers(self._sp_playlist), lib.sp_playlist_subscribers_free) # The ``subscribers`` field is ``char *[1]`` according to the struct, # so we must cast it to ``char **`` to be able to access more than the # first subscriber. subscribers = ffi.cast('char **', sp_subscribers.subscribers) usernames = [] for i in range(sp_subscribers.count): usernames.append(utils.to_unicode(subscribers[i])) return usernames
def display_name(self): """The user's displayable username.""" return utils.to_unicode(lib.sp_user_display_name(self._sp_user))
def get_copyright(sp_albumbrowse, key): return utils.to_unicode( lib.sp_albumbrowse_copyright(sp_albumbrowse, key))
def __init__(self, error_type): self.error_type = error_type message = utils.to_unicode(lib.sp_error_message(error_type)) super(Error, self).__init__(message)
def canonical_name(self): """The user's canonical username.""" return utils.to_unicode(lib.sp_user_canonical_name(self._sp_user))
def user_agent(self): """A string with the name of your client. Defaults to ``pyspotify 2.x.y``. """ return utils.to_unicode(self._sp_session_config.user_agent)
def user_name(self): """The username of the logged in user.""" return utils.to_unicode(lib.sp_session_user_name(self._sp_session))
def proxy_password(self): """Password to authenticate with proxy server. Defaults to :class:`None`. """ return utils.to_unicode(self._sp_session_config.proxy_password) or None
def proxy_username(self): """Username to authenticate with proxy server. Defaults to :class:`None`. """ return utils.to_unicode(self._sp_session_config.proxy_username) or None
def test_cdata_to_unicode_is_unwrapped_and_decoded_as_utf8(self): cdata = spotify.ffi.new('char[]', 'æøå'.encode('utf-8')) self.assertEqual(utils.to_unicode(cdata), 'æøå')
def test_anything_else_to_unicode_fails(self): with self.assertRaises(ValueError): utils.to_unicode([]) with self.assertRaises(ValueError): utils.to_unicode(123)
def test_unicode_to_unicode_is_passed_through(self): self.assertEqual(utils.to_unicode('æøå'), 'æøå')
def test_bytes_to_unicode_is_decoded_as_utf8(self): self.assertEqual(utils.to_unicode('æøå'.encode('utf-8')), 'æøå')