Initial commit

This commit is contained in:
2025-08-21 00:25:48 +10:00
commit 309bcf4d73
6 changed files with 167 additions and 0 deletions

29
last_fm.py Normal file
View File

@ -0,0 +1,29 @@
import json
from typing import List
class LastFm:
def __init__(self, credentials_file):
with open(credentials_file, 'r') as f:
credentials = json.loads(f.read())
self.lastfm = pylast.LastFMNetwork(
api_key=credentials['api_kay'],
api_secret=credentials['api_secret']
)
def get_recent_plays(self, username):
self.lastfm.get_user(username).get_recent_tracks(limit=200)
def get_top_artists(self, username: str, min_scrobbles: int) -> List[pylast.TopItem]:
artists = []
page = 0
while True:
artists_page = self.lastfm.get_user(username).get_top_artists()
for artist in artists_page:
if (artist.weight > min_scrobbles):
artists.append(artist)
else:
break