<jupyter_start><jupyter_text>Adquisición de canciones mediante API<jupyter_code>import requests
import json
#TODO: Ignorar las canciones que no tienen lyrics
#TODO: Extraer genero musical (se puede extraer el sub-genero )
#Referencia de como usar el api de music match https://youtu.be/WFRzKmpepj4
artist= ['enjambre','slipknot','interpol']
lyric = ['madrugada','Nero forte','c mere']

def get_lyric(song_name,artist):
    base_url= 'https://api.musixmatch.com/ws/1.1/'
    api_key = "&apikey=3950aca40989ee9f7d05723278e3fdfd"
    q_track = '&q_track='
    q_artist = '&q_artist='
    lyric_matcher = 'matcher.lyrics.get?format=json&callback=callback' #nos permitirá hacer la búsqueda de la canción por artista y título 
    data = requests.get(base_url+lyric_matcher+q_track+ song_name +q_artist+ artist +api_key)
    data = data.json() #lee la información en json (cuidado con jsonp, se tiene que hacer mayor procesamiento)
    data = data['message']['body']['lyrics']['lyrics_body'].replace('******* This Lyrics is NOT for Commercial use *******', '')
    data = data.replace('(1409620732275)',' ')
    return data
  
def get_explicit_label(song_name,artist):
    base_url= 'https://api.musixmatch.com/ws/1.1/'
    api_key = "&apikey=3950aca40989ee9f7d05723278e3fdfd"
    q_track = '&q_track='
    q_artist = '&q_artist='
    lyric_matcher = 'matcher.lyrics.get?format=json&callback=callback' #nos permitirá hacer la búsqueda de la canción por artista y título 
    data = requests.get(base_url+lyric_matcher+q_track+ song_name +q_artist+ artist +api_key)
    data = data.json()
    data = data['message']['body']['lyrics']['explicit']
    return data

def get_music_gender(song_name,artist):
    base_url= 'https://api.musixmatch.com/ws/1.1/'
    api_key = "&apikey=3950aca40989ee9f7d05723278e3fdfd"
    q_track = '&q_track='
    q_artist = '&q_artist='
    track_matcher = 'matcher.track.get?format=json&callback=callback'
    data = requests.get(base_url + track_matcher + q_artist + artist + q_track + song_name + api_key)
    data = data.json()
    data = data['message']['body']['track']['primary_genres']['music_genre_list'][0]['music_genre']['music_genre_name']
    return data

data=[]
for i in range(len(lyric)):
    data.append(get_lyric(lyric[i],artist[i]))
    data.append(get_explicit_label(lyric[i],artist[i]))
    data.append(get_music_gender(lyric[i],artist[i]))

for j in data:
    print(j)
  #data = requests.get('https://api.musixmatch.com/ws/1.1/matcher.lyrics.get?format=json&callback=callback&q_track=before%20I%20forget%20&q_artist=slipknot&apikey=3950aca40989ee9f7d05723278e3fdfd')
#get_music_gender(lyric[0],artist[0])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1460590212924916, 'fraction_numerical': 0.04146432573776616, 'mean_word_length': 5.563725490196078, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '662139', 'license': 'MIT', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1038, 'n_words': 178, 'path': 'Lyrics_API_Lib.ipynb', 'repo_name': 'Hecramco/NLP_Violencia-en-musica-', 'size': '2677'}