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

Updated scrobbler

This commit is contained in:
Krateng 2020-09-04 16:36:35 +02:00
parent e8c316f199
commit 7c8b0dd7cb
No known key found for this signature in database
GPG Key ID: 46735607861C6FCE
4 changed files with 22 additions and 16 deletions

View File

@ -239,7 +239,10 @@ def static_html(name):
lc["filterkeys"], lc["limitkeys"], lc["delimitkeys"], lc["amountkeys"], lc["specialkeys"] = uri_to_internal(keys) lc["filterkeys"], lc["limitkeys"], lc["delimitkeys"], lc["amountkeys"], lc["specialkeys"] = uri_to_internal(keys)
template = jinja_environment.get_template(name + '.jinja') template = jinja_environment.get_template(name + '.jinja')
try:
res = template.render(**LOCAL_CONTEXT) res = template.render(**LOCAL_CONTEXT)
except ValueError as e:
abort(404,"Entity does not exist")
if settings.get_settings("DEV_MODE"): jinja_environment.cache.clear() if settings.get_settings("DEV_MODE"): jinja_environment.cache.clear()

View File

@ -1,5 +1,4 @@
chrome.tabs.onUpdated.addListener(onTabUpdated); chrome.tabs.onUpdated.addListener(onTabUpdated);
chrome.tabs.onRemoved.addListener(onTabRemoved); chrome.tabs.onRemoved.addListener(onTabRemoved);
//chrome.tabs.onActivated.addListener(onTabChanged); //chrome.tabs.onActivated.addListener(onTabChanged);
@ -303,21 +302,25 @@ class Controller {
function scrobble(artist,title,seconds,secondsago=0) { function scrobble(artist,title,seconds,secondsago=0) {
console.log("Scrobbling " + artist + " - " + title + "; " + seconds + " seconds playtime, " + secondsago + " seconds ago") console.log("Scrobbling " + artist + " - " + title + "; " + seconds + " seconds playtime, " + secondsago + " seconds ago")
var artiststring = encodeURIComponent(artist)
var titlestring = encodeURIComponent(title)
var d = new Date() var d = new Date()
var time = Math.floor(d.getTime()/1000) - secondsago var time = Math.floor(d.getTime()/1000) - secondsago
//console.log("Time: " + time) //console.log("Time: " + time)
var requestbody = "artist=" + artiststring + "&title=" + titlestring + "&duration=" + seconds + "&time=" + time var payload = {
chrome.storage.local.get("apikey",function(result) { "artist":artist,
APIKEY = result["apikey"] "title":title,
chrome.storage.local.get("serverurl",function(result) { "duration":seconds,
URL = result["serverurl"] "time":time
}
chrome.storage.local.get(["serverurl","apikey"],function(result) {
payload["key"] = result["apikey"];
var xhttp = new XMLHttpRequest(); var xhttp = new XMLHttpRequest();
xhttp.open("POST",URL + "/api/newscrobble",true); xhttp.open("POST",result["serverurl"] + "/apis/mlj_1/newscrobble",true);
xhttp.send(requestbody + "&key=" + APIKEY) xhttp.setRequestHeader("Content-Type", "application/json");
//console.log("Sent: " + requestbody) //xhttp.send(requestbody + "&key=" + APIKEY)
}); var body = JSON.stringify(payload);
xhttp.send(body)
//console.log("Sent: " + body)
}); });

View File

@ -3,8 +3,8 @@
"version": "1.6", "version": "1.6",
"description": "Scrobbles tracks from various sites to your Maloja server", "description": "Scrobbles tracks from various sites to your Maloja server",
"manifest_version": 2, "manifest_version": 2,
"permissions": ["activeTab", "permissions": [
"declarativeContent", "activeTab",
"tabs", "tabs",
"storage", "storage",
"http://*/", "http://*/",

Binary file not shown.