Skip to content

Instantly share code, notes, and snippets.

@Shiroizu
Created November 20, 2022 03:47
Show Gist options
  • Save Shiroizu/8c22cdd51bef31aac7bdf165f5b76b55 to your computer and use it in GitHub Desktop.
Save Shiroizu/8c22cdd51bef31aac7bdf165f5b76b55 to your computer and use it in GitHub Desktop.
# Outputs a list of artists based on rated songs by the user (sorted by total song score).
# Useful for finding more artists to follow.
# Output example
'''
Favs Likes Name URL
10 2 オカメP https://vocadb.net/Ar/87
5 2 まらしぃ https://vocadb.net/Ar/494 (not following)
3 4 *Luna https://vocadb.net/Ar/1620 (not following)
5 1 TaKU.K https://vocadb.net/Ar/21387
4 2 regulus https://vocadb.net/Ar/1315
4 2 ゆよゆっぺ https://vocadb.net/Ar/6 (not following)
...
'''
import requests, time
user_id =
output_length = 20 # 0 to print all
print(f"Checking rated songs by user id {user_id}\n")
unique_artists = {}
page = 1
while True:
params = {"maxResults": "50", "fields": "Artists", "start": str(50 * (page-1))}
r = requests.get(f"https://vocadb.net/api/users/{user_id}/ratedSongs", params)
songs = r.json()["items"]
if not songs:
break
for song in songs:
placeholder = ""
rating = song["rating"]
try:
for artist in song["song"]["artists"]:
if "Producer" in artist["categories"]:
placeholder = artist["name"]
artist_id = artist["artist"]["id"]
if artist_id in unique_artists:
if rating == "Favorite":
unique_artists[artist_id][1] += 1
elif rating == "Like":
unique_artists[artist_id][2] += 1
else:
if rating == "Favorite":
unique_artists[artist_id] = [artist["artist"]["name"], 1, 0]
elif rating == "Like":
unique_artists[artist_id] = [artist["artist"]["name"], 0, 1]
except KeyError:
print(f"Custom artist entry '{placeholder}' on S/{song['song']['id']}")
page += 1
time.sleep(1)
unique_artists_with_score = []
for ar_id in unique_artists:
name, favs, likes = [unique_artists[ar_id][0], unique_artists[ar_id][1], unique_artists[ar_id][2]]
score = favs * 3 + likes * 2
unique_artists_with_score.append([name, favs, likes, score, ar_id])
unique_artists_with_score.sort(key = lambda x: x[3], reverse=True)
followed_artists = []
page = 1
while True:
params = {"maxResults": "50", "start": str(50 * (page-1))}
r = requests.get(f"https://vocadb.net/api/users/{user_id}/followedArtists", params)
artists = r.json()["items"]
if not artists:
break
for artist in artists:
followed_artists.append(artist["artist"]["id"])
page += 1
time.sleep(1)
print("\n Favs Likes Name URL")
if not output_length:
output_length = None
for ar in unique_artists_with_score[:output_length]:
follow_msg = "(not following)"
name, favs, likes, score, ar_id = ar
if ar_id in followed_artists:
follow_msg = ""
print(f" {str(favs).rjust(3, ' ')} {str(likes).rjust(3, ' ')} {name.ljust(20, ' ')} https://vocadb.net/Ar/{ar_id} {follow_msg}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment