async def search_song(self, keyword: str) -> api.SearchResult: resp = await self.search_song_raw(keyword) try: _songs = resp['songResultData']['result'] except KeyError: raise exceptions.DataError('search song: no data') if not _songs: raise exceptions.DataError('search song: no data') songs = [ api.SearchSongData( song_id=_song['copyrightId'], name=_song['name'].strip(), artist='/'.join([s['name'].strip() for s in _song['singers']]), album='/'.join([a['name'].strip() for a in _song['albums']]) ) for _song in _songs ] return api.SearchResult(keyword=keyword, count=len(songs), songs=songs)
async def search_song(self, keyword: str) -> api.SearchResult: resp = await self.search_song_raw(keyword) try: songs = resp['result']['songs'] except KeyError: raise exceptions.DataError('search song: no data') if not songs: raise exceptions.DataError('search song: no data') songs = [ api.SearchSongData( song_id=song['id'], name=song['name'].strip(), artist='/'.join([a['name'].strip() for a in song['artists']]), album=song['album']['name'].strip(), ) for song in songs ] return api.SearchResult(keyword=keyword, count=len(songs), songs=songs)
async def search_song(self, keyword: str) -> api.SearchResult: resp = await self.search_song_raw(keyword) try: _songs = resp['data']['info'] except KeyError: raise exceptions.DataError('search song: no data') if not _songs: raise exceptions.DataError('search song: no data') songs = [ api.SearchSongData( song_id=_song['hash'], name=_song['songname'].strip(), artist=_song['singername'].replace('、', '/').strip(), album=_song['album_name'].strip(), ) for _song in _songs ] return api.SearchResult(keyword=keyword, count=len(songs), songs=songs)