This is a continuation of Last time. We will look at API acquisition for each album, song items, etc.
Use the id of any artist obtained last time.
main.py
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
client_id = 'Client id'
client_secret = 'Client secret'
spotify_client_credentials = spotipy.oauth2.SpotifyClientCredentials(client_id, client_secret)
spotify = spotipy.Spotify(client_credentials_manager=spotify_client_credentials)
artist_uri = 'spotify:artist:5PalnqYJTpnO5wt00jf0um'
results = spotify.artist_albums(artist_uri, album_type='album')
print(results)
Now you can get the album information of the artist specified by id. When I run it ...
{
"album_type": "album",
"name": "Regenerative landscape",
"external_urls": {
"spotify": "https://open.spotify.com/album/2evf6T9osScdVnhVrL7tXX"
},
"release_date": "2013-01-23",
"uri": "spotify:album:2evf6T9osScdVnhVrL7tXX",
"total_tracks": 10,
"href": "https://api.spotify.com/v1/albums/2evf6T9osScdVnhVrL7tXX",
"artists": [
{
"name": "the cabs",
"external_urls": {
"spotify": "https://open.spotify.com/artist/5PalnqYJTpnO5wt00jf0um"
},
"uri": "spotify:artist:5PalnqYJTpnO5wt00jf0um",
"href": "https://api.spotify.com/v1/artists/5PalnqYJTpnO5wt00jf0um",
"type": "artist",
"id": "5PalnqYJTpnO5wt00jf0um"
}
],
"images": [
{
"url": "https://i.scdn.co/image/ab67616d0000b273c4f2e7d76207985faf2427c5",
"width": 640,
"height": 640
},
{
"url": "https://i.scdn.co/image/ab67616d00001e02c4f2e7d76207985faf2427c5",
"width": 300,
"height": 300
},
{
"url": "https://i.scdn.co/image/ab67616d00004851c4f2e7d76207985faf2427c5",
"width": 64,
"height": 64
}
],
"album_group": "album",
"type": "album",
"id": "2evf6T9osScdVnhVrL7tXX",
"available_markets": [
"JP"
],
"release_date_precision": "day"
},
{
"album_type": "album",
"name": "saisei no hukei",
"external_urls": {
"spotify": "https://open.spotify.com/album/6koCjq9UGVZFa9YjJgCLok"
},
"release_date": "2013-01-23",
"uri": "spotify:album:6koCjq9UGVZFa9YjJgCLok",
"total_tracks": 10,
"href": "https://api.spotify.com/v1/albums/6koCjq9UGVZFa9YjJgCLok",
"artists": [
{
"name": "the cabs",
"external_urls": {
"spotify": "https://open.spotify.com/artist/5PalnqYJTpnO5wt00jf0um"
},
"uri": "spotify:artist:5PalnqYJTpnO5wt00jf0um",
"href": "https://api.spotify.com/v1/artists/5PalnqYJTpnO5wt00jf0um",
"type": "artist",
"id": "5PalnqYJTpnO5wt00jf0um"
}
],
"images": [
{
"url": "https://i.scdn.co/image/ab67616d0000b27371b964ec832c791e2e880428",
"width": 640,
"height": 640
},
{
"url": "https://i.scdn.co/image/ab67616d00001e0271b964ec832c791e2e880428",
"width": 300,
"height": 300
},
{
"url": "https://i.scdn.co/image/ab67616d0000485171b964ec832c791e2e880428",
"width": 64,
"height": 64
}
],
"album_group": "album",
"type": "album",
"id": "6koCjq9UGVZFa9YjJgCLok",
"available_markets": [
"AD",
"AE",
"AL",
"AR",
"AT",
"AU",
"BA",
"BE",
"BG",
"BH",
"BO",
"BR",
"BY",
"CA",
"CH",
"CL",
"CO",
"CR",
"CY",
"CZ",
"DE",
"DK",
"DO",
"DZ",
"EC",
"EE",
"EG",
"ES",
"FI",
"FR",
"GB",
"GR",
"GT",
"HK",
"HN",
"HR",
"HU",
"ID",
"IE",
"IL",
"IN",
"IS",
"IT",
"JO",
"KW",
"KZ",
"LB",
"LI",
"LT",
"LU",
"LV",
"MA",
"MC",
"MD",
"ME",
"MK",
"MT",
"MX",
"MY",
"NI",
"NL",
"NO",
"NZ",
"OM",
"PA",
"PE",
"PH",
"PL",
"PS",
"PT",
"PY",
"QA",
"RO",
"RS",
"RU",
"SA",
"SE",
"SG",
"SI",
"SK",
"SV",
"TH",
"TN",
"TR",
"TW",
"UA",
"US",
"UY",
"VN",
"XK",
"ZA"
],
"release_date_precision": "day"
}
]
It's quite a long time, but I was able to get the album. I will look at the part that interests me.
available_markets
It seems to represent a country where you can watch. Apparently, it is described in the ISO country code. In other words, it seems that there are places where you cannot listen to it in some countries.
total_tracks
The total number of songs included in the album.
album_type
In the above result, only album
is available, but there are also single
and compilation
, which are used to classify on the Spotify screen.
Next, let's get the music.
Use the album_id
you used earlier. I look at a different album, but the way I get the id doesn't change.
main.py
.
.
.
album_id = 'spotify:album:61Xe5yDSI4IrIqPdYqXxMJ'
results = spotify.album(album_id)['tracks']['items'][1] #Get the second song of the album
print(results)
{
'is_local': False,
'name': 'camn aven',
'external_urls': {
'spotify': 'https://open.spotify.com/track/7gA5tchFTCxarNIt3JGDhD'
},
'uri': 'spotify:track:7gA5tchFTCxarNIt3JGDhD',
'explicit': False,
'preview_url': 'https://p.scdn.co/mp3-preview/84b9a4c8f35fd36b8884d003ee17836265fb47f3?cid=6551068e9be94d4bb07c29cb25fa84f0',
'track_number': 2,
'disc_number': 1,
'href': 'https://api.spotify.com/v1/tracks/7gA5tchFTCxarNIt3JGDhD',
'artists': [
{
'name': 'the cabs',
'external_urls': {
'spotify': 'https://open.spotify.com/artist/5PalnqYJTpnO5wt00jf0um'
},
'uri': 'spotify:artist:5PalnqYJTpnO5wt00jf0um',
'href': 'https://api.spotify.com/v1/artists/5PalnqYJTpnO5wt00jf0um',
'type': 'artist',
'id': '5PalnqYJTpnO5wt00jf0um'}],
'duration_ms': 214000,
'type': 'track',
'id': '7gA5tchFTCxarNIt3JGDhD',
'available_markets': ['JP']
}
We will look at the characteristics of the song using the id of the song obtained from here.
We will use the above track_id. It seems that it can be obtained with an object called audio_features.
main.py
.
.
.
track_id = 'spotify:album:7gA5tchFTCxarNIt3JGDhD'
results = spotify.audio_features(track_id)
print(results)
[
{
'track_href': 'https://api.spotify.com/v1/tracks/7gA5tchFTCxarNIt3JGDhD',
'analysis_url': 'https://api.spotify.com/v1/audio-analysis/7gA5tchFTCxarNIt3JGDhD',
'energy': 0.941,
'liveness': 0.0952,
'tempo': 100.324,
'speechiness': 0.052,
'uri': 'spotify:track:7gA5tchFTCxarNIt3JGDhD',
'acousticness': 8.32e-05,
'instrumentalness': 0.0512,
'time_signature': 3,
'danceability': 0.449,
'key': 5,
'duration_ms': 214000,
'loudness': -2.499,
'valence': 0.538,
'type': 'audio_features',
'id': '7gA5tchFTCxarNIt3JGDhD',
'mode': 1
}
]
I could see more detailed information about the song. There are some items that you are not familiar with even if you use spotify normally. I will post the official reference later, but I will introduce some.
energy This item is evaluated between 0 and 1. It seems that the faster, noisy, and noisy songs are highly evaluated.
time_signature Represents the time signature of a song. The song I extracted, camn aven, has a strange time signature, so I think it's probably not evaluated correctly.
instrumentalness This is an instrument (length of playing time). When it exceeds 0.5, it is close to an instrumental track.
danceability It shows how easy it is to dance. It is a mystery how to evaluate it.
This time, I analyzed it in smaller units such as music. There are quite a lot of hidden parameters, so it would be interesting to try to find a similar band using this.
Get Audio Features for a Track ← Explains the parameters of the song. Get an Album
Recommended Posts