Source code for spotify.search

from __future__ import unicode_literals

import logging
import threading

import spotify
from spotify import ffi, lib, serialized, utils


__all__ = ['Search', 'SearchPlaylist', 'SearchType']

logger = logging.getLogger(__name__)





@ffi.callback('void(sp_search *, void *)')
@serialized
def _search_complete_callback(sp_search, handle):
    logger.debug('search_complete_callback called')
    if handle == ffi.NULL:
        logger.warning(
            'pyspotify search_complete_callback called without userdata'
        )
        return
    (session, search_result, callback) = ffi.from_handle(handle)
    session._callback_handles.remove(handle)
    search_result.loaded_event.set()
    if callback is not None:
        callback(search_result)


[docs]class SearchPlaylist(object): """A playlist matching a search query.""" name = None """The name of the playlist.""" uri = None """The URI of the playlist.""" image_uri = None """The URI of the playlist's image.""" def __init__(self, session, name, uri, image_uri): self._session = session self.name = name self.uri = uri self.image_uri = image_uri def __repr__(self): return 'SearchPlaylist(name=%r, uri=%r)' % (self.name, self.uri) @property def playlist(self): """The :class:`~spotify.Playlist` object for this :class:`SearchPlaylist`.""" return self._session.get_playlist(self.uri) @property def image(self): """The :class:`~spotify.Image` object for this :class:`SearchPlaylist`.""" return self._session.get_image(self.image_uri)
[docs]@utils.make_enum('SP_SEARCH_') class SearchType(utils.IntEnum): pass