Browse Source

refactoring...

ytmgr-py
Daniel Martinez 1 year ago
parent
commit
f607be11c8
  1. 12
      currents.py

12
currents.py

@ -48,16 +48,13 @@ for song in fullpath:
data = new_songs_dict.values()
artists = []
for song in data:
artist = song[1]
artists.append(artist)
artists.append(song[1])
unique_artists = set(artists)
##grab top track info from last.fm, create lists
top_songs = []
for artist in unique_artists:
uri_artist = artist.replace(" ", "%20")
uri_artist.replace("&", "%26")
last_url = "http://ws.audioscrobbler.com/2.0/?method="+"artist.gettoptracks&artist="+uri_artist+"&api_key="+str(config["last_fm"]["api_key"])+"&format=json&limit="+str(config["currents"]["max_artist_tracks"])
r = requests.get(url=last_url)
lastfm_params = {'method': "artist.gettoptracks", "artist": artist, "api_key": config["last_fm"]["api_key"], "format": "json", "limit": config["currents"]["max_artist_tracks"]}
r = requests.get('http://ws.audioscrobbler.com/2.0/', params=lastfm_params)
if "error" in r.text:
continue
tracks_dict = json.loads(r.text)
@ -87,5 +84,4 @@ with open(os.path.join(currents_dir, playlist_name), 'w') as play:
play.write("#EXTM3U \n")
for id in id_list:
data = new_songs_dict.get(id)
path = data[3]
play.write(path)
play.write(data[3])
Loading…
Cancel
Save