Пример #1
0
    def __init__(
        self,
        session,
        album=None,
        callback=None,
        sp_albumbrowse=None,
        add_ref=True,
    ):

        assert album or sp_albumbrowse, 'album or sp_albumbrowse is required'

        self._session = session
        self.loaded_event = threading.Event()

        if sp_albumbrowse is None:
            handle = ffi.new_handle((self._session, self, callback))
            self._session._callback_handles.add(handle)

            sp_albumbrowse = lib.sp_albumbrowse_create(
                self._session._sp_session,
                album._sp_album,
                _albumbrowse_complete_callback,
                handle,
            )
            add_ref = False

        if add_ref:
            lib.sp_albumbrowse_add_ref(sp_albumbrowse)
        self._sp_albumbrowse = ffi.gc(sp_albumbrowse,
                                      lib.sp_albumbrowse_release)
Пример #2
0
    def __init__(self,
                 session,
                 uri=None,
                 sp_image=None,
                 add_ref=True,
                 callback=None):

        assert uri or sp_image, 'uri or sp_image is required'

        self._session = session

        if uri is not None:
            image = spotify.Link(self._session, uri=uri).as_image()
            if image is None:
                raise ValueError('Failed to get image from Spotify URI: %r' %
                                 uri)
            sp_image = image._sp_image
            add_ref = True

        if add_ref:
            lib.sp_image_add_ref(sp_image)
        self._sp_image = ffi.gc(sp_image, lib.sp_image_release)

        self.loaded_event = threading.Event()

        handle = ffi.new_handle((self._session, self, callback))
        self._session._callback_handles.add(handle)
        spotify.Error.maybe_raise(
            lib.sp_image_add_load_callback(self._sp_image,
                                           _image_load_callback, handle))
Пример #3
0
    def __init__(self,
                 session,
                 artist=None,
                 type=None,
                 callback=None,
                 sp_artistbrowse=None,
                 add_ref=True):

        assert artist or sp_artistbrowse, (
            'artist or sp_artistbrowse is required')

        self._session = session
        self.loaded_event = threading.Event()

        if sp_artistbrowse is None:
            if type is None:
                type = ArtistBrowserType.FULL

            handle = ffi.new_handle((self._session, self, callback))
            self._session._callback_handles.add(handle)

            sp_artistbrowse = lib.sp_artistbrowse_create(
                self._session._sp_session, artist._sp_artist, int(type),
                _artistbrowse_complete_callback, handle)
            add_ref = False

        if add_ref:
            lib.sp_artistbrowse_add_ref(sp_artistbrowse)
        self._sp_artistbrowse = ffi.gc(sp_artistbrowse,
                                       lib.sp_artistbrowse_release)
Пример #4
0
    def __init__(
            self, session, artist=None, type=None, callback=None,
            sp_artistbrowse=None, add_ref=True):

        assert artist or sp_artistbrowse, (
            'artist or sp_artistbrowse is required')

        self._session = session
        self.loaded_event = threading.Event()

        if sp_artistbrowse is None:
            if type is None:
                type = ArtistBrowserType.FULL

            handle = ffi.new_handle((self._session, self, callback))
            self._session._callback_handles.add(handle)

            sp_artistbrowse = lib.sp_artistbrowse_create(
                self._session._sp_session, artist._sp_artist,
                int(type), _artistbrowse_complete_callback, handle)
            add_ref = False

        if add_ref:
            lib.sp_artistbrowse_add_ref(sp_artistbrowse)
        self._sp_artistbrowse = ffi.gc(
            sp_artistbrowse, lib.sp_artistbrowse_release)
Пример #5
0
    def __init__(
            self, album=None, callback=None,
            sp_albumbrowse=None, add_ref=True):

        assert album or sp_albumbrowse, 'album or sp_albumbrowse is required'

        self.complete_event = threading.Event()
        self._callback_handles = set()

        if sp_albumbrowse is None:
            handle = ffi.new_handle((callback, self))
            # TODO Think through the life cycle of the handle object. Can it
            # happen that we GC the browser and handle object, and then later
            # the callback is called?
            self._callback_handles.add(handle)

            sp_albumbrowse = lib.sp_albumbrowse_create(
                spotify.session_instance._sp_session, album._sp_album,
                _albumbrowse_complete_callback, handle)
            add_ref = False

        if add_ref:
            lib.sp_albumbrowse_add_ref(sp_albumbrowse)
        self._sp_albumbrowse = ffi.gc(
            sp_albumbrowse, lib.sp_albumbrowse_release)
Пример #6
0
    def __init__(
            self, session, type=None, region=None, canonical_username=None,
            callback=None, sp_toplistbrowse=None, add_ref=True):

        assert (type is not None and region is not None) or sp_toplistbrowse, \
            'type and region, or sp_toplistbrowse, is required'

        self._session = session
        self.type = type
        self.region = region
        self.canonical_username = canonical_username
        self.loaded_event = threading.Event()

        if sp_toplistbrowse is None:
            if isinstance(region, ToplistRegion):
                region = int(region)
            else:
                region = utils.to_country_code(region)

            handle = ffi.new_handle((self._session, self, callback))
            self._session._callback_handles.add(handle)

            sp_toplistbrowse = lib.sp_toplistbrowse_create(
                self._session._sp_session, int(type), region,
                utils.to_char_or_null(canonical_username),
                _toplistbrowse_complete_callback, handle)
            add_ref = False

        if add_ref:
            lib.sp_toplistbrowse_add_ref(sp_toplistbrowse)
        self._sp_toplistbrowse = ffi.gc(
            sp_toplistbrowse, lib.sp_toplistbrowse_release)
Пример #7
0
    def __init__(
            self, session, canonical_username=None, tracks=None, message='',
            callback=None, sp_inbox=None, add_ref=True):

        assert canonical_username and tracks or sp_inbox, \
            'canonical_username and tracks, or sp_inbox, is required'

        self._session = session
        self.loaded_event = threading.Event()

        if sp_inbox is None:
            canonical_username = utils.to_char(canonical_username)

            if isinstance(tracks, spotify.Track):
                tracks = [tracks]

            message = utils.to_char(message)

            handle = ffi.new_handle((self._session, self, callback))
            self._session._callback_handles.add(handle)

            sp_inbox = lib.sp_inbox_post_tracks(
                self._session._sp_session, canonical_username,
                [t._sp_track for t in tracks], len(tracks),
                message, _inboxpost_complete_callback, handle)
            add_ref = True

            if sp_inbox == ffi.NULL:
                raise spotify.Error('Inbox post request failed to initialize')

        if add_ref:
            lib.sp_inbox_add_ref(sp_inbox)
        self._sp_inbox = ffi.gc(sp_inbox, lib.sp_inbox_release)
Пример #8
0
    def __init__(
        self,
        session,
        query='',
        callback=None,
        track_offset=0,
        track_count=20,
        album_offset=0,
        album_count=20,
        artist_offset=0,
        artist_count=20,
        playlist_offset=0,
        playlist_count=20,
        search_type=None,
        sp_search=None,
        add_ref=True,
    ):

        assert query or sp_search, 'query or sp_search is required'

        self._session = session
        self.callback = callback
        self.track_offset = track_offset
        self.track_count = track_count
        self.album_offset = album_offset
        self.album_count = album_count
        self.artist_offset = artist_offset
        self.artist_count = artist_count
        self.playlist_offset = playlist_offset
        self.playlist_count = playlist_count
        if search_type is None:
            search_type = SearchType.STANDARD
        self.search_type = search_type

        self.loaded_event = threading.Event()

        if sp_search is None:
            handle = ffi.new_handle((self._session, self, callback))
            self._session._callback_handles.add(handle)

            sp_search = lib.sp_search_create(
                self._session._sp_session,
                utils.to_char(query),
                track_offset,
                track_count,
                album_offset,
                album_count,
                artist_offset,
                artist_count,
                playlist_offset,
                playlist_count,
                int(search_type),
                _search_complete_callback,
                handle,
            )
            add_ref = False

        if add_ref:
            lib.sp_search_add_ref(sp_search)
        self._sp_search = ffi.gc(sp_search, lib.sp_search_release)
Пример #9
0
    def __init__(
            self, session, uri=None, sp_image=None, add_ref=True,
            callback=None):

        assert uri or sp_image, 'uri or sp_image is required'

        self._session = session

        if uri is not None:
            image = spotify.Link(self._session, uri=uri).as_image()
            if image is None:
                raise ValueError(
                    'Failed to get image from Spotify URI: %r' % uri)
            sp_image = image._sp_image
            add_ref = True

        if add_ref:
            lib.sp_image_add_ref(sp_image)
        self._sp_image = ffi.gc(sp_image, lib.sp_image_release)

        self.loaded_event = threading.Event()

        handle = ffi.new_handle((self._session, self, callback))
        self._session._callback_handles.add(handle)
        spotify.Error.maybe_raise(lib.sp_image_add_load_callback(
            self._sp_image, _image_load_callback, handle))
Пример #10
0
    def __init__(self,
                 query='',
                 callback=None,
                 track_offset=0,
                 track_count=20,
                 album_offset=0,
                 album_count=20,
                 artist_offset=0,
                 artist_count=20,
                 playlist_offset=0,
                 playlist_count=20,
                 search_type=None,
                 sp_search=None,
                 add_ref=True):

        assert query or sp_search, 'query or sp_search is required'

        self.callback = callback
        self.track_offset = track_offset
        self.track_count = track_count
        self.album_offset = album_offset
        self.album_count = album_count
        self.artist_offset = artist_offset
        self.artist_count = artist_count
        self.playlist_offset = playlist_offset
        self.playlist_count = playlist_count
        if search_type is None:
            search_type = SearchType.STANDARD
        self.search_type = search_type

        self.complete_event = threading.Event()
        self._callback_handles = set()

        if sp_search is None:
            handle = ffi.new_handle((callback, self))
            # TODO Think through the life cycle of the handle object. Can it
            # happen that we GC the search and handle object, and then later
            # the callback is called?
            self._callback_handles.add(handle)

            sp_search = lib.sp_search_create(
                spotify.session_instance._sp_session, utils.to_char(query),
                track_offset, track_count, album_offset, album_count,
                artist_offset, artist_count, playlist_offset, playlist_count,
                int(search_type), _search_complete_callback, handle)
            add_ref = False

        if add_ref:
            lib.sp_search_add_ref(sp_search)
        self._sp_search = ffi.gc(sp_search, lib.sp_search_release)
Пример #11
0
    def __init__(
        self,
        session,
        canonical_username=None,
        tracks=None,
        message='',
        callback=None,
        sp_inbox=None,
        add_ref=True,
    ):

        assert (
            canonical_username and tracks or sp_inbox
        ), 'canonical_username and tracks, or sp_inbox, is required'

        self._session = session
        self.loaded_event = threading.Event()

        if sp_inbox is None:
            canonical_username = utils.to_char(canonical_username)

            if isinstance(tracks, spotify.Track):
                tracks = [tracks]

            message = utils.to_char(message)

            handle = ffi.new_handle((self._session, self, callback))
            self._session._callback_handles.add(handle)

            sp_inbox = lib.sp_inbox_post_tracks(
                self._session._sp_session,
                canonical_username,
                [t._sp_track for t in tracks],
                len(tracks),
                message,
                _inboxpost_complete_callback,
                handle,
            )
            add_ref = True

            if sp_inbox == ffi.NULL:
                raise spotify.Error('Inbox post request failed to initialize')

        if add_ref:
            lib.sp_inbox_add_ref(sp_inbox)
        self._sp_inbox = ffi.gc(sp_inbox, lib.sp_inbox_release)
Пример #12
0
    def __init__(
            self, session, query='', callback=None,
            track_offset=0, track_count=20,
            album_offset=0, album_count=20,
            artist_offset=0, artist_count=20,
            playlist_offset=0, playlist_count=20,
            search_type=None,
            sp_search=None, add_ref=True):

        assert query or sp_search, 'query or sp_search is required'

        self._session = session
        self.callback = callback
        self.track_offset = track_offset
        self.track_count = track_count
        self.album_offset = album_offset
        self.album_count = album_count
        self.artist_offset = artist_offset
        self.artist_count = artist_count
        self.playlist_offset = playlist_offset
        self.playlist_count = playlist_count
        if search_type is None:
            search_type = SearchType.STANDARD
        self.search_type = search_type

        self.loaded_event = threading.Event()

        if sp_search is None:
            handle = ffi.new_handle((self._session, self, callback))
            self._session._callback_handles.add(handle)

            sp_search = lib.sp_search_create(
                self._session._sp_session, utils.to_char(query),
                track_offset, track_count,
                album_offset, album_count,
                artist_offset, artist_count,
                playlist_offset, playlist_count,
                int(search_type), _search_complete_callback, handle)
            add_ref = False

        if add_ref:
            lib.sp_search_add_ref(sp_search)
        self._sp_search = ffi.gc(sp_search, lib.sp_search_release)
Пример #13
0
    def __init__(
        self,
        session,
        type=None,
        region=None,
        canonical_username=None,
        callback=None,
        sp_toplistbrowse=None,
        add_ref=True,
    ):

        assert (type is not None and region is not None) or sp_toplistbrowse, (
            'type and region, or sp_toplistbrowse, is required')

        self._session = session
        self.type = type
        self.region = region
        self.canonical_username = canonical_username
        self.loaded_event = threading.Event()

        if sp_toplistbrowse is None:
            if isinstance(region, ToplistRegion):
                region = int(region)
            else:
                region = utils.to_country_code(region)

            handle = ffi.new_handle((self._session, self, callback))
            self._session._callback_handles.add(handle)

            sp_toplistbrowse = lib.sp_toplistbrowse_create(
                self._session._sp_session,
                int(type),
                region,
                utils.to_char_or_null(canonical_username),
                _toplistbrowse_complete_callback,
                handle,
            )
            add_ref = False

        if add_ref:
            lib.sp_toplistbrowse_add_ref(sp_toplistbrowse)
        self._sp_toplistbrowse = ffi.gc(sp_toplistbrowse,
                                        lib.sp_toplistbrowse_release)
Пример #14
0
    def __init__(self,
                 type=None,
                 region=None,
                 canonical_username=None,
                 callback=None,
                 sp_toplistbrowse=None,
                 add_ref=True):

        assert (type is not None and region is not None) or sp_toplistbrowse, \
            'type and region, or sp_toplistbrowse, is required'

        # TODO Document these attributes?
        self.type = type
        self.region = region
        self.canonical_username = canonical_username

        self.complete_event = threading.Event()
        self._callback_handles = set()

        if sp_toplistbrowse is None:
            if isinstance(region, ToplistRegion):
                region = int(region)
            else:
                region = utils.to_country_code(region)

            handle = ffi.new_handle((callback, self))
            # TODO Think through the life cycle of the handle object. Can it
            # happen that we GC the search and handle object, and then later
            # the callback is called?
            self._callback_handles.add(handle)

            sp_toplistbrowse = lib.sp_toplistbrowse_create(
                spotify.session_instance._sp_session, int(type), region,
                utils.to_char_or_null(canonical_username),
                _toplistbrowse_complete_callback, handle)
            add_ref = False

        if add_ref:
            lib.sp_toplistbrowse_add_ref(sp_toplistbrowse)
        self._sp_toplistbrowse = ffi.gc(sp_toplistbrowse,
                                        lib.sp_toplistbrowse_release)
Пример #15
0
    def __init__(self,
                 canonical_username=None,
                 tracks=None,
                 message='',
                 callback=None,
                 sp_inbox=None,
                 add_ref=True):

        assert canonical_username and tracks or sp_inbox, \
            'canonical_username and tracks, or sp_inbox, is required'

        self.complete_event = threading.Event()
        self._callback_handles = set()

        if sp_inbox is None:
            canonical_username = utils.to_char(canonical_username)

            if isinstance(tracks, spotify.Track):
                tracks = [tracks]

            message = utils.to_char(message)

            handle = ffi.new_handle((callback, self))
            # TODO Think through the life cycle of the handle object. Can it
            # happen that we GC the search and handle object, and then later
            # the callback is called?
            self._callback_handles.add(handle)

            sp_inbox = lib.sp_inbox_post_tracks(
                spotify.session_instance._sp_session, canonical_username,
                [t._sp_track for t in tracks], len(tracks), message,
                _inboxpost_complete_callback, handle)
            add_ref = True

            if sp_inbox == ffi.NULL:
                raise spotify.Error('Inbox post request failed to initialize')

        if add_ref:
            lib.sp_inbox_add_ref(sp_inbox)
        self._sp_inbox = ffi.gc(sp_inbox, lib.sp_inbox_release)
Пример #16
0
    def __init__(
            self, session, album=None, callback=None,
            sp_albumbrowse=None, add_ref=True):

        assert album or sp_albumbrowse, 'album or sp_albumbrowse is required'

        self._session = session
        self.loaded_event = threading.Event()

        if sp_albumbrowse is None:
            handle = ffi.new_handle((self._session, self, callback))
            self._session._callback_handles.add(handle)

            sp_albumbrowse = lib.sp_albumbrowse_create(
                self._session._sp_session, album._sp_album,
                _albumbrowse_complete_callback, handle)
            add_ref = False

        if add_ref:
            lib.sp_albumbrowse_add_ref(sp_albumbrowse)
        self._sp_albumbrowse = ffi.gc(
            sp_albumbrowse, lib.sp_albumbrowse_release)