Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
375 views
in Technique[技术] by (71.8m points)

python - Checking to see if a song is available to play with Spotipy

My problem: Differentiate between tracks that are playable and not.

I am trying to use Spotipy to print me the metadata details of all the tracks in a playlist. Some songs I have added to my playlist is no longer available, and therefore do not show in my spotify playlist (greyed out). However they do print normally togheter with the rest of the tracks that are available. I do not want them there; if I can't play them at this time I don't want them to show in my printed playlist.

I check which markets the track is available in to determine if it should print or not. This is working fine.

'available_markets': []

The problem I have is that there are some tracks that do not have any available markets and are empty like the code snippet shows. They are identical to the songs tracks that are unavailable to me. But I can still play them! This means my code to remove unavailable songs also removes playable song.

I haven't found another way to get data on if a track really is available or not. Anything I have missed?

question from:https://stackoverflow.com/questions/65872480/checking-to-see-if-a-song-is-available-to-play-with-spotipy

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Check if the track is available within the market and/or if the available market field is empty, it should return true in both cases.

It would go something like

if something in available_markets or not available_markets:
  print("It works!")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...