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 = {}
|
DB = {}
|
||||||
|
|
||||||
|
|
||||||
engine = sql.create_engine(f"sqlite:///{data_dir['scrobbles']('malojadb.sqlite')}", echo = False)
|
engine = sql.create_engine(f"sqlite:///{data_dir['scrobbles']('malojadb.sqlite')}", echo = False)
|
||||||
meta = sql.MetaData()
|
meta = sql.MetaData()
|
||||||
|
|
||||||
|
# create table definitions
|
||||||
for tablename in DBTABLES:
|
for tablename in DBTABLES:
|
||||||
|
|
||||||
DB[tablename] = sql.Table(
|
DB[tablename] = sql.Table(
|
||||||
@ -81,8 +81,10 @@ for tablename in DBTABLES:
|
|||||||
**DBTABLES[tablename]['extrakwargs']
|
**DBTABLES[tablename]['extrakwargs']
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# actually create tables for new databases
|
||||||
meta.create_all(engine)
|
meta.create_all(engine)
|
||||||
|
|
||||||
|
# upgrade database with new columns
|
||||||
with engine.begin() as conn:
|
with engine.begin() as conn:
|
||||||
for tablename in DBTABLES:
|
for tablename in DBTABLES:
|
||||||
info = DBTABLES[tablename]
|
info = DBTABLES[tablename]
|
||||||
@ -159,7 +161,8 @@ def scrobbles_db_to_dict(rows):
|
|||||||
"time":row.timestamp,
|
"time":row.timestamp,
|
||||||
"track":tracks[row.track_id],
|
"track":tracks[row.track_id],
|
||||||
"duration":row.duration,
|
"duration":row.duration,
|
||||||
"origin":row.origin
|
"origin":row.origin,
|
||||||
|
"extra":json.loads(row.extra or '{}')
|
||||||
}
|
}
|
||||||
for row in rows
|
for row in rows
|
||||||
]
|
]
|
||||||
@ -198,11 +201,12 @@ def artist_db_to_dict(row):
|
|||||||
|
|
||||||
def scrobble_dict_to_db(info):
|
def scrobble_dict_to_db(info):
|
||||||
return {
|
return {
|
||||||
"rawscrobble":json.dumps(info),
|
|
||||||
"timestamp":info['time'],
|
"timestamp":info['time'],
|
||||||
"origin":info['origin'],
|
"origin":info['origin'],
|
||||||
"duration":info['duration'],
|
"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):
|
def track_dict_to_db(info):
|
||||||
|
@ -71,6 +71,12 @@ def import_scrobbles(inputf):
|
|||||||
# clean up
|
# clean up
|
||||||
(scrobble['artists'],scrobble['title']) = c.fullclean(scrobble['artists'],scrobble['title'])
|
(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({
|
scrobblebuffer.append({
|
||||||
"time":scrobble['timestamp'],
|
"time":scrobble['timestamp'],
|
||||||
"track":{
|
"track":{
|
||||||
@ -80,11 +86,7 @@ def import_scrobbles(inputf):
|
|||||||
},
|
},
|
||||||
"duration":scrobble['duration'],
|
"duration":scrobble['duration'],
|
||||||
"origin":"import:" + typeid,
|
"origin":"import:" + typeid,
|
||||||
"extra":{
|
"extra":extrainfo
|
||||||
"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
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (result['CONFIDENT_IMPORT'] + result['UNCERTAIN_IMPORT']) % 1000 == 0:
|
if (result['CONFIDENT_IMPORT'] + result['UNCERTAIN_IMPORT']) % 1000 == 0:
|
||||||
|
Loading…
Reference in New Issue
Block a user