<jupyter_start><jupyter_text>Collecting data from Deezer<jupyter_code># importing required packaegs
import requests
import json
import pandas as pd

url = "https://api.deezer.com/genre/0"

headers = {
    'x-rapidapi-host': "deezerdevs-deezer.p.rapidapi.com",
    'x-rapidapi-key': "<API-Key>"
    }

response = requests.request("GET", url, headers=headers)
# response text from URL
response.text
# testing the URL for artist data
url = "https://api.deezer.com/search/artist?q=<NAME>"

headers = {
    'x-rapidapi-host': "deezerdevs-deezer.p.rapidapi.com",
    'x-rapidapi-key': "<KEY>"
    }

response = requests.request("GET", url, headers=headers)
response.text
# obtaining 5 artists data along with artist ID
top_5_artists=[]
for i in ['<NAME>','<NAME>','<NAME>','Drake','The Weeknd']:
    url = "https://api.deezer.com/search/artist?q="+i
    response = requests.request("GET", url, headers=headers)
    top_5_artists.append(response.text)
# converting string to json format
for i in range(len(top_5_artists)):
    test_1 = json.loads(top_5_artists[i])
    top_5_artists[i]= test_1
# collecting the artist IDs to to download songs data for that ID
for i in top_5_artists:
    for j in i['data']:
        print(j['id'])
        print(j['name'])
        print()
# collected artist ID from Deezer
selena = [292185]
Adam = [4404332,74319652]
Justin = [288166,67282302]
Drake = [246791,5215664]
weekend = [4050205]
# collecting data of artist which contain top 50 songs along with URL to download the song
selena_songs=[]
for i in selena:
    url = "https://api.deezer.com/artist/"+str(i)+"/top?limit=50"
    response = requests.request("GET", url, headers=headers)
    selena_songs.append(response.text)

for i in range(len(selena_songs)):
    test_1 = json.loads(selena_songs[i])
    selena_songs[i]= test_1

selena_artists_df = pd.DataFrame()
for i in selena_songs:
    if 'error' not in i:
        for j in i['data']:
            if j['artist']['name'] == '<NAME>':
                selena_artists_df = selena_artists_df.append(j, ignore_index=True)

selena_artists_df.to_pickle("Selena.pkl")                
# collecting data of artist which contain top 50 songs along with URL to download the song
Adam_songs=[]
for i in Adam:
    url = "https://api.deezer.com/artist/"+str(i)+"/top?limit=50"
    response = requests.request("GET", url, headers=headers)
    Adam_songs.append(response.text)

for i in range(len(Adam_songs)):
    test_1 = json.loads(Adam_songs[i])
    Adam_songs[i]= test_1

Adam_artists_df = pd.DataFrame()
for i in Adam_songs:
    if 'error' not in i:
        for j in i['data']:
            if j['artist']['name'] == '<NAME>':
                Adam_artists_df = Adam_artists_df.append(j, ignore_index=True)

Adam_artists_df.to_pickle('adam.pkl')
# collecting data of artist which contain top 50 songs along with URL to download the song
Justin_songs=[]
for i in Justin:
    url = "https://api.deezer.com/artist/"+str(i)+"/top?limit=50"
    response = requests.request("GET", url, headers=headers)
    Justin_songs.append(response.text)

for i in range(len(Justin_songs)):
    test_1 = json.loads(Justin_songs[i])
    Justin_songs[i]= test_1

Justin_artists_df = pd.DataFrame()
for i in Justin_songs:
    if 'error' not in i:
        for j in i['data']:
            if j['artist']['name'] == '<NAME>':
                Justin_artists_df = Justin_artists_df.append(j, ignore_index=True)

Justin_artists_df.to_pickle('Justin.pkl')
# collecting data of artist which contain top 50 songs along with URL to download the song
Drake_songs=[]
for i in Drake:
    url = "https://api.deezer.com/artist/"+str(i)+"/top?limit=50"
    response = requests.request("GET", url, headers=headers)
    Drake_songs.append(response.text)

for i in range(len(Drake_songs)):
    test_1 = json.loads(Drake_songs[i])
    Drake_songs[i]= test_1

Drake_artists_df = pd.DataFrame()
for i in Drake_songs:
    if 'error' not in i:
        for j in i['data']:
            if j['artist']['name'] == 'Drake':
                Drake_artists_df = Drake_artists_df.append(j, ignore_index=True)

Drake_artists_df.to_pickle('Drake.pkl')
# collecting data of artist which contain top 50 songs along with URL to download the song
weekend_songs=[]
for i in weekend:
    url = "https://api.deezer.com/artist/"+str(i)+"/top?limit=50"
    response = requests.request("GET", url, headers=headers)
    weekend_songs.append(response.text)

for i in range(len(weekend_songs)):
    test_1 = json.loads(weekend_songs[i])
    weekend_songs[i]= test_1

weekend_artists_df = pd.DataFrame()
for i in weekend_songs:
    if 'error' not in i:
        for j in i['data']:
            if j['artist']['name'] == 'The Weeknd':
                weekend_artists_df = weekend_artists_df.append(j, ignore_index=True)

weekend_artists_df.to_pickle('Weeknd.pkl')
# creating nameID column to recognize the song with ID and name
selena_artists_df.insert(0, 'song_id','<NAME>_' + selena_artists_df['id'].astype(int).astype(str))
selena_artists_df.insert(1, 'Artist_Name', '<NAME>')
# creating nameID column to recognize the song with ID and name
Adam_artists_df.insert(0, 'song_id','<NAME>_' + Adam_artists_df['id'].astype(int).astype(str))
Adam_artists_df.insert(1, 'Artist_Name', '<NAME>')
# creating nameID column to recognize the song with ID and name
Justin_artists_df.insert(0, 'song_id','<NAME>_' + Justin_artists_df['id'].astype(int).astype(str))
Justin_artists_df.insert(1, 'Artist_Name', '<NAME>')
# creating nameID column to recognize the song with ID and name
Drake_artists_df.insert(0, 'song_id','Drake_' + Drake_artists_df['id'].astype(int).astype(str))
Drake_artists_df.insert(1, 'Artist_Name', 'Drake')
# creating nameID column to recognize the song with ID and name
weekend_artists_df.insert(0, 'song_id','The Weeknd_' + weekend_artists_df['id'].astype(int).astype(str))
weekend_artists_df.insert(1, 'Artist_Name', 'The Weeknd')
# concatinating all the artists data in 1 file for further work to download the songs
artist_df = pd.concat([selena_artists_df,Adam_artists_df,Justin_artists_df,Drake_artsists_df,weekend_artists_df])
# converting the dataframe to pickle file for further analysis
artist_df.to_pickle("all_artists.pkl")<jupyter_output><empty_output><jupyter_text>Top 50 or less songs for each singer details are written to pickle file for further processing and downloading the songs for voice processing. In total of 187 songs from Deezer has been collected  Downloading Audio files from Deezer collected data<jupyter_code># importing required packaegs
import pandas as pd
import json
import urllib.request as req
from tqdm import tqdm
artist_df = pd.read_pickle('Deezer Data/artists.pkl')
artist_df.shape
artist_df.head()
# downloading songs from a url and saving in mp3 format
artist_mp4_mapping = dict(zip(artist_df['song_id'], artist_df['preview']))
for idx, url in tqdm(artist_mp4_mapping.items()):
    try:
        download_path = 'Deezer Data/artist/mp3/' + str(idx) +'.mp3'
        req.urlretrieve(url, download_path)
    except:
        print('Error ocuured for Id:', idx)<jupyter_output>100%|██████████| 189/189 [01:30<00:00,  2.08it/s]
{'fraction_non_alphanumeric': 0.13126491646778043, 'fraction_numerical': 0.01909307875894988, 'mean_word_length': 4.484218629715166, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 23, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '474743', 'license': 'MIT', 'n_tokens_mistral': 2661, 'n_tokens_neox': 2546, 'n_words': 623, 'path': 'notebooks/Deezer data collection and audio file download.ipynb', 'repo_name': 'npulagam/Music_Classifier_Singer_Identifier', 'size': '7246'}