Пример #1
0
 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)))
Пример #2
0
 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)))
Пример #3
0
 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)
Пример #4
0
 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))
Пример #5
0
 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))
Пример #6
0
    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))
Пример #7
0
 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)
Пример #8
0
 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))
Пример #9
0
 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))
Пример #10
0
 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)
Пример #11
0
 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)
Пример #12
0
    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))
Пример #13
0
    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))
Пример #14
0
    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
Пример #15
0
    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
Пример #16
0
    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))
Пример #17
0
    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
Пример #18
0
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())
Пример #19
0
    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
Пример #20
0
    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
Пример #21
0
    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
Пример #22
0
    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
Пример #23
0
    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
Пример #24
0
    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
Пример #25
0
    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))
Пример #26
0
    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))
Пример #27
0
    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
Пример #28
0
    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
Пример #29
0
    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
Пример #30
0
 def display_name(self):
     """The user's displayable username."""
     return utils.to_unicode(lib.sp_user_display_name(self._sp_user))
Пример #31
0
 def get_copyright(sp_albumbrowse, key):
     return utils.to_unicode(
         lib.sp_albumbrowse_copyright(sp_albumbrowse, key))
Пример #32
0
 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)
Пример #33
0
 def canonical_name(self):
     """The user's canonical username."""
     return utils.to_unicode(lib.sp_user_canonical_name(self._sp_user))
Пример #34
0
 def get_copyright(sp_albumbrowse, key):
     return utils.to_unicode(
         lib.sp_albumbrowse_copyright(sp_albumbrowse, key))
Пример #35
0
    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)
Пример #36
0
 def user_name(self):
     """The username of the logged in user."""
     return utils.to_unicode(lib.sp_session_user_name(self._sp_session))
Пример #37
0
    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
Пример #38
0
 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)
Пример #39
0
    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
Пример #40
0
 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), 'æøå')
Пример #41
0
 def canonical_name(self):
     """The user's canonical username."""
     return utils.to_unicode(lib.sp_user_canonical_name(self._sp_user))
Пример #42
0
    def test_anything_else_to_unicode_fails(self):
        with self.assertRaises(ValueError):
            utils.to_unicode([])

        with self.assertRaises(ValueError):
            utils.to_unicode(123)
Пример #43
0
 def test_unicode_to_unicode_is_passed_through(self):
     self.assertEqual(utils.to_unicode('æøå'), 'æøå')
Пример #44
0
 def test_bytes_to_unicode_is_decoded_as_utf8(self):
     self.assertEqual(utils.to_unicode('æøå'.encode('utf-8')), 'æøå')
Пример #45
0
 def display_name(self):
     """The user's displayable username."""
     return utils.to_unicode(lib.sp_user_display_name(self._sp_user))
Пример #46
0
 def user_name(self):
     """The username of the logged in user."""
     return utils.to_unicode(lib.sp_session_user_name(self._sp_session))