Пример #1
0
 def get_artist(self, id):
     print(f'calling Spotify to get artist with id of {id}')
     spotify_artist = self.sp.artist(id)
     artist = Artist()
     artist.id = spotify_artist['id']
     artist.name = spotify_artist['name']
     artist.genres = spotify_artist['genres']
     return artist
Пример #2
0
    def search_by_artist(self, criteria):
        print(f'searching Spotify by artist with criteria of {criteria}')

        results = self.sp.search(q=criteria, limit=1, type="artist")

        total_found = results['artists']['total']

        if total_found <= 0:
            print(f'No artists found for {criteria}')
            raise KeyError(f'No artists found for {criteria}')

        if total_found > 1:
            print(
                f'Too many artists found for {criteria}.  Found {total_found}')
            raise IndexError(
                f'Too many artists found for {criteria}.  Found {total_found}')

        for i, a in enumerate(results['artists']['items']):
            artist = Artist()
            artist.id = a['id']
            artist.name = a['name']
            artist.genres = a['genres']
            return artist