1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Add reparse scrobble feature

This commit is contained in:
alim4r 2022-04-20 15:59:33 +02:00
parent 43ec4c2c9e
commit b525252af1
5 changed files with 80 additions and 9 deletions

View File

@ -589,3 +589,9 @@ def get_export(**keys):
def delete_scrobble(timestamp):
"""Internal Use Only"""
database.remove_scrobble(timestamp)
@api.post("reparse_scrobble")
@authenticated_function(api=True)
def reparse_scrobble(timestamp):
"""Internal Use Only"""
database.reparse_scrobble(timestamp)

View File

@ -102,7 +102,35 @@ def incoming_scrobble(rawscrobble,fix=True,client=None,api=None,dbconn=None):
log(f"Incoming scrobble [Client: {client} | API: {api}]: {rawscrobble}")
# raw scrobble to processed info
scrobbledict = rawscrobble_to_scrobbledict(rawscrobble, fix, client);
sqldb.add_scrobble(scrobbledict,dbconn=dbconn)
proxy_scrobble_all(scrobbledict['track']['artists'],scrobbledict['track']['title'],scrobbledict['time'])
dbcache.invalidate_caches(scrobbledict['time'])
#return {"status":"success","scrobble":scrobbledict}
return scrobbledict
@waitfordb
def reparse_scrobble(timestamp):
log(f"Reparsing Scrobble {timestamp}")
scrobble = sqldb.get_scrobble(timestamp)
if not scrobble:
return
scrobbledict = rawscrobble_to_scrobbledict(scrobble['rawscrobble'])
track_id = sqldb.get_track_id(scrobbledict['track'])
# check if id changed
if sqldb.get_track_id(scrobble['track']) != track_id:
sqldb.update_scrobble_track_id(timestamp, track_id)
def rawscrobble_to_scrobbledict(rawscrobble, fix=True, client=None):
# raw scrobble to processed info
scrobbleinfo = {**rawscrobble}
if fix:
scrobbleinfo['track_artists'],scrobbleinfo['track_title'] = cla.fullclean(scrobbleinfo['track_artists'],scrobbleinfo['track_title'])
@ -129,17 +157,9 @@ def incoming_scrobble(rawscrobble,fix=True,client=None,api=None,dbconn=None):
"rawscrobble":rawscrobble
}
sqldb.add_scrobble(scrobbledict,dbconn=dbconn)
proxy_scrobble_all(scrobbledict['track']['artists'],scrobbledict['track']['title'],scrobbledict['time'])
dbcache.invalidate_caches(scrobbledict['time'])
#return {"status":"success","scrobble":scrobbledict}
return scrobbledict
@waitfordb
def remove_scrobble(timestamp):
log(f"Deleting Scrobble {timestamp}")

View File

@ -277,6 +277,17 @@ def delete_scrobble(scrobble_id,dbconn=None):
dbconn.execute(op)
@connection_provider
def update_scrobble_track_id(scrobble_id, track_id, dbconn=None):
with SCROBBLE_LOCK:
op = DB['scrobbles'].update().where(
DB['scrobbles'].c.timestamp == scrobble_id
).values(track_id=track_id)
dbconn.execute(op)
### these will 'get' the ID of an entity, creating it if necessary
@cached_wrapper
@ -691,7 +702,16 @@ def get_artist(id,dbconn=None):
return artist_db_to_dict(artistinfo)
@cached_wrapper
@connection_provider
def get_scrobble(timestamp,dbconn=None):
op = DB['scrobbles'].select().where(
DB['scrobbles'].c.timestamp==timestamp
)
result = dbconn.execute(op).all()
scrobble = result[0]
return scrobbles_db_to_dict([scrobble], True)[0]
##### MAINTENANCE

View File

@ -17,6 +17,22 @@
{{ entityrow.row(s.track) }}
{% if adminmode %}
<td class='reparse_area'>
<span class="confirmactions">
<button class="smallbutton warning" onclick="reparseScrobble({{ s.time }})">Confirm</button>
<button class="smallbutton" onclick="toggleReparseConfirm(this)">Cancel</button>
</span>
<span class="initializeactions">
<div class='deleteicon clickable_icon danger' onclick="toggleReparseConfirm(this)">
<svg style="width:14px;height:14px" viewBox="0 0 24 24">
<path d="M19,4H15.5L14.5,3H9.5L8.5,4H5V6H19M6,19A2,2 0 0,0 8,21H16A2,2 0 0,0 18,19V7H6V19Z" />
</svg>
</div>
</span>
</td>
<td class='delete_area'>
<span class="confirmactions">
<button class="smallbutton warning" onclick="deleteScrobble({{ s.time }},this)">Confirm</button>

View File

@ -10,3 +10,12 @@ function deleteScrobble(id,element) {
neo.xhttpreq("/apis/mlj_1/delete_scrobble",data={'timestamp':id},method="POST",callback=(()=>null),json=true);
}
function toggleReparseConfirm(element) {
element.parentElement.parentElement.classList.toggle('active');
}
function reparseScrobble(id) {
neo.xhttpreq("/apis/mlj_1/reparse_scrobble",data={'timestamp':id},method="POST",callback=(()=>null),json=true);
}