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

Merge pull request #122 from alim4r/feature/reparse-scrobble

Add reparse scrobble feature
This commit is contained in:
krateng 2022-04-22 17:17:11 +02:00 committed by GitHub
commit e9189b8903
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 88 additions and 9 deletions

View File

@ -677,3 +677,9 @@ def merge_artists(target_id,source_ids):
return {
"status":"success"
}
@api.post("reparse_scrobble")
@authenticated_function(api=True)
def reparse_scrobble(timestamp):
"""Internal Use Only"""
database.reparse_scrobble(timestamp)

View File

@ -102,7 +102,36 @@ 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=timestamp, include_internal=True)
if not scrobble or not scrobble['rawscrobble']:
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 +158,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}")
@ -203,6 +224,7 @@ def get_scrobbles(dbconn=None,**keys):
#return result[keys['page']*keys['perpage']:(keys['page']+1)*keys['perpage']]
return list(reversed(result))
@waitfordb
def get_scrobbles_num(dbconn=None,**keys):
(since,to) = keys.get('timerange').timestamps()

View File

@ -280,6 +280,17 @@ def delete_scrobble(scrobble_id,dbconn=None):
return True
@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
@ -776,7 +787,16 @@ def get_artist(id,dbconn=None):
return artist_db_to_dict(artistinfo,dbconn=dbconn)
@cached_wrapper
@connection_provider
def get_scrobble(timestamp, include_internal=False, 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(rows=[scrobble], include_internal=include_internal)[0]
##### MAINTENANCE

View File

@ -17,6 +17,22 @@
{{ entityrow.row(s.track) }}
{% if adminmode %}
<td class='delete_area'>
<span class="confirmactions">
<button class="smallbutton warning" onclick="reparseScrobble({{ s.time }},this)">Confirm</button>
<button class="smallbutton" onclick="toggleReparseConfirm(this)">Cancel</button>
</span>
<span class="initializeactions">
<div class='refreshicon 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

@ -617,6 +617,10 @@ table.list td.searchProvider:hover {
table.list td.delete_area {
text-align: right;
width:0em;
}
table.list td.delete_area.active {
width:7em;
}

View File

@ -187,3 +187,14 @@ function cancelMerge() {
lcst.setItem(key,[]);
showValidMergeIcons();
}
function toggleReparseConfirm(element) {
element.parentElement.parentElement.classList.toggle('active');
}
function reparseScrobble(id, element) {
toggleReparseConfirm(element);
neo.xhttpreq("/apis/mlj_1/reparse_scrobble",data={'timestamp':id},method="POST",callback=(()=>null),json=true);
}