From eb9d29686b489d769ae2a50355e9d8017f786317 Mon Sep 17 00:00:00 2001 From: krateng Date: Mon, 10 Jan 2022 04:51:58 +0100 Subject: [PATCH] Ported reasonable changes from the eldritch branch --- maloja/database/sqldb.py | 12 +++--------- maloja/upgrade.py | 4 +++- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/maloja/database/sqldb.py b/maloja/database/sqldb.py index 0b55fab..677635d 100644 --- a/maloja/database/sqldb.py +++ b/maloja/database/sqldb.py @@ -138,7 +138,6 @@ def scrobble_dict_to_db(info): "timestamp":info['time'], "origin":info['origin'], "duration":info['duration'], - "extra":info['extra'], "track_id":get_track_id(info['track']) } @@ -146,7 +145,7 @@ def track_dict_to_db(info): return { "title":info['title'], "title_normalized":normalize_name(info['title']), - "length":info['length'] + "length":info.get('length') } def artist_dict_to_db(info): @@ -175,10 +174,7 @@ def add_scrobbles(scrobbleslist): with engine.begin() as conn: for op in ops: - try: - conn.execute(op) - except: - pass + conn.execute(op) ### these will 'get' the ID of an entity, creating it if necessary @@ -214,9 +210,7 @@ def get_track_id(trackdict): with engine.begin() as conn: op = DB['tracks'].insert().values( - title=trackdict['title'], - title_normalized=ntitle, - length=trackdict['length'] + **track_dict_to_db(trackdict) ) result = conn.execute(op) track_id = result.inserted_primary_key[0] diff --git a/maloja/upgrade.py b/maloja/upgrade.py index 4257db8..7126131 100644 --- a/maloja/upgrade.py +++ b/maloja/upgrade.py @@ -32,8 +32,9 @@ def upgrade_db(callback_add_scrobbles): scrobblefiles = [f for f in os.listdir(oldfolder) if f.endswith(".tsv")] if len(scrobblefiles) > 0: print(col['yellow']("Upgrading v2 Database to v3 Database. This could take a while...")) + idx = 0 for sf in scrobblefiles: - print(f"\tImporting from old tsv scrobble file: {sf}") + idx += 1 if re.match(r"[0-9]+_[0-9]+\.tsv",sf): origin = 'legacy' elif sf == "lastfmimport.tsv": @@ -44,6 +45,7 @@ def upgrade_db(callback_add_scrobbles): from doreah import tsv scrobbles = tsv.parse(os.path.join(oldfolder,sf),"int","string","string","string","string",comments=False) scrobblelist = [] + print(f"\tImporting from {sf} ({idx}/{len(scrobblefiles)}) - {len(scrobbles)} Scrobbles") for scrobble in scrobbles: timestamp, artists, title, album, duration = scrobble if album in ('-',''): album = None