[GH-ISSUE #730] How to get "category" tags for albums? #439

Closed
opened 2026-02-27 23:22:38 +03:00 by kerem · 5 comments
Owner

Originally created by @josh-ashkinaze on GitHub (Sep 24, 2021).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/730

Which object has "category" as an attribute? Here is a simple script to get all albums by the Talking Heads. Yet for each album object, I can't view the actual genre/categories of the album.

# Source
# https://github.com/plamere/spotipy/blob/master/examples/artist_albums.py

import spotipy
from spotipy.oauth2 import SpotifyOAuth
from spotipy.oauth2 import SpotifyClientCredentials
import logging

cid = "client_id"
cs = "client_secret"
uri = "http://localhost:8888/callback"

auth_manager = SpotifyClientCredentials(client_id=cid, client_secret=cs)
sp = spotipy.Spotify(auth_manager=auth_manager)

logger = logging.getLogger('artist_albums')
logging.basicConfig(level='INFO')

def get_artist(name):
    results = sp.search(q='artist:' + name, type='artist')
    items = results['artists']['items']
    if len(items) > 0:
        return items[0]
    else:
        return None


def show_artist_albums(artist):
    albums = []
    results = sp.artist_albums(artist['id'], album_type='album')
    albums.extend(results['items'])
    while results['next']:
        results = sp.next(results)
        albums.extend(results['items'])
    seen = set()  # to avoid dups
    albums.sort(key=lambda album: album['name'].lower())
    for album in albums:
        name = album['name']
        if name not in seen:
            logger.info('ALBUM: %s', name)
            seen.add(name)
    return albums
            
artist = get_artist("Talking Heads")
albums = show_artist_albums(artist)

# Get album object
sample_album = albums[0]
sample_album_dets = sp.albums([sample_album['id']])


Originally created by @josh-ashkinaze on GitHub (Sep 24, 2021). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/730 Which object has "category" as an attribute? Here is a simple script to get all albums by the Talking Heads. Yet for each album object, I can't view the actual genre/categories of the album. ``` # Source # https://github.com/plamere/spotipy/blob/master/examples/artist_albums.py import spotipy from spotipy.oauth2 import SpotifyOAuth from spotipy.oauth2 import SpotifyClientCredentials import logging cid = "client_id" cs = "client_secret" uri = "http://localhost:8888/callback" auth_manager = SpotifyClientCredentials(client_id=cid, client_secret=cs) sp = spotipy.Spotify(auth_manager=auth_manager) logger = logging.getLogger('artist_albums') logging.basicConfig(level='INFO') def get_artist(name): results = sp.search(q='artist:' + name, type='artist') items = results['artists']['items'] if len(items) > 0: return items[0] else: return None def show_artist_albums(artist): albums = [] results = sp.artist_albums(artist['id'], album_type='album') albums.extend(results['items']) while results['next']: results = sp.next(results) albums.extend(results['items']) seen = set() # to avoid dups albums.sort(key=lambda album: album['name'].lower()) for album in albums: name = album['name'] if name not in seen: logger.info('ALBUM: %s', name) seen.add(name) return albums artist = get_artist("Talking Heads") albums = show_artist_albums(artist) # Get album object sample_album = albums[0] sample_album_dets = sp.albums([sample_album['id']]) ```
kerem closed this issue 2026-02-27 23:22:39 +03:00
Author
Owner

@stephanebruckert commented on GitHub (Sep 29, 2021):

Not all releases/artists have a genre unfortunately

<!-- gh-comment-id:930560296 --> @stephanebruckert commented on GitHub (Sep 29, 2021): Not all releases/artists have a genre unfortunately
Author
Owner

@Peter-Schorn commented on GitHub (Sep 29, 2021):

The album object does not have a genre field. The artist object does (but it may be empty). See the object index.

<!-- gh-comment-id:930570338 --> @Peter-Schorn commented on GitHub (Sep 29, 2021): The album object does not have a genre field. The artist object does (but it may be empty). See the [object index](https://developer.spotify.com/documentation/web-api/reference/#objects-index).
Author
Owner

@stephanebruckert commented on GitHub (Sep 29, 2021):

@Peter-Schorn albums also have a genres field, see here https://developer.spotify.com/console/get-album/?id=0sNOF9WDwhWunNAHPD3Baj (although it's empty here)

<!-- gh-comment-id:930574006 --> @stephanebruckert commented on GitHub (Sep 29, 2021): @Peter-Schorn albums also have a `genres` field, see here https://developer.spotify.com/console/get-album/?id=0sNOF9WDwhWunNAHPD3Baj (although it's empty here)
Author
Owner

@Peter-Schorn commented on GitHub (Sep 29, 2021):

I didn't realize that. The documentation for AlbumBase does not include a genre field. This must be a bug.

<!-- gh-comment-id:930576899 --> @Peter-Schorn commented on GitHub (Sep 29, 2021): I didn't realize that. The documentation for [AlbumBase](https://developer.spotify.com/documentation/web-api/reference/#object-albumbase) does not include a `genre` field. This must be a bug.
Author
Owner

@stephanebruckert commented on GitHub (Oct 23, 2021):

Hope these answers helped @josh-ashkinaze

<!-- gh-comment-id:950141862 --> @stephanebruckert commented on GitHub (Oct 23, 2021): Hope these answers helped @josh-ashkinaze
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#439
No description provided.