<jupyter_start><jupyter_text>Artist's Look-a-LikeThis notebook retrieve Motor's artists genre and other related attribute of his/her works.  Attributes quereied are primary from Spotify API.  These attributes are then fed into , which ultimate identify other similar artists.  0.) Initialize Parameters  a. Libraries<jupyter_code># API Client file located locally in ./client/hausgemacht_SpotiPy.py
from hausgemachtspotipy.hausgemacht_SpotiPy import *

import pandas as pd
import datetime
import math<jupyter_output><empty_output><jupyter_text>b. Credentials<jupyter_code># Spotify
client_id = "cd1845f23d914228b14f6bed139ee594"
client_secret = ""<jupyter_output><empty_output><jupyter_text>--- 1.) Create connectiont to Spotify APICalling API Client Class, `hausgemacht Spotipy`.<jupyter_code># Calling API Client Class, `SpotifyAPI`
sp = SpotifyAPI(client_id, client_secret)<jupyter_output><empty_output><jupyter_text>--- 2.) Artists  a. Import Motor's Artists<jupyter_code>data = [
    ["03uMw43UVu9MsQCcHVSGjX", "<NAME>"], 
    ["3mmI5HKArDwgggj4j0aJyC", "BHZ"], 
    ["3ea4XDPCrAm68rpImApb94", "<NAME>"], 
    ["1cIilB8ckONPBhSG6IvxSu", "ZUSTRA"], 
    ["0SCFEgshN89tlgOPM7lbSB", "<NAME>"], 
    ["6u79NimWxdl5RXgDrnGeqk", "<NAME> & Palast Orchester"], 
    ["78TTCmh2koperK5NBn7DgR", "102 BOYZ"], 
    ["13Vka7xGjRHhIOGzvomJZd", "Bae.con"], 
    ["3IFgjVPT8yeB4UnJCWOpZA", "Teenage Mutants"], 
    ["7FvEqUihbJfx5vpfGd1OLz", "<NAME>"], 
    ["4AScySQVdebovwUwTVWzhN", "Inoffiziell.Goldenboy"], 
    ["0kQfuEQhZ0BxRSM5TyKolM", "Kellermensch"], 
    ["7ctR7ruX0kn0gUrmbfTzL1", "<NAME>"]
]

df_artists = pd.DataFrame(data, columns=["artist_id", "artist_name"])<jupyter_output><empty_output><jupyter_text>b. I.D Artist's Genres<jupyter_code>genres = []

for id in df_artists["artist_id"]:
    artist_resp = sp.get_artist(id)
    genres.append(artist_resp["genres"])

df_artists["artist_genres"] = genres

# Export dataframe as ZIP-CSV file
compression_opts = dict(method='zip', archive_name='out_artists.csv')  
df_artists.to_csv('./results/out_artists.zip', index=False, compression=compression_opts)<jupyter_output>https://api.spotify.com/v1/artists/03uMw43UVu9MsQCcHVSGjX
https://api.spotify.com/v1/artists/3mmI5HKArDwgggj4j0aJyC
https://api.spotify.com/v1/artists/3ea4XDPCrAm68rpImApb94
https://api.spotify.com/v1/artists/1cIilB8ckONPBhSG6IvxSu
https://api.spotify.com/v1/artists/0SCFEgshN89tlgOPM7lbSB
https://api.spotify.com/v1/artists/6u79NimWxdl5RXgDrnGeqk
https://api.spotify.com/v1/artists/78TTCmh2koperK5NBn7DgR
https://api.spotify.com/v1/artists/13Vka7xGjRHhIOGzvomJZd
https://api.spotify.com/v1/artists/3IFgjVPT8yeB4UnJCWOpZA
https://api.spotify.com/v1/artists/7FvEqUihbJfx5vpfGd1OLz
https://api.spotify.com/v1/artists/4AScySQVdebovwUwTVWzhN
https://api.spotify.com/v1/artists/0kQfuEQhZ0BxRSM5TyKolM
https://api.spotify.com/v1/artists/7ctR7ruX0kn0gUrmbfTzL1<jupyter_text>--- 3.) Albums  a. Populate Artist's AlbumsList all albums of an artist via artist's Spotify ID<jupyter_code>row_albums = []

for index, row_artist in df_artists.iterrows():
    
    albums = sp.get_artist_albums(row_artist['artist_id'])

    # --- #HardCode "20" for max. number of rows returned by Spotify 
    if albums["total"] > 20:
        albums_cnt = 20
    else:
        albums_cnt = albums["total"]
    
    for i in range(albums_cnt):
        artist_id = row_artist['artist_id']
        album_id = albums["items"][i]["id"]
        album_release_date = albums["items"][i]["release_date"]
        album_name = albums["items"][i]["name"]
        row_albums.append([artist_id, album_id, album_release_date, album_name])



df_albums = pd.DataFrame(row_albums, columns=["artist_id", "album_id", "album_release_date", "album_name"])
df_albums.to_clipboard(sep = ",", index=False)

compression_opts = dict(method='zip', archive_name='out_albums.csv')  
df_albums.to_csv('./results/out_albums.zip', index=False, compression=compression_opts)<jupyter_output>https://api.spotify.com/v1/artists/03uMw43UVu9MsQCcHVSGjX/albums
https://api.spotify.com/v1/artists/3mmI5HKArDwgggj4j0aJyC/albums
https://api.spotify.com/v1/artists/3ea4XDPCrAm68rpImApb94/albums
https://api.spotify.com/v1/artists/1cIilB8ckONPBhSG6IvxSu/albums
https://api.spotify.com/v1/artists/0SCFEgshN89tlgOPM7lbSB/albums
https://api.spotify.com/v1/artists/6u79NimWxdl5RXgDrnGeqk/albums
https://api.spotify.com/v1/artists/78TTCmh2koperK5NBn7DgR/albums
https://api.spotify.com/v1/artists/13Vka7xGjRHhIOGzvomJZd/albums
https://api.spotify.com/v1/artists/3IFgjVPT8yeB4UnJCWOpZA/albums
https://api.spotify.com/v1/artists/7FvEqUihbJfx5vpfGd1OLz/albums
https://api.spotify.com/v1/artists/4AScySQVdebovwUwTVWzhN/albums
https://api.spotify.com/v1/artists/0kQfuEQhZ0BxRSM5TyKolM/albums
https://api.spotify.com/v1/artists/7ctR7ruX0kn0gUrmbfTzL1/albums<jupyter_text>--- 4.) Tracks  a. List Tracks per AlbumLIst all tracks of an album via album's Spotify ID<jupyter_code>row_tracks = []

for index, row_album in df_albums.iterrows():

    tracks = sp.get_album_tracks(row_album['album_id'])

    # --- #HardCode "20" for max. number of rows returned by Spotify 
    if tracks["total"] > 20:
        track_cnt = 20
    else:
        track_cnt = tracks["total"]

    for i in range(track_cnt):
        album_id = row_album['album_id']
        track_id = tracks["items"][i]["id"]
        track_num = tracks["items"][i]["track_number"]
        track_name = tracks["items"][i]["name"]
        # track_duration = tracks["items"][i]["duration_ms"]
        track_duration = datetime.timedelta(milliseconds = tracks["items"][i]["duration_ms"])
        row_tracks.append([album_id, track_id, track_num, track_name, track_duration])


df_tracks = pd.DataFrame(row_tracks, columns=["album_id", "track_id", "track_num", "track_name", "track_duration"])
df_tracks.to_clipboard(sep = ",", index=False)

# compression_opts = dict(method='zip', archive_name='out_tracks.csv')  
# df_tracks.to_csv('./results/out_tracks.zip', index=False, compression=compression_opts)<jupyter_output>https://api.spotify.com/v1/albums/0toymsLJ0xNYQExQf1jKeN/tracks
https://api.spotify.com/v1/albums/4r8HtFE8TGFtqEpMV7mU60/tracks
https://api.spotify.com/v1/albums/3hslHc7Pmv3PyuUZVcMbZG/tracks
https://api.spotify.com/v1/albums/1GJ3SzkwuktHSSSIb3zThC/tracks
https://api.spotify.com/v1/albums/2GcpfpIBh1EbZYyvqYMeAI/tracks
https://api.spotify.com/v1/albums/4ieLwljBoO1svXM5K6UtzA/tracks
https://api.spotify.com/v1/albums/6k8uz0zLnKhSWA1jPbrKvv/tracks
https://api.spotify.com/v1/albums/63OtMpfcpIe7FiXY2Cpb4v/tracks
https://api.spotify.com/v1/albums/4cSGagidZg8OfE9TY8mnP9/tracks
https://api.spotify.com/v1/albums/288HbeEv8cuamJikA3PPrN/tracks
https://api.spotify.com/v1/albums/288MFsW7Tq858DT9VKt2tg/tracks
https://api.spotify.com/v1/albums/7hIkxeYznFQftpneL5H9ZZ/tracks
https://api.spotify.com/v1/albums/6fWpiDZCwdITgoJDx8aqXT/tracks
https://api.spotify.com/v1/albums/2FhvMcP1mm2SSp3q5htGtp/tracks
https://api.spotify.com/v1/albums/3XQhpRdAkLI9WbFfO8h6AU/tracks
https://api.spotify.com/v1/albums/51WdYo[...]<jupyter_text>b. Query track's Audio Features<jupyter_code>danceability = []
energy = []
key = []
loudness = []
speechiness = []
acousticness = []
instrumentalness = []
liveness = []
valence = []
tempo = []

for id in df_tracks["track_id"]:
    track_resp = sp.get_track_features(id)
    danceability.append( track_resp["danceability"] )
    energy.append( track_resp["energy"] )
    key.append( track_resp["key"] )
    loudness.append( track_resp["loudness"] )
    speechiness.append( track_resp["speechiness"] )
    acousticness.append( track_resp["acousticness"] )
    instrumentalness.append( track_resp["instrumentalness"] )
    liveness.append( track_resp["liveness"] )
    valence.append( track_resp["valence"] )
    tempo.append( track_resp["tempo"] )

df_tracks["danceability"] = danceability
df_tracks["energy"] = energy
df_tracks["key"] = key
df_tracks["loudness"] = loudness
df_tracks["speechiness"] = speechiness
df_tracks["acousticness"] = acousticness
df_tracks["instrumentalness"] = instrumentalness
df_tracks["liveness"] = liveness
df_tracks["valence"] = valence
df_tracks["tempo"] = tempo

compression_opts = dict(method='zip', archive_name='out_tracks.csv')  
df_tracks.to_csv('./results/out_tracks.zip', index=False, compression=compression_opts)<jupyter_output>com/v1/audio-features/2fNSDlX6Fa8adWskDUfKae
https://api.spotify.com/v1/audio-features/469TsPGP0T3DGokNo6Vdgq
https://api.spotify.com/v1/audio-features/235Hq2mOb7ezbjqTlmNRKY
https://api.spotify.com/v1/audio-features/2pfMSI2iQddJeePcui2drG
https://api.spotify.com/v1/audio-features/36r73EpuviBetBuQeF5kvk
https://api.spotify.com/v1/audio-features/3Dg5wHk8yf0XvG1ROugtUK
https://api.spotify.com/v1/audio-features/4CCyxM5XX8fFbhH7Jp9S7w
https://api.spotify.com/v1/audio-features/2Ee5Trz9wwLffTwRn8jWqJ
https://api.spotify.com/v1/audio-features/1so0272NRu2ZYUTb3fjZC6
https://api.spotify.com/v1/audio-features/3PW5xknWSgWVMAKIH7fcwC
https://api.spotify.com/v1/audio-features/22YxC3ytBdBfQ7to3ABvFr
https://api.spotify.com/v1/audio-features/53vcRE2LvvyiYTVI94APFZ
https://api.spotify.com/v1/audio-features/3IzygbKjMcooi8tz7lTLKa
https://api.spotify.com/v1/audio-features/2zo2pEbYQLJOwWUbBUM6LP
https://api.spotify.com/v1/audio-features/3YsuqzCeNs1xK2xO59XGaN
https://api.spotify.com/v1/audio-features/0iy[...]
{'fraction_non_alphanumeric': 0.14179666487358794, 'fraction_numerical': 0.04098977945131791, 'mean_word_length': 5.697406340057637, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 37, 'https://': 57, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '358230', 'license': 'MIT', 'n_tokens_mistral': 4177, 'n_tokens_neox': 3962, 'n_words': 411, 'path': 'dev/Spotify_Scraper_08_Artist_Album_Tracks_Attributes.ipynb', 'repo_name': 'rtheman/hausgemachtspotipy', 'size': '9323'}