mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Implemented extra information field in DB
This commit is contained in:
parent
6fc3a9cbf8
commit
bd29c1e1ba
@ -68,10 +68,10 @@ DBTABLES = {
|
||||
|
||||
DB = {}
|
||||
|
||||
|
||||
engine = sql.create_engine(f"sqlite:///{data_dir['scrobbles']('malojadb.sqlite')}", echo = False)
|
||||
meta = sql.MetaData()
|
||||
|
||||
# create table definitions
|
||||
for tablename in DBTABLES:
|
||||
|
||||
DB[tablename] = sql.Table(
|
||||
@ -81,8 +81,10 @@ for tablename in DBTABLES:
|
||||
**DBTABLES[tablename]['extrakwargs']
|
||||
)
|
||||
|
||||
# actually create tables for new databases
|
||||
meta.create_all(engine)
|
||||
|
||||
# upgrade database with new columns
|
||||
with engine.begin() as conn:
|
||||
for tablename in DBTABLES:
|
||||
info = DBTABLES[tablename]
|
||||
@ -159,7 +161,8 @@ def scrobbles_db_to_dict(rows):
|
||||
"time":row.timestamp,
|
||||
"track":tracks[row.track_id],
|
||||
"duration":row.duration,
|
||||
"origin":row.origin
|
||||
"origin":row.origin,
|
||||
"extra":json.loads(row.extra or '{}')
|
||||
}
|
||||
for row in rows
|
||||
]
|
||||
@ -198,11 +201,12 @@ def artist_db_to_dict(row):
|
||||
|
||||
def scrobble_dict_to_db(info):
|
||||
return {
|
||||
"rawscrobble":json.dumps(info),
|
||||
"timestamp":info['time'],
|
||||
"origin":info['origin'],
|
||||
"duration":info['duration'],
|
||||
"track_id":get_track_id(info['track'])
|
||||
"track_id":get_track_id(info['track']),
|
||||
"extra":json.dumps(info.get('extra',{})),
|
||||
"rawscrobble":json.dumps(info)
|
||||
}
|
||||
|
||||
def track_dict_to_db(info):
|
||||
|
@ -71,6 +71,12 @@ def import_scrobbles(inputf):
|
||||
# clean up
|
||||
(scrobble['artists'],scrobble['title']) = c.fullclean(scrobble['artists'],scrobble['title'])
|
||||
|
||||
# extra info
|
||||
extrainfo = {}
|
||||
if scrobble.get('album'): extrainfo['album_name'] = scrobble['album']
|
||||
# saving this in the scrobble instead of the track because for now it's not meant
|
||||
# to be authorative information, just payload of the scrobble
|
||||
|
||||
scrobblebuffer.append({
|
||||
"time":scrobble['timestamp'],
|
||||
"track":{
|
||||
@ -80,11 +86,7 @@ def import_scrobbles(inputf):
|
||||
},
|
||||
"duration":scrobble['duration'],
|
||||
"origin":"import:" + typeid,
|
||||
"extra":{
|
||||
"album":scrobble['album']
|
||||
# saving this in the scrobble instead of the track because for now it's not meant
|
||||
# to be authorative information, just payload of the scrobble
|
||||
}
|
||||
"extra":extrainfo
|
||||
})
|
||||
|
||||
if (result['CONFIDENT_IMPORT'] + result['UNCERTAIN_IMPORT']) % 1000 == 0:
|
||||
|
Loading…
Reference in New Issue
Block a user