mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Added basic scrobbling function
This commit is contained in:
parent
2f8720898b
commit
bdf114d7fe
12
cleanup.py
12
cleanup.py
@ -1,10 +1,22 @@
|
||||
import re
|
||||
|
||||
def fullclean(artist,title):
|
||||
artists = cleanup(removespecial(artist))
|
||||
title = cleantitle(removespecial(title))
|
||||
(title,moreartists) = findartistsintitle(title)
|
||||
artists += moreartists
|
||||
|
||||
return (artists,title)
|
||||
|
||||
def removespecial(s):
|
||||
return s.replace("\t","").replace("␟","").replace("\n","")
|
||||
|
||||
def cleanup(artiststr):
|
||||
|
||||
if artiststr == "":
|
||||
return []
|
||||
|
||||
|
||||
artists = [artiststr]
|
||||
|
||||
artistsnew = []
|
||||
|
11
database.py
11
database.py
@ -3,6 +3,7 @@ from importlib.machinery import SourceFileLoader
|
||||
import waitress
|
||||
import os
|
||||
import datetime
|
||||
import cleanup
|
||||
|
||||
|
||||
SCROBBLES = [] # Format: tuple(track_ref,timestamp,saved)
|
||||
@ -105,6 +106,16 @@ def get_charts():
|
||||
#results = db_query(since=since,to=to)
|
||||
#return {"list":results}
|
||||
|
||||
@route("/newscrobble")
|
||||
def post_scrobble():
|
||||
keys = request.query
|
||||
artists = keys.get("artist")
|
||||
title = keys.get("title")
|
||||
(artists,title) = cleanup.fullclean(artists,title)
|
||||
time = int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp())
|
||||
|
||||
createScrobble(artists,title,time)
|
||||
|
||||
# Starts the server
|
||||
def runserver(DATABASE_PORT):
|
||||
|
||||
|
@ -5,6 +5,7 @@ from importlib.machinery import SourceFileLoader
|
||||
import _thread
|
||||
import waitress
|
||||
import urllib.request
|
||||
import urllib.parse
|
||||
|
||||
|
||||
MAIN_PORT = 12345
|
||||
@ -35,7 +36,11 @@ def mainpage():
|
||||
|
||||
@route("/db/<pth:path>")
|
||||
def database(pth):
|
||||
contents = urllib.request.urlopen("http://localhost:" + str(DATABASE_PORT) + "/" + pth).read()
|
||||
keys = request.query
|
||||
keystring = "?"
|
||||
for k in keys:
|
||||
keystring += urllib.parse.quote(k) + "=" + urllib.parse.quote(keys[k]) + "&"
|
||||
contents = urllib.request.urlopen("http://localhost:" + str(DATABASE_PORT) + "/" + pth + keystring).read()
|
||||
response.content_type = "application/json"
|
||||
#print("Returning " + "http://localhost:" + str(DATABASE_PORT) + "/" + pth)
|
||||
return contents
|
||||
|
Loading…
Reference in New Issue
Block a user