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

Compare commits

...

14 Commits

Author SHA1 Message Date
krateng
4cffc9971d Merge branch 'master' into feature-restructure 2022-04-14 15:19:38 +02:00
krateng
bcb1d36b4a Exit codes for main function, fix GH-113 2022-04-14 15:10:15 +02:00
krateng
9d8752d052 Fixed proper recognition of artist and track entities, fix GH-111 2022-04-14 14:49:59 +02:00
krateng
741246a7c1
Merge pull request #110 from da2x/patch-1
Set Referrer-Policy to same-origin
2022-04-14 14:35:55 +02:00
Daniel Aleksandersen
c076518d76
Set Referrer-Policy to same-origin
Remove the Referer (sic) HTTP request header from external requests (e.g. to
the image CDNs).

The charset directive must be included in the first TCP packet. It should
be set at the very top of the document. Grouping document mode metas
and descriptive metadata in separate groups.
2022-04-14 13:02:21 +02:00
krateng
4a8221f7a0 Added waitress warning interception 2022-04-13 18:00:39 +02:00
krateng
42579ad1f0 Fixed missing import, GH-108 2022-04-13 15:42:45 +02:00
krateng
ef312c6ba9 Updated admin mode info 2022-04-12 23:04:17 +02:00
krateng
dad1365627 Renamed imported scrobble folder 2022-04-12 20:33:36 +02:00
krateng
1c2062c512 Reenabled site generation profiling 2022-04-12 19:04:22 +02:00
krateng
6b39ca8b19 Added duration warning to upgrade page 2022-04-12 19:03:55 +02:00
krateng
700b81217c Version bump 2022-04-12 17:59:32 +02:00
krateng
50cf592a75 Fixed upgrading early scrobbles, GH-106 2022-04-12 17:57:13 +02:00
krateng
0f39ecbf7e Fixed funding file 2022-04-12 16:39:44 +02:00
13 changed files with 61 additions and 24 deletions

2
.github/FUNDING.yml vendored
View File

@ -1 +1 @@
custom: ["https://flattr.com/@Krateng", "https://paypal.me/krateng", "bitcoin:1krat8JMniJBTiHftMfR1LtF3Y1w5DAxx"]
custom: ["https://flattr.com/@Krateng", "https://paypal.me/krateng"]

View File

@ -151,14 +151,13 @@ def main(*args,**kwargs):
if "version" in kwargs:
print(info.VERSION)
return True
else:
try:
action, *args = args
action = actions[action]
except (ValueError, KeyError):
print("Valid commands: " + " ".join(a for a in actions))
return
return False
return action(*args,**kwargs)
return True

View File

@ -4,7 +4,7 @@
# you know what f*ck it
# this is hardcoded for now because of that damn project / package name discrepancy
# i'll fix it one day
VERSION = "3.0.0"
VERSION = "3.0.2"
HOMEPAGE = "https://github.com/krateng/maloja"

View File

@ -1,4 +1,5 @@
import os
import math
from bottle import response, static_file, request, FormsDict

View File

@ -46,7 +46,7 @@ class DatabaseNotBuilt(HTTPError):
def __init__(self):
super().__init__(
status=503,
body="The Maloja Database is being upgraded to Version 3. This could take several minutes.",
body="The Maloja Database is being upgraded to Version 3. This could take quite a long time! (~ 2-5 minutes per 10 000 scrobbles)",
headers={"Retry-After":120}
)

View File

@ -10,24 +10,30 @@ from ..pkg_global.conf import data_dir
profiler = cProfile.Profile()
FULL_PROFILE = False
def profile(func):
def newfunc(*args,**kwargs):
benchmarkfolder = data_dir['logs']("benchmarks")
os.makedirs(benchmarkfolder,exist_ok=True)
if FULL_PROFILE:
benchmarkfolder = data_dir['logs']("benchmarks")
os.makedirs(benchmarkfolder,exist_ok=True)
clock = Clock()
clock.start()
profiler.enable()
if FULL_PROFILE:
profiler.enable()
result = func(*args,**kwargs)
profiler.disable()
if FULL_PROFILE:
profiler.disable()
log(f"Executed {func.__name__} ({args}, {kwargs}) in {clock.stop():.2f}s",module="debug_performance")
try:
pstats.Stats(profiler).dump_stats(os.path.join(benchmarkfolder,f"{func.__name__}.stats"))
except:
pass
if FULL_PROFILE:
try:
pstats.Stats(profiler).dump_stats(os.path.join(benchmarkfolder,f"{func.__name__}.stats"))
except:
pass
return result

View File

@ -5,6 +5,7 @@ from threading import Thread
from importlib import resources
from css_html_js_minify import html_minify, css_minify
import datauri
import time
# server stuff
@ -34,7 +35,7 @@ from .dev.profiler import profile
PORT = malojaconfig["PORT"]
HOST = malojaconfig["HOST"]
THREADS = 12
THREADS = 16
BaseRequest.MEMFILE_MAX = 15 * 1024 * 1024
#STATICFOLDER = importlib.resources.path(__name__,"web/static")
@ -233,6 +234,7 @@ def static(path):
### DYNAMIC
@profile
def jinja_page(name):
if name in aliases: redirect(aliases[name])
keys = remove_identical(FormsDict.decode(request.query))
@ -292,6 +294,31 @@ def redirect_track(artists,title):
#####
# warning interception
import logging
class WaitressLogHandler():
def __init__(self):
self.lastwarned = 0
self.barrier = 5
self.level = 20
self.filters = []
def handle(self,record):
if record.name == 'waitress.queue':
now = time.time()
depth = record.args[0]
if depth > self.barrier:
log(f"Waitress Task Queue Depth at {depth}")
self.lastwarned = now
self.barrier = max(depth,self.barrier+5)
elif now - self.lastwarned > 5:
self.barrier = max(5,self.barrier-5)
else:
log(f"Waitress: {record.msg % record.args}")
logging.getLogger().addHandler(WaitressLogHandler())
def run_server():
log("Starting up Maloja server...")
@ -299,6 +326,7 @@ def run_server():
Thread(target=database.start_db).start()
try:
#run(webserver, host=HOST, port=MAIN_PORT, server='waitress')
log(f"Listening on {HOST}:{PORT}")

View File

@ -44,7 +44,7 @@ def upgrade_apikeys():
def upgrade_db(callback_add_scrobbles):
oldfolder = os.path.join(dir_settings['state'],"scrobbles")
newfolder = os.path.join(dir_settings['state'],".oldscrobbles")
newfolder = os.path.join(dir_settings['state'],".v2scrobbles")
os.makedirs(newfolder,exist_ok=True)
if os.path.exists(oldfolder):
scrobblefiles = [f for f in os.listdir(oldfolder) if f.endswith(".tsv")]
@ -67,7 +67,7 @@ def upgrade_db(callback_add_scrobbles):
scrobblelist = []
log(f"\tImporting from {sf} ({idx}/{len(scrobblefiles)}) - {len(scrobbles)} Scrobbles")
for scrobble in scrobbles:
timestamp, artists, title, album, duration = scrobble
timestamp, artists, title, album, duration, *_ = scrobble + [None,None]
if album in ('-',''): album = None
if duration in ('-',''): duration = None
scrobblelist.append({

View File

@ -3,8 +3,10 @@
<html>
<head>
<title>{% block title %}{% endblock %}</title>
<meta charset="UTF-8" />
<meta name="referrer" content="same-origin" />
<title>{% block title %}{% endblock %}</title>
<meta name="description" content='Maloja is a self-hosted music scrobble server.' />
<meta name="color-scheme" content="dark" />

View File

@ -65,6 +65,7 @@
With Admin Mode activated, you can:
<ul>
<li>manually scrobble from track pages</li>
<li>delete scrobbles</li>
<li>upload artist and track art by dropping a file on the existing image on an artist or track page</li>
<li>see more detailed error pages</li>
</ul>

View File

@ -2,14 +2,14 @@
{% import 'snippets/links.jinja' as links %}
{% if 'artists' in entity %}
{% if entity is mapping and 'artists' in entity %}
{% set img = images.get_track_image(entity) %}
{% else %}
{% set img = images.get_artist_image(entity) %}
{% endif %}
<td class='icon'><div style="background-image:url('{{ img }}')"></div></td>
{% if "artists" in entity %}
{% if entity is mapping and 'artists' in entity %}
{% if settings['TRACK_SEARCH_PROVIDER'] %}
<td class='searchProvider'>{{ links.link_search(entity) }}</td>
{% endif %}

View File

@ -1,5 +1,5 @@
{% macro link(entity) -%}
{% if 'artists' in entity %}
{% if entity is mapping and 'artists' in entity %}
{% set name = entity.title %}
{% else %}
{% set name = entity %}
@ -17,7 +17,7 @@
{% macro url(entity) %}
{% if 'artists' in entity -%}
{% if entity is mapping and 'artists' in entity -%}
{{ mlj_uri.create_uri("/track",{'track':entity}) }}
{%- else -%}
{{ mlj_uri.create_uri("/artist",{'artist':entity}) }}

View File

@ -1,6 +1,6 @@
[project]
name = "malojaserver"
version = "3.0.0"
version = "3.0.2"
description = "Self-hosted music scrobble database"
readme = "./README.md"
requires-python = ">=3.6"
@ -21,7 +21,7 @@ classifiers = [
dependencies = [
"bottle>=0.12.16",
"waitress>=1.3",
"doreah>=1.9.0, <2",
"doreah>=1.9.1, <2",
"nimrodel>=0.8.0",
"setproctitle>=1.1.10",
#"pyvips>=2.1.16",