diff --git a/maloja/database/__init__.py b/maloja/database/__init__.py index 45211ed..fb9f48b 100644 --- a/maloja/database/__init__.py +++ b/maloja/database/__init__.py @@ -235,6 +235,8 @@ def get_scrobbles_num(dbconn=None,**keys): result = len(sqldb.get_scrobbles_of_artist(artist=keys['artist'],since=since,to=to,resolve_references=False,dbconn=dbconn)) elif 'track' in keys: result = len(sqldb.get_scrobbles_of_track(track=keys['track'],since=since,to=to,resolve_references=False,dbconn=dbconn)) + elif 'album' in keys: + result = len(sqldb.get_scrobbles_of_album(album=keys['album'],since=since,to=to,resolve_references=False,dbconn=dbconn)) else: result = sqldb.get_scrobbles_num(since=since,to=to,dbconn=dbconn) return result @@ -359,6 +361,21 @@ def get_top_tracks(dbconn=None,**keys): return results +@waitfordb +def get_top_albums(dbconn=None,**keys): + + rngs = ranges(**{k:keys[k] for k in keys if k in ["since","to","within","timerange","step","stepn","trail"]}) + results = [] + + for rng in rngs: + try: + res = get_charts_albums(timerange=rng,dbconn=dbconn)[0] + results.append({"range":rng,"album":res["album"],"scrobbles":res["scrobbles"]}) + except Exception: + results.append({"range":rng,"album":None,"scrobbles":0}) + + return results + @waitfordb def artist_info(dbconn=None,**keys): diff --git a/maloja/database/sqldb.py b/maloja/database/sqldb.py index 36ccc1e..01e2975 100644 --- a/maloja/database/sqldb.py +++ b/maloja/database/sqldb.py @@ -166,7 +166,7 @@ def connection_provider(func): # "artists":list, # "title":string, # "album":{ -# "title":string, +# "albumtitle":string, # "artists":list # }, # "length":None @@ -240,7 +240,7 @@ def albums_db_to_dict(rows,dbconn=None): return [ { "artists":artists[row.id], - "title":row.albtitle, + "albumtitle":row.albtitle, } for row in rows ] @@ -279,8 +279,8 @@ def artist_dict_to_db(info,dbconn=None): def album_dict_to_db(info,dbconn=None): return { - "albtitle":info.get('title'), - "albtitle_normalized":normalize_name(info.get('title')) + "albtitle":info.get('albumtitle'), + "albtitle_normalized":normalize_name(info.get('albumtitle')) } @@ -441,7 +441,7 @@ def get_artist_id(artistname,create_new=True,dbconn=None): @cached_wrapper @connection_provider def get_album_id(albumdict,create_new=True,dbconn=None): - ntitle = normalize_name(albumdict['title']) + ntitle = normalize_name(albumdict['albumtitle']) artist_ids = [get_artist_id(a,dbconn=dbconn) for a in albumdict['artists']] artist_ids = list(set(artist_ids)) diff --git a/maloja/malojauri.py b/maloja/malojauri.py index b18ca9f..e2675cc 100644 --- a/maloja/malojauri.py +++ b/maloja/malojauri.py @@ -28,7 +28,7 @@ def uri_to_internal(keys,forceTrack=False,forceArtist=False,forceAlbum=False,api filterkeys = {"artist":keys.get("artist")} if "associated" in keys: filterkeys["associated"] = True elif type == "album": - filterkeys = {"album":{"artists":keys.getall("artist"),"title":keys.get("title") or keys.get("albumtitle")}} + filterkeys = {"album":{"artists":keys.getall("artist"),"albumtitle":keys.get("title") or keys.get("albumtitle")}} else: filterkeys = {} @@ -98,7 +98,7 @@ def internal_to_uri(keys): elif "album" in keys: for a in keys["album"]["artists"]: urikeys.append("artist",a) - urikeys.append("albumtitle",keys["album"]["title"]) + urikeys.append("albumtitle",keys["album"]["albumtitle"]) #time if "timerange" in keys: diff --git a/maloja/pkg_global/conf.py b/maloja/pkg_global/conf.py index f11d569..164cfa3 100644 --- a/maloja/pkg_global/conf.py +++ b/maloja/pkg_global/conf.py @@ -177,7 +177,7 @@ malojaconfig = Configuration( }, "Database":{ - "album_information_trust":(tp.Choice({'first':"First",'last':"Last"}),"Album Information Authority","first", "Whether to trust the first album information that is sent with a track or update every time a different album is sent"), + "album_information_trust":(tp.Choice({'first':"First",'last':"Last",'majority':"Majority"}), "Album Information Authority","first", "Whether to trust the first album information that is sent with a track or update every time a different album is sent"), "invalid_artists":(tp.Set(tp.String()), "Invalid Artists", ["[Unknown Artist]","Unknown Artist","Spotify"], "Artists that should be discarded immediately"), "remove_from_title":(tp.Set(tp.String()), "Remove from Title", ["(Original Mix)","(Radio Edit)","(Album Version)","(Explicit Version)","(Bonus Track)"], "Phrases that should be removed from song titles"), "delimiters_feat":(tp.Set(tp.String()), "Featuring Delimiters", ["ft.","ft","feat.","feat","featuring"], "Delimiters used for extra artists, even when in the title field"),