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:
commit
e9189b8903
@ -677,3 +677,9 @@ def merge_artists(target_id,source_ids):
|
|||||||
return {
|
return {
|
||||||
"status":"success"
|
"status":"success"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@api.post("reparse_scrobble")
|
||||||
|
@authenticated_function(api=True)
|
||||||
|
def reparse_scrobble(timestamp):
|
||||||
|
"""Internal Use Only"""
|
||||||
|
database.reparse_scrobble(timestamp)
|
@ -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}")
|
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}
|
scrobbleinfo = {**rawscrobble}
|
||||||
if fix:
|
if fix:
|
||||||
scrobbleinfo['track_artists'],scrobbleinfo['track_title'] = cla.fullclean(scrobbleinfo['track_artists'],scrobbleinfo['track_title'])
|
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
|
"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
|
return scrobbledict
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@waitfordb
|
@waitfordb
|
||||||
def remove_scrobble(timestamp):
|
def remove_scrobble(timestamp):
|
||||||
log(f"Deleting 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 result[keys['page']*keys['perpage']:(keys['page']+1)*keys['perpage']]
|
||||||
return list(reversed(result))
|
return list(reversed(result))
|
||||||
|
|
||||||
|
|
||||||
@waitfordb
|
@waitfordb
|
||||||
def get_scrobbles_num(dbconn=None,**keys):
|
def get_scrobbles_num(dbconn=None,**keys):
|
||||||
(since,to) = keys.get('timerange').timestamps()
|
(since,to) = keys.get('timerange').timestamps()
|
||||||
|
@ -280,6 +280,17 @@ def delete_scrobble(scrobble_id,dbconn=None):
|
|||||||
|
|
||||||
return True
|
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
|
### these will 'get' the ID of an entity, creating it if necessary
|
||||||
|
|
||||||
@cached_wrapper
|
@cached_wrapper
|
||||||
@ -776,7 +787,16 @@ def get_artist(id,dbconn=None):
|
|||||||
return artist_db_to_dict(artistinfo,dbconn=dbconn)
|
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
|
##### MAINTENANCE
|
||||||
|
@ -17,6 +17,22 @@
|
|||||||
{{ entityrow.row(s.track) }}
|
{{ entityrow.row(s.track) }}
|
||||||
{% if adminmode %}
|
{% 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'>
|
<td class='delete_area'>
|
||||||
<span class="confirmactions">
|
<span class="confirmactions">
|
||||||
<button class="smallbutton warning" onclick="deleteScrobble({{ s.time }},this)">Confirm</button>
|
<button class="smallbutton warning" onclick="deleteScrobble({{ s.time }},this)">Confirm</button>
|
||||||
|
@ -617,6 +617,10 @@ table.list td.searchProvider:hover {
|
|||||||
|
|
||||||
table.list td.delete_area {
|
table.list td.delete_area {
|
||||||
text-align: right;
|
text-align: right;
|
||||||
|
width:0em;
|
||||||
|
}
|
||||||
|
|
||||||
|
table.list td.delete_area.active {
|
||||||
width:7em;
|
width:7em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,3 +187,14 @@ function cancelMerge() {
|
|||||||
lcst.setItem(key,[]);
|
lcst.setItem(key,[]);
|
||||||
showValidMergeIcons();
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user