Example #1
0
    def get_published_playlists(self, canonical_username=None):
        """Get the :class:`PlaylistContainer` of published playlists for the
        user with ``canonical_username``.

        .. warning::

            The playlists API was broken at 2018-05-24 by a server-side change
            made by Spotify. The functionality was never restored.

            Please use the Spotify Web API to work with playlists.

        If ``canonical_username`` isn't specified, the published container for
        the currently logged in user is returned.
        """
        warnings.warn("Spotify broke the libspotify playlists API 2018-05-24 "
                      "and never restored it. "
                      "Please use the Spotify Web API to work with playlists.")
        if canonical_username is None:
            canonical_username = ffi.NULL
        else:
            canonical_username = utils.to_bytes(canonical_username)
        sp_playlistcontainer = (
            lib.sp_session_publishedcontainer_for_user_create(
                self._sp_session, canonical_username))
        if sp_playlistcontainer == ffi.NULL:
            return None
        return spotify.PlaylistContainer._cached(self,
                                                 sp_playlistcontainer,
                                                 add_ref=False)
Example #2
0
 def starred_for_user(self, canonical_username):
     """The starred :class:`Playlist` for the user with
     ``canonical_username``."""
     sp_playlist = lib.sp_session_starred_for_user_create(
         self._sp_session, utils.to_bytes(canonical_username))
     if sp_playlist == ffi.NULL:
         return None
     return spotify.Playlist._cached(sp_playlist, add_ref=False)
Example #3
0
    def settings_location(self):
        """A location for libspotify to save settings.

        Defaults to ``tmp`` in the current working directory.

        Must be a bytestring. Cannot be shared with other Spotify apps. Can
        only be used by one session at the time. Optimally, you should use a
        lock file or similar to ensure this.
        """
        return utils.to_bytes(self._sp_session_config.settings_location)
Example #4
0
 def _as_sp_playlist(self):
     sp_playlist = None
     if self.type == LinkType.PLAYLIST:
         sp_playlist = lib.sp_playlist_create(self._session._sp_session,
                                              self._sp_link)
     elif self.type == LinkType.STARRED:
         matches = re.match(r'^spotify:user:([^:]+):starred$', self.uri)
         if matches:
             username = matches.group(1)
             sp_playlist = lib.sp_session_starred_for_user_create(
                 self._session._sp_session, utils.to_bytes(username))
     if sp_playlist is None or sp_playlist == ffi.NULL:
         return None
     return sp_playlist
Example #5
0
 def _as_sp_playlist(self):
     sp_playlist = None
     if self.type == LinkType.PLAYLIST:
         sp_playlist = lib.sp_playlist_create(
             self._session._sp_session, self._sp_link)
     elif self.type == LinkType.STARRED:
         matches = re.match(r'^spotify:user:([^:]+):starred$', self.uri)
         if matches:
             username = matches.group(1)
             sp_playlist = lib.sp_session_starred_for_user_create(
                 self._session._sp_session, utils.to_bytes(username))
     if sp_playlist is None or sp_playlist == ffi.NULL:
         return None
     return sp_playlist
Example #6
0
    def get_starred(self, canonical_username=None):
        """Get the starred :class:`Playlist` for the user with
        ``canonical_username``.

        If ``canonical_username`` isn't specified, the starred playlist for
        the currently logged in user is returned.
        """
        if canonical_username is None:
            sp_playlist = lib.sp_session_starred_create(self._sp_session)
        else:
            sp_playlist = lib.sp_session_starred_for_user_create(
                self._sp_session, utils.to_bytes(canonical_username))
        if sp_playlist == ffi.NULL:
            return None
        return spotify.Playlist._cached(self, sp_playlist, add_ref=False)
Example #7
0
    def get_starred(self, canonical_username=None):
        """Get the starred :class:`Playlist` for the user with
        ``canonical_username``.

        If ``canonical_username`` isn't specified, the starred playlist for
        the currently logged in user is returned.
        """
        if canonical_username is None:
            sp_playlist = lib.sp_session_starred_create(self._sp_session)
        else:
            sp_playlist = lib.sp_session_starred_for_user_create(
                self._sp_session, utils.to_bytes(canonical_username))
        if sp_playlist == ffi.NULL:
            return None
        return spotify.Playlist._cached(self, sp_playlist, add_ref=False)
Example #8
0
    def published_playlists_for_user(self, canonical_username=None):
        """The :class:`PlaylistContainer` of published playlists for the user
        with ``canonical_username``.

        If ``canonical_username`` isn't specified, the published container for
        the currently logged in user is returned."""
        if canonical_username is None:
            canonical_username = ffi.NULL
        else:
            canonical_username = utils.to_bytes(canonical_username)
        sp_playlistcontainer = (
            lib.sp_session_publishedcontainer_for_user_create(
                self._sp_session, canonical_username))
        if sp_playlistcontainer == ffi.NULL:
            return None
        return spotify.PlaylistContainer._cached(sp_playlistcontainer,
                                                 add_ref=False)
Example #9
0
    def get_published_playlists(self, canonical_username=None):
        """Get the :class:`PlaylistContainer` of published playlists for the
        user with ``canonical_username``.

        If ``canonical_username`` isn't specified, the published container for
        the currently logged in user is returned.
        """
        if canonical_username is None:
            canonical_username = ffi.NULL
        else:
            canonical_username = utils.to_bytes(canonical_username)
        sp_playlistcontainer = (
            lib.sp_session_publishedcontainer_for_user_create(
                self._sp_session, canonical_username))
        if sp_playlistcontainer == ffi.NULL:
            return None
        return spotify.PlaylistContainer._cached(
            self, sp_playlistcontainer, add_ref=False)
Example #10
0
    def test_anything_else_to_bytes_fails(self):
        with self.assertRaises(ValueError):
            utils.to_bytes([])

        with self.assertRaises(ValueError):
            utils.to_bytes(123)
Example #11
0
 def test_cdata_to_bytes_is_unwrapped(self):
     cdata = spotify.ffi.new('char[]', 'æøå'.encode('utf-8'))
     self.assertEqual(utils.to_bytes(cdata), 'æøå'.encode('utf-8'))
Example #12
0
 def test_bytes_to_bytes_is_passed_through(self):
     self.assertEqual(
         utils.to_bytes('æøå'.encode('utf-8')), 'æøå'.encode('utf-8')
     )
Example #13
0
 def test_unicode_to_bytes_is_encoded_as_utf8(self):
     self.assertEqual(utils.to_bytes('æøå'), 'æøå'.encode('utf-8'))