Announcements

Help Wizard

Step 1

NEXT STEP

FAQs

Please see below the most popular frequently asked questions.

Loading article...

Loading faqs...

VIEW ALL

Ongoing Issues

Please see below the current ongoing issues which are under investigation.

Loading issue...

Loading ongoing issues...

VIEW ALL

Explicit Filter in Get Recommendations (API)

Solved!

Explicit Filter in Get Recommendations (API)

I would like to use Get Recommendations for explicit=False songs. Explicit is in the response but not in the request.

 

1. Feature request: can we add explicit=False arg to Get Recommendations

2. In the meantime, how can I implement my own filter?

Reply

Accepted Solutions
Marked as solution

Greeting you with a wagging tail mashmia!
Unfortunately, the Spotify API currently does not provide an explicit "false" argument for the Get Recommendations endpoint. However, you can still filter the recommendations based on explicit content by implementing your own filter in your code.

Here's an example of how you can filter out explicit content from the recommendations response in Python:

 

 

import spotipy
from spotipy.oauth2 import SpotifyClientCredentials

client_id = 'your_client_id'
client_secret = 'your_client_secret'
client_credentials_manager = SpotifyClientCredentials(client_id, client_secret)
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)

# Get recommendations
recs = sp.recommendations(seed_artists=['6mdiAmATAx73kdxrNrnlao'], seed_genres=['rock'], limit=10)

# Filter out explicit tracks
filtered_recs = []
for track in recs['tracks']:
    if not track['explicit']:
        filtered_recs.append(track)

print(filtered_recs)

 

 

 

In this example, we first use the sp.recommendations method to retrieve a list of recommended tracks based on a set of seed artists and genres. We then loop through the list of tracks and check the explicit property for each track. If the track is not marked as explicit, we add it to a new list of filtered recommendations.

You can customize this code to fit your specific use case and filtering criteria.

I'll be barking up the wrong tree without updates on your situation, 

 

-Prague the Dog

View solution in original post

1 Reply
Marked as solution

Greeting you with a wagging tail mashmia!
Unfortunately, the Spotify API currently does not provide an explicit "false" argument for the Get Recommendations endpoint. However, you can still filter the recommendations based on explicit content by implementing your own filter in your code.

Here's an example of how you can filter out explicit content from the recommendations response in Python:

 

 

import spotipy
from spotipy.oauth2 import SpotifyClientCredentials

client_id = 'your_client_id'
client_secret = 'your_client_secret'
client_credentials_manager = SpotifyClientCredentials(client_id, client_secret)
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)

# Get recommendations
recs = sp.recommendations(seed_artists=['6mdiAmATAx73kdxrNrnlao'], seed_genres=['rock'], limit=10)

# Filter out explicit tracks
filtered_recs = []
for track in recs['tracks']:
    if not track['explicit']:
        filtered_recs.append(track)

print(filtered_recs)

 

 

 

In this example, we first use the sp.recommendations method to retrieve a list of recommended tracks based on a set of seed artists and genres. We then loop through the list of tracks and check the explicit property for each track. If the track is not marked as explicit, we add it to a new list of filtered recommendations.

You can customize this code to fit your specific use case and filtering criteria.

I'll be barking up the wrong tree without updates on your situation, 

 

-Prague the Dog

Suggested posts

Type a product name