mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Implemented scrobbling via POST
This commit is contained in:
parent
5b0436e256
commit
75a70a10b7
30
database.py
30
database.py
@ -1,4 +1,4 @@
|
||||
from bottle import route, run, template, static_file, request, response, FormsDict
|
||||
from bottle import route, get, post, run, template, static_file, request, response, FormsDict
|
||||
from importlib.machinery import SourceFileLoader
|
||||
import urllib
|
||||
import waitress
|
||||
@ -96,7 +96,8 @@ def get_scrobbles():
|
||||
def get_tracks():
|
||||
artist = request.query.get("artist")
|
||||
|
||||
artistid = ARTISTS.index(artist)
|
||||
if artist is not None:
|
||||
artistid = ARTISTS.index(artist)
|
||||
|
||||
# Option 1
|
||||
ls = [getTrackObject(t) for t in TRACKS if (artistid in t[0]) or (artistid==None)]
|
||||
@ -122,8 +123,8 @@ def get_charts():
|
||||
#results = db_query(since=since,to=to)
|
||||
#return {"list":results}
|
||||
|
||||
@route("/newscrobble")
|
||||
def post_scrobble():
|
||||
@get("/newscrobble")
|
||||
def pseudo_post_scrobble():
|
||||
keys = FormsDict.decode(request.query) # The Dal★Shabet handler
|
||||
artists = keys.get("artist")
|
||||
title = keys.get("title")
|
||||
@ -143,6 +144,27 @@ def post_scrobble():
|
||||
|
||||
return ""
|
||||
|
||||
@post("/newscrobble")
|
||||
def post_scrobble():
|
||||
keys = FormsDict.decode(request.forms) # The Dal★Shabet handler
|
||||
artists = keys.get("artist")
|
||||
title = keys.get("title")
|
||||
try:
|
||||
time = int(keys.get("time"))
|
||||
except:
|
||||
time = int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp())
|
||||
(artists,title) = c.fullclean(artists,title)
|
||||
|
||||
## this is necessary for localhost testing
|
||||
response.set_header("Access-Control-Allow-Origin","*")
|
||||
|
||||
createScrobble(artists,title,time)
|
||||
|
||||
if (time - lastsync) > 3600:
|
||||
sync()
|
||||
|
||||
return ""
|
||||
|
||||
@route("/sync")
|
||||
def abouttoshutdown():
|
||||
sync()
|
||||
|
@ -211,8 +211,8 @@ function scrobble(artist,title,seconds) {
|
||||
artiststring = encodeURIComponent(artist)
|
||||
titlestring = encodeURIComponent(title)
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.open("GET","http://localhost:42010/db/newscrobble?artist=" + artiststring + "&title=" + titlestring + "&duration=" + seconds,true);
|
||||
xhttp.send()
|
||||
xhttp.open("POST","http://localhost:42010/db/newscrobble",true);
|
||||
xhttp.send("artist=" + artiststring + "&title=" + titlestring + "&duration=" + seconds)
|
||||
}
|
||||
|
||||
function setUpdate() {
|
||||
|
11
server.py
11
server.py
@ -1,4 +1,4 @@
|
||||
from bottle import route, run, template, static_file, request, response, FormsDict
|
||||
from bottle import route, get, post, run, template, static_file, request, response, FormsDict
|
||||
from importlib.machinery import SourceFileLoader
|
||||
import _thread
|
||||
import waitress
|
||||
@ -22,7 +22,7 @@ def mainpage():
|
||||
# this is the fallback option. If you run this service behind a reverse proxy, it is recommended to rewrite /db/ requests to the port of the db server
|
||||
# e.g. location /db { rewrite ^/db(.*)$ $1 break; proxy_pass http://yoururl:12349; }
|
||||
|
||||
@route("/db/<pth:path>")
|
||||
@get("/db/<pth:path>")
|
||||
def database(pth):
|
||||
keys = FormsDict.decode(request.query) # The Dal★Shabet handler
|
||||
keystring = "?"
|
||||
@ -33,6 +33,13 @@ def database(pth):
|
||||
response.set_header("Access-Control-Allow-Origin","*")
|
||||
#print("Returning " + "http://localhost:" + str(DATABASE_PORT) + "/" + pth)
|
||||
return contents
|
||||
|
||||
@post("/db/<pth:path>")
|
||||
def database(pth):
|
||||
contents = urllib.request.urlopen("http://localhost:" + str(DATABASE_PORT) + "/" + pth,request.body).read()
|
||||
response.content_type = "application/json"
|
||||
response.set_header("Access-Control-Allow-Origin","*")
|
||||
return contents
|
||||
|
||||
@route("/exit")
|
||||
def shutdown():
|
||||
|
Loading…
Reference in New Issue
Block a user