From feaccf1259f103b6c77796ef256b5b113d8a5bcd Mon Sep 17 00:00:00 2001 From: krateng Date: Thu, 30 Mar 2023 19:57:56 +0200 Subject: [PATCH 1/2] Added album title rule --- maloja/cleanup.py | 8 +++++++- maloja/database/__init__.py | 2 ++ maloja/proccontrol/tasks/import_scrobbles.py | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) 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..e64cca4 100644 --- a/maloja/database/__init__.py +++ b/maloja/database/__init__.py @@ -144,6 +144,8 @@ 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()) 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 },'') From 8cb446f1fb2cef70f6e89b574bce9dbf9426a89c Mon Sep 17 00:00:00 2001 From: krateng Date: Thu, 30 Mar 2023 20:39:27 +0200 Subject: [PATCH 2/2] Fixed scrobbling with incomplete album information --- maloja/database/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/maloja/database/__init__.py b/maloja/database/__init__.py index e64cca4..0869696 100644 --- a/maloja/database/__init__.py +++ b/maloja/database/__init__.py @@ -148,6 +148,10 @@ def rawscrobble_to_scrobbledict(rawscrobble, fix=True, client=None): 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 = {