mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Ported reasonable changes from the eldritch branch
This commit is contained in:
parent
b50afe70ea
commit
eb9d29686b
@ -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]
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user