diff --git a/maloja/cleanup.py b/maloja/cleanup.py index 9095114..62120b9 100644 --- a/maloja/cleanup.py +++ b/maloja/cleanup.py @@ -26,6 +26,7 @@ class CleanerAgent: self.rules_belongtogether = [r[1] for r in rawrules if r[0]=="belongtogether"] self.rules_notanartist = [r[1] for r in rawrules if r[0]=="notanartist"] self.rules_replacetitle = {r[1].lower():r[2] for r in rawrules if r[0]=="replacetitle"} + self.rules_replacealbumtitle = {r[1].lower():r[2] for r in rawrules if r[0]=="replacealbumtitle"} self.rules_replaceartist = {r[1].lower():r[2] for r in rawrules if r[0]=="replaceartist"} self.rules_ignoreartist = [r[1].lower() for r in rawrules if r[0]=="ignoreartist"] self.rules_addartists = {r[2].lower():(r[1].lower(),r[3]) for r in rawrules if r[0]=="addartists"} @@ -188,9 +189,14 @@ class CleanerAgent: if st in title.lower(): artists += self.rules_artistintitle[st].split("␟") return (title,artists) + def parseAlbumtitle(self,t): + if t.strip().lower() in self.rules_replacealbumtitle: + return self.rules_replacealbumtitle[t.strip().lower()] + t = t.replace("[","(").replace("]",")") - + t = t.strip() + return t def flatten(lis): diff --git a/maloja/database/__init__.py b/maloja/database/__init__.py index 9d437a1..0869696 100644 --- a/maloja/database/__init__.py +++ b/maloja/database/__init__.py @@ -144,8 +144,14 @@ def rawscrobble_to_scrobbledict(rawscrobble, fix=True, client=None): scrobbleinfo['track_artists'],scrobbleinfo['track_title'] = cla.fullclean(scrobbleinfo['track_artists'],scrobbleinfo['track_title']) if scrobbleinfo.get('album_artists'): scrobbleinfo['album_artists'] = cla.parseArtists(scrobbleinfo['album_artists']) + if scrobbleinfo.get("album_title"): + scrobbleinfo['album_title'] = cla.parseAlbumtitle(scrobbleinfo['album_title']) scrobbleinfo['scrobble_time'] = scrobbleinfo.get('scrobble_time') or int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp()) + # if we send [] as albumartists, it means various + # if we send nothing, the scrobbler just doesnt support it and we assume track artists + if 'album_artists' not in scrobbleinfo: + scrobbleinfo['album_artists'] = scrobbleinfo.get('track_artists') # processed info to internal scrobble dict scrobbledict = { diff --git a/maloja/proccontrol/tasks/import_scrobbles.py b/maloja/proccontrol/tasks/import_scrobbles.py index 376591d..b34ccc0 100644 --- a/maloja/proccontrol/tasks/import_scrobbles.py +++ b/maloja/proccontrol/tasks/import_scrobbles.py @@ -309,6 +309,8 @@ def parse_lastfm(inputf): 'scrobble_time': int(datetime.datetime.strptime( time + '+0000', "%d %b %Y %H:%M%z" + # lastfm exports have time in UTC + # some old imports might have the wrong time here! ).timestamp()), 'scrobble_duration':None },'')