예제 #1
0
파일: netease.py 프로젝트: owlwang/pymxget
    async def search_songs(self, keyword: str) -> api.SearchSongsResult:
        resp = await self.search_songs_raw(keyword)
        try:
            songs = resp['result']['songs']
        except KeyError:
            raise exceptions.DataError('search songs: no data')

        if not songs:
            raise exceptions.DataError('search songs: no data')

        songs = [
            api.SearchSongsData(
                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.SearchSongsResult(keyword=keyword, count=len(songs), songs=songs)
예제 #2
0
    async def search_songs(self, keyword: str) -> api.SearchSongsResult:
        resp = await self.search_songs_raw(keyword)
        try:
            _songs = resp['data']['list']
        except KeyError:
            raise exceptions.DataError('search songs: no data')

        if not _songs:
            raise exceptions.DataError('search songs: no data')

        songs = [
            api.SearchSongsData(
                song_id=_song['rid'],
                name=_song['name'].strip(),
                artist=_song['artist'].replace('&', '/').strip(),
                album=_song['album'].strip(),
            ) for _song in _songs
        ]
        return api.SearchSongsResult(keyword=keyword, count=len(songs), songs=songs)
예제 #3
0
파일: migu.py 프로젝트: owlwang/pymxget
    async def search_songs(self, keyword: str) -> api.SearchSongsResult:
        resp = await self.search_songs_raw(keyword)
        try:
            _songs = resp['songResultData']['result']
        except KeyError:
            raise exceptions.DataError('search songs: no data')

        if not _songs:
            raise exceptions.DataError('search songs: no data')

        songs = [
            api.SearchSongsData(
                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.SearchSongsResult(keyword=keyword, count=len(songs), songs=songs)