async def render(req, **kwargs): """/search handler :type app: feeluown.app.App """ q = req.query.get('q', '') if not q: return type_ = req.query.get('type', None) type_ = SearchType.parse(type_) if type_ else SearchType.so source_in = req.query.get('source_in', None) if source_in is not None: source_in = source_in.split(',') else: source_in = None app = req.ctx['app'] ui = app.ui right_panel = ui.right_panel table_container = right_panel.table_container right_panel.collection_container.hide() right_panel.scrollarea.show() reader = wrap(app.library.a_search(q, type_in=type_, source_in=source_in)) renderer = SearchResultRenderer(q, type_, reader, source_in=source_in) await table_container.set_renderer(renderer)
def search(keyword, **kwargs): type_ = SearchType.parse(kwargs['type_']) if type_ == SearchType.pl: data = provider.api.search_playlists(keyword) playlists = [ _deserialize(playlist, _BriefPlaylistSchema, False) for playlist in data ] return QQSearchModel(playlists=playlists) else: type_type_map = { SearchType.so: 0, SearchType.al: 8, SearchType.ar: 9, } data = provider.api.search(keyword, type_=type_type_map[type_]) if type_ == SearchType.so: songs = [_deserialize(song, QQSongSchema) for song in data] return QQSearchModel(songs=songs) elif type_ == SearchType.al: albums = [ _deserialize(album, _BriefAlbumSchema, False) for album in data ] return QQSearchModel(albums=albums) else: artists = [ _deserialize(artist, _BriefArtistSchema, False) for artist in data ] return QQSearchModel(artists=artists)
def search(self, keyword, type_, **kwargs): type_ = SearchType.parse(type_) type_type_map = { SearchType.so: 1, SearchType.al: 10, SearchType.ar: 100, SearchType.pl: 1000, } data = provider.api.search(keyword, stype=type_type_map[type_]) result = _deserialize(data, NeteaseSearchSchema) result.q = keyword return result