mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Merge branch 'master' into feature-webedit
This commit is contained in:
commit
64d4036f55
30
API.md
30
API.md
@ -1,6 +1,7 @@
|
|||||||
# Scrobbling
|
# Scrobbling
|
||||||
|
|
||||||
In order to scrobble from a wide selection of clients, you can use Maloja's standard-compliant APIs with the following settings:
|
Scrobbling can be done with the native API, see [below](#submitting-a-scrobble).
|
||||||
|
In order to scrobble from a wide selection of clients, you can also use Maloja's standard-compliant APIs with the following settings:
|
||||||
|
|
||||||
GNU FM |
|
GNU FM |
|
||||||
------ | ---------
|
------ | ---------
|
||||||
@ -41,7 +42,7 @@ The user starts playing '(Fine Layers of) Slaysenflite', which is exactly 3:00 m
|
|||||||
* If the user ends the play after 1:22, no scrobble is submitted
|
* If the user ends the play after 1:22, no scrobble is submitted
|
||||||
* If the user ends the play after 2:06, a scrobble with `"duration":126` is submitted
|
* If the user ends the play after 2:06, a scrobble with `"duration":126` is submitted
|
||||||
* If the user jumps back several times and ends the play after 3:57, a scrobble with `"duration":237` is submitted
|
* If the user jumps back several times and ends the play after 3:57, a scrobble with `"duration":237` is submitted
|
||||||
* If the user jumps back several times and ends the play after 4:49, two scrobbles with `"duration":180` and `"duration":109` should be submitted
|
* If the user jumps back several times and ends the play after 4:49, two scrobbles with `"duration":180` and `"duration":109` are submitted
|
||||||
|
|
||||||
</td></tr>
|
</td></tr>
|
||||||
<table>
|
<table>
|
||||||
@ -55,10 +56,25 @@ All endpoints return JSON data. POST request can be made with query string or fo
|
|||||||
|
|
||||||
No application should ever rely on the non-existence of fields in the JSON data - i.e., additional fields can be added at any time without this being considered a breaking change. Existing fields should usually not be removed or changed, but it is always a good idea to add basic handling for missing fields.
|
No application should ever rely on the non-existence of fields in the JSON data - i.e., additional fields can be added at any time without this being considered a breaking change. Existing fields should usually not be removed or changed, but it is always a good idea to add basic handling for missing fields.
|
||||||
|
|
||||||
|
## Submitting a Scrobble
|
||||||
|
|
||||||
|
The POST endpoint `/newscrobble` is used to submit new scrobbles. These use a flat JSON structure with the following fields:
|
||||||
|
|
||||||
|
| Key | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `artists` | List(String) | Track artists |
|
||||||
|
| `title` | String | Track title |
|
||||||
|
| `album` | String | Name of the album (Optional) |
|
||||||
|
| `albumartists` | List(String) | Album artists (Optional) |
|
||||||
|
| `duration` | Integer | How long the song was listened to in seconds (Optional) |
|
||||||
|
| `length` | Integer | Actual length of the full song in seconds (Optional) |
|
||||||
|
| `time` | Integer | Timestamp of the listen if it was not at the time of submitting (Optional) |
|
||||||
|
| `nofix` | Boolean | Skip server-side metadata fixing (Optional) |
|
||||||
|
|
||||||
## General Structure
|
## General Structure
|
||||||
|
|
||||||
|
The API is not fully consistent in order to ensure backwards-compatibility. Refer to the individual endpoints.
|
||||||
Most endpoints follow this structure:
|
Generally, most endpoints follow this structure:
|
||||||
|
|
||||||
| Key | Type | Description |
|
| Key | Type | Description |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
@ -66,7 +82,7 @@ Most endpoints follow this structure:
|
|||||||
| `error` | Mapping | Details about the error if one occured. |
|
| `error` | Mapping | Details about the error if one occured. |
|
||||||
| `warnings` | List | Any warnings that did not result in failure, but should be noted. Field is omitted if there are no warnings! |
|
| `warnings` | List | Any warnings that did not result in failure, but should be noted. Field is omitted if there are no warnings! |
|
||||||
| `desc` | String | Human-readable feedback. This can be shown directly to the user if desired. |
|
| `desc` | String | Human-readable feedback. This can be shown directly to the user if desired. |
|
||||||
| `list` | List | List of returned [entities](#Entity-Structure) |
|
| `list` | List | List of returned [entities](#entity-structure) |
|
||||||
|
|
||||||
|
|
||||||
Both errors and warnings have the following structure:
|
Both errors and warnings have the following structure:
|
||||||
@ -87,7 +103,7 @@ Whenever a list of entities is returned, they have the following fields:
|
|||||||
| Key | Type | Description |
|
| Key | Type | Description |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `time` | Integer | Timestamp of the Scrobble in UTC |
|
| `time` | Integer | Timestamp of the Scrobble in UTC |
|
||||||
| `track` | Mapping | The [track](#Track) being scrobbled |
|
| `track` | Mapping | The [track](#track) being scrobbled |
|
||||||
| `duration` | Integer | How long the track was played for in seconds |
|
| `duration` | Integer | How long the track was played for in seconds |
|
||||||
| `origin` | String | Client that submitted the scrobble, or import source |
|
| `origin` | String | Client that submitted the scrobble, or import source |
|
||||||
|
|
||||||
@ -118,7 +134,7 @@ Whenever a list of entities is returned, they have the following fields:
|
|||||||
|
|
||||||
| Key | Type | Description |
|
| Key | Type | Description |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `artists` | List | The [artists](#Artist) credited with the track |
|
| `artists` | List | The [artists](#artist) credited with the track |
|
||||||
| `title` | String | The title of the track |
|
| `title` | String | The title of the track |
|
||||||
| `length` | Integer | The full length of the track in seconds |
|
| `length` | Integer | The full length of the track in seconds |
|
||||||
|
|
||||||
|
@ -42,3 +42,10 @@ minor_release_name: "Yeonhee"
|
|||||||
- "[Bugfix] Fixed importing a Spotify file without path"
|
- "[Bugfix] Fixed importing a Spotify file without path"
|
||||||
- "[Bugfix] No longer releasing database lock during scrobble creation"
|
- "[Bugfix] No longer releasing database lock during scrobble creation"
|
||||||
- "[Distribution] Experimental arm64 image"
|
- "[Distribution] Experimental arm64 image"
|
||||||
|
3.0.7:
|
||||||
|
commit: "62abc319303a6cb6463f7c27b6ef09b76fc67f86"
|
||||||
|
notes:
|
||||||
|
- "[Bugix] Improved signal handling"
|
||||||
|
- "[Bugix] Fixed constant re-caching of all-time stats, significantly increasing page load speed"
|
||||||
|
- "[Logging] Disabled cache information when cache is not used"
|
||||||
|
- "[Distribution] Experimental arm/v7 image"
|
||||||
|
@ -6,3 +6,5 @@ minor_release_name: "Soyeon"
|
|||||||
- "[Feature] Implemented track title and artist name editing from web interface"
|
- "[Feature] Implemented track title and artist name editing from web interface"
|
||||||
- "[Feature] Implemented track and artist merging from web interface"
|
- "[Feature] Implemented track and artist merging from web interface"
|
||||||
- "[Feature] Implemented scrobble reparsing from web interface"
|
- "[Feature] Implemented scrobble reparsing from web interface"
|
||||||
|
- "[Performance] Adjusted cache sizes"
|
||||||
|
- "[Logging] Added cache memory use information"
|
||||||
|
@ -6,6 +6,7 @@ FOLDER = "dev/releases"
|
|||||||
|
|
||||||
releases = {}
|
releases = {}
|
||||||
for f in os.listdir(FOLDER):
|
for f in os.listdir(FOLDER):
|
||||||
|
if f == "branch.yml": continue
|
||||||
#maj,min = (int(i) for i in f.split('.')[:2])
|
#maj,min = (int(i) for i in f.split('.')[:2])
|
||||||
|
|
||||||
with open(os.path.join(FOLDER,f)) as fd:
|
with open(os.path.join(FOLDER,f)) as fd:
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
# you know what f*ck it
|
# you know what f*ck it
|
||||||
# this is hardcoded for now because of that damn project / package name discrepancy
|
# this is hardcoded for now because of that damn project / package name discrepancy
|
||||||
# i'll fix it one day
|
# i'll fix it one day
|
||||||
VERSION = "3.0.6"
|
VERSION = "3.0.7"
|
||||||
HOMEPAGE = "https://github.com/krateng/maloja"
|
HOMEPAGE = "https://github.com/krateng/maloja"
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
import lru
|
import lru
|
||||||
import psutil
|
import psutil
|
||||||
import json
|
import json
|
||||||
|
import sys
|
||||||
from doreah.regular import runhourly
|
from doreah.regular import runhourly
|
||||||
from doreah.logging import log
|
from doreah.logging import log
|
||||||
|
|
||||||
@ -12,16 +13,10 @@ from ..pkg_global.conf import malojaconfig
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if malojaconfig['USE_GLOBAL_CACHE']:
|
if malojaconfig['USE_GLOBAL_CACHE']:
|
||||||
CACHE_SIZE = 1000
|
|
||||||
ENTITY_CACHE_SIZE = 100000
|
|
||||||
|
|
||||||
cache = lru.LRU(CACHE_SIZE)
|
cache = lru.LRU(10000)
|
||||||
entitycache = lru.LRU(ENTITY_CACHE_SIZE)
|
entitycache = lru.LRU(100000)
|
||||||
|
|
||||||
hits, misses = 0, 0
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -31,11 +26,10 @@ if malojaconfig['USE_GLOBAL_CACHE']:
|
|||||||
trim_cache()
|
trim_cache()
|
||||||
|
|
||||||
def print_stats():
|
def print_stats():
|
||||||
log(f"Cache Size: {len(cache)} [{len(entitycache)} E], System RAM Utilization: {psutil.virtual_memory().percent}%, Cache Hits: {hits}/{hits+misses}")
|
for name,c in (('Cache',cache),('Entity Cache',entitycache)):
|
||||||
#print("Full rundown:")
|
hits, misses = c.get_stats()
|
||||||
#import sys
|
log(f"{name}: Size: {len(c)} | Hits: {hits}/{hits+misses} | Estimated Memory: {human_readable_size(c)}")
|
||||||
#for k in cache.keys():
|
log(f"System RAM Utilization: {psutil.virtual_memory().percent}%")
|
||||||
# print(f"\t{k}\t{sys.getsizeof(cache[k])}")
|
|
||||||
|
|
||||||
|
|
||||||
def cached_wrapper(inner_func):
|
def cached_wrapper(inner_func):
|
||||||
@ -49,12 +43,9 @@ if malojaconfig['USE_GLOBAL_CACHE']:
|
|||||||
global hits, misses
|
global hits, misses
|
||||||
key = (serialize(args),serialize(kwargs), inner_func, kwargs.get("since"), kwargs.get("to"))
|
key = (serialize(args),serialize(kwargs), inner_func, kwargs.get("since"), kwargs.get("to"))
|
||||||
|
|
||||||
if key in cache:
|
try:
|
||||||
hits += 1
|
return cache[key]
|
||||||
return cache.get(key)
|
except KeyError:
|
||||||
|
|
||||||
else:
|
|
||||||
misses += 1
|
|
||||||
result = inner_func(*args,**kwargs,dbconn=conn)
|
result = inner_func(*args,**kwargs,dbconn=conn)
|
||||||
cache[key] = result
|
cache[key] = result
|
||||||
return result
|
return result
|
||||||
@ -67,25 +58,18 @@ if malojaconfig['USE_GLOBAL_CACHE']:
|
|||||||
# cache that's aware of what we're calling
|
# cache that's aware of what we're calling
|
||||||
def cached_wrapper_individual(inner_func):
|
def cached_wrapper_individual(inner_func):
|
||||||
|
|
||||||
|
|
||||||
def outer_func(set_arg,**kwargs):
|
def outer_func(set_arg,**kwargs):
|
||||||
|
|
||||||
|
|
||||||
if 'dbconn' in kwargs:
|
if 'dbconn' in kwargs:
|
||||||
conn = kwargs.pop('dbconn')
|
conn = kwargs.pop('dbconn')
|
||||||
else:
|
else:
|
||||||
conn = None
|
conn = None
|
||||||
|
|
||||||
#global hits, misses
|
|
||||||
result = {}
|
result = {}
|
||||||
for id in set_arg:
|
for id in set_arg:
|
||||||
if (inner_func,id) in entitycache:
|
try:
|
||||||
result[id] = entitycache[(inner_func,id)]
|
result[id] = entitycache[(inner_func,id)]
|
||||||
#hits += 1
|
except KeyError:
|
||||||
else:
|
|
||||||
pass
|
pass
|
||||||
#misses += 1
|
|
||||||
|
|
||||||
|
|
||||||
remaining = inner_func(set(e for e in set_arg if e not in result),dbconn=conn)
|
remaining = inner_func(set(e for e in set_arg if e not in result),dbconn=conn)
|
||||||
for id in remaining:
|
for id in remaining:
|
||||||
@ -115,13 +99,14 @@ if malojaconfig['USE_GLOBAL_CACHE']:
|
|||||||
def trim_cache():
|
def trim_cache():
|
||||||
ramprct = psutil.virtual_memory().percent
|
ramprct = psutil.virtual_memory().percent
|
||||||
if ramprct > malojaconfig["DB_MAX_MEMORY"]:
|
if ramprct > malojaconfig["DB_MAX_MEMORY"]:
|
||||||
log(f"{ramprct}% RAM usage, clearing cache and adjusting size!")
|
log(f"{ramprct}% RAM usage, clearing cache!")
|
||||||
|
for c in (cache,entitycache):
|
||||||
|
c.clear()
|
||||||
#ratio = 0.6
|
#ratio = 0.6
|
||||||
#targetsize = max(int(len(cache) * ratio),50)
|
#targetsize = max(int(len(cache) * ratio),50)
|
||||||
#log(f"Reducing to {targetsize} entries")
|
#log(f"Reducing to {targetsize} entries")
|
||||||
#cache.set_size(targetsize)
|
#cache.set_size(targetsize)
|
||||||
#cache.set_size(HIGH_NUMBER)
|
#cache.set_size(HIGH_NUMBER)
|
||||||
cache.clear()
|
|
||||||
#if cache.get_size() > CACHE_ADJUST_STEP:
|
#if cache.get_size() > CACHE_ADJUST_STEP:
|
||||||
# cache.set_size(cache.get_size() - CACHE_ADJUST_STEP)
|
# cache.set_size(cache.get_size() - CACHE_ADJUST_STEP)
|
||||||
|
|
||||||
@ -156,3 +141,32 @@ def serialize(obj):
|
|||||||
elif isinstance(obj,dict):
|
elif isinstance(obj,dict):
|
||||||
return "{" + ",".join(serialize(o) + ":" + serialize(obj[o]) for o in obj) + "}"
|
return "{" + ",".join(serialize(o) + ":" + serialize(obj[o]) for o in obj) + "}"
|
||||||
return json.dumps(obj.hashable())
|
return json.dumps(obj.hashable())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def get_size_of(obj,counted=None):
|
||||||
|
if counted is None:
|
||||||
|
counted = set()
|
||||||
|
if id(obj) in counted: return 0
|
||||||
|
size = sys.getsizeof(obj)
|
||||||
|
counted.add(id(obj))
|
||||||
|
try:
|
||||||
|
for k,v in obj.items():
|
||||||
|
size += get_size_of(v,counted=counted)
|
||||||
|
except:
|
||||||
|
try:
|
||||||
|
for i in obj:
|
||||||
|
size += get_size_of(i,counted=counted)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return size
|
||||||
|
|
||||||
|
def human_readable_size(obj):
|
||||||
|
units = ['','K','M','G','T','P']
|
||||||
|
idx = 0
|
||||||
|
bytes = get_size_of(obj)
|
||||||
|
while bytes > 1024 and len(units) > idx+1:
|
||||||
|
bytes = bytes / 1024
|
||||||
|
idx += 1
|
||||||
|
|
||||||
|
return f"{bytes:.2f} {units[idx]}B"
|
||||||
|
@ -23,6 +23,7 @@ class JinjaDBConnection:
|
|||||||
return self
|
return self
|
||||||
def __exit__(self, exc_type, exc_value, exc_traceback):
|
def __exit__(self, exc_type, exc_value, exc_traceback):
|
||||||
self.conn.close()
|
self.conn.close()
|
||||||
|
if malojaconfig['USE_REQUEST_CACHE']:
|
||||||
log(f"Generated page with {self.hits}/{self.hits+self.misses} local Cache hits",module="debug_performance")
|
log(f"Generated page with {self.hits}/{self.hits+self.misses} local Cache hits",module="debug_performance")
|
||||||
del self.cache
|
del self.cache
|
||||||
def __getattr__(self,name):
|
def __getattr__(self,name):
|
||||||
|
@ -117,6 +117,8 @@ def connection_provider(func):
|
|||||||
with engine.connect() as connection:
|
with engine.connect() as connection:
|
||||||
kwargs['dbconn'] = connection
|
kwargs['dbconn'] = connection
|
||||||
return func(*args,**kwargs)
|
return func(*args,**kwargs)
|
||||||
|
|
||||||
|
wrapper.__innerfunc__ = func
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
##### DB <-> Dict translations
|
##### DB <-> Dict translations
|
||||||
|
@ -148,9 +148,9 @@ malojaconfig = Configuration(
|
|||||||
"Technical":{
|
"Technical":{
|
||||||
"cache_expire_positive":(tp.Integer(), "Image Cache Expiration", 60, "Days until images are refetched"),
|
"cache_expire_positive":(tp.Integer(), "Image Cache Expiration", 60, "Days until images are refetched"),
|
||||||
"cache_expire_negative":(tp.Integer(), "Image Cache Negative Expiration", 5, "Days until failed image fetches are reattempted"),
|
"cache_expire_negative":(tp.Integer(), "Image Cache Negative Expiration", 5, "Days until failed image fetches are reattempted"),
|
||||||
"db_max_memory":(tp.Integer(min=0,max=100), "RAM Percentage soft limit", 80, "RAM Usage in percent at which Maloja should no longer increase its database cache."),
|
"db_max_memory":(tp.Integer(min=0,max=100), "RAM Percentage soft limit", 50, "RAM Usage in percent at which Maloja should no longer increase its database cache."),
|
||||||
"use_request_cache":(tp.Boolean(), "Use request-local DB Cache", False),
|
"use_request_cache":(tp.Boolean(), "Use request-local DB Cache", False),
|
||||||
"use_global_cache":(tp.Boolean(), "Use global DB Cache", False)
|
"use_global_cache":(tp.Boolean(), "Use global DB Cache", True)
|
||||||
},
|
},
|
||||||
"Fluff":{
|
"Fluff":{
|
||||||
"scrobbles_gold":(tp.Integer(), "Scrobbles for Gold", 250, "How many scrobbles a track needs to be considered 'Gold' status"),
|
"scrobbles_gold":(tp.Integer(), "Scrobbles for Gold", 250, "How many scrobbles a track needs to be considered 'Gold' status"),
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "malojaserver"
|
name = "malojaserver"
|
||||||
version = "3.0.6"
|
version = "3.0.7"
|
||||||
description = "Self-hosted music scrobble database"
|
description = "Self-hosted music scrobble database"
|
||||||
readme = "./README.md"
|
readme = "./README.md"
|
||||||
requires-python = ">=3.7"
|
requires-python = ">=3.7"
|
||||||
|
Loading…
Reference in New Issue
Block a user