Ported reasonable changes from the eldritch branch

This commit is contained in:
krateng 2022-01-10 04:51:58 +01:00
parent b50afe70ea
commit eb9d29686b
2 changed files with 6 additions and 10 deletions

View File

@ -138,7 +138,6 @@ def scrobble_dict_to_db(info):
"timestamp":info['time'], "timestamp":info['time'],
"origin":info['origin'], "origin":info['origin'],
"duration":info['duration'], "duration":info['duration'],
"extra":info['extra'],
"track_id":get_track_id(info['track']) "track_id":get_track_id(info['track'])
} }
@ -146,7 +145,7 @@ def track_dict_to_db(info):
return { return {
"title":info['title'], "title":info['title'],
"title_normalized":normalize_name(info['title']), "title_normalized":normalize_name(info['title']),
"length":info['length'] "length":info.get('length')
} }
def artist_dict_to_db(info): def artist_dict_to_db(info):
@ -175,10 +174,7 @@ def add_scrobbles(scrobbleslist):
with engine.begin() as conn: with engine.begin() as conn:
for op in ops: for op in ops:
try: conn.execute(op)
conn.execute(op)
except:
pass
### these will 'get' the ID of an entity, creating it if necessary ### 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: with engine.begin() as conn:
op = DB['tracks'].insert().values( op = DB['tracks'].insert().values(
title=trackdict['title'], **track_dict_to_db(trackdict)
title_normalized=ntitle,
length=trackdict['length']
) )
result = conn.execute(op) result = conn.execute(op)
track_id = result.inserted_primary_key[0] track_id = result.inserted_primary_key[0]

View File

@ -32,8 +32,9 @@ def upgrade_db(callback_add_scrobbles):
scrobblefiles = [f for f in os.listdir(oldfolder) if f.endswith(".tsv")] scrobblefiles = [f for f in os.listdir(oldfolder) if f.endswith(".tsv")]
if len(scrobblefiles) > 0: if len(scrobblefiles) > 0:
print(col['yellow']("Upgrading v2 Database to v3 Database. This could take a while...")) print(col['yellow']("Upgrading v2 Database to v3 Database. This could take a while..."))
idx = 0
for sf in scrobblefiles: 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): if re.match(r"[0-9]+_[0-9]+\.tsv",sf):
origin = 'legacy' origin = 'legacy'
elif sf == "lastfmimport.tsv": elif sf == "lastfmimport.tsv":
@ -44,6 +45,7 @@ def upgrade_db(callback_add_scrobbles):
from doreah import tsv from doreah import tsv
scrobbles = tsv.parse(os.path.join(oldfolder,sf),"int","string","string","string","string",comments=False) scrobbles = tsv.parse(os.path.join(oldfolder,sf),"int","string","string","string","string",comments=False)
scrobblelist = [] scrobblelist = []
print(f"\tImporting from {sf} ({idx}/{len(scrobblefiles)}) - {len(scrobbles)} Scrobbles")
for scrobble in scrobbles: for scrobble in scrobbles:
timestamp, artists, title, album, duration = scrobble timestamp, artists, title, album, duration = scrobble
if album in ('-',''): album = None if album in ('-',''): album = None