From 0ddb5a4dd9f970c3520053efc2ad961357b2f281 Mon Sep 17 00:00:00 2001 From: Krateng Date: Wed, 29 Jul 2020 17:49:55 +0200 Subject: [PATCH] Updated server setup page --- maloja/database.py | 47 ++++++++++++ maloja/web/jinja/setup.jinja | 140 +++++++++++++++++++++++++++++++++++ maloja/web/setup.html | 133 --------------------------------- maloja/web/setup.py | 57 -------------- 4 files changed, 187 insertions(+), 190 deletions(-) create mode 100644 maloja/web/jinja/setup.jinja delete mode 100644 maloja/web/setup.html delete mode 100644 maloja/web/setup.py diff --git a/maloja/database.py b/maloja/database.py index 608da89..c3dec71 100644 --- a/maloja/database.py +++ b/maloja/database.py @@ -829,6 +829,53 @@ def issues(): return {"duplicates":duplicates,"combined":combined,"newartists":newartists,"inconsistent":inconsistent} +def get_predefined_rulesets(): + validchars = "-_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" + + rulesets = [] + + for f in os.listdir(datadir("rules/predefined")): + if f.endswith(".tsv"): + + rawf = f.replace(".tsv","") + valid = True + for char in rawf: + if char not in validchars: + valid = False + break # don't even show up invalid filenames + + if not valid: continue + if not "_" in rawf: continue + + try: + with open(datadir("rules/predefined",f)) as tsvfile: + line1 = tsvfile.readline() + line2 = tsvfile.readline() + + if "# NAME: " in line1: + name = line1.replace("# NAME: ","") + else: name = rawf.split("_")[1] + if "# DESC: " in line2: + desc = line2.replace("# DESC: ","") + else: desc = "" + + author = rawf.split("_")[0] + except: + continue + + ruleset = {"file":rawf} + rulesets.append(ruleset) + if os.path.exists(datadir("rules",f)): + ruleset["active"] = True + else: + ruleset["active"] = False + + ruleset["name"] = name + ruleset["author"] = author + ruleset["desc"] = desc + + return rulesets + @dbserver.post("importrules") def import_rulemodule(**keys): apikey = keys.pop("key",None) diff --git a/maloja/web/jinja/setup.jinja b/maloja/web/jinja/setup.jinja new file mode 100644 index 0000000..5fd88fe --- /dev/null +++ b/maloja/web/jinja/setup.jinja @@ -0,0 +1,140 @@ +{% extends "base.jinja" %} +{% block title %}Maloja - Setup{% endblock %} + +{% block scripts %} + + + +{% endblock %} + +{% set rulesets = dbp.get_predefined_rulesets() %} + +{% block content %} + + + + + + + +
+
+
+

Maloja


+ +

Welcome to your own Maloja server!

+
+ +

Start Scrobbling

+ + If you use Vivaldi, Brave, Iridium or any other Chromium-based browser and listen to music on Plex or YouTube Music, download the extension and simply enter the server URL as well as your API key in the relevant fields. They will turn green if the server is accessible. +

+ You can also use any standard-compliant scrobbler. For GNUFM (audioscrobbler) scrobblers, enter yourserver.tld/api/s/audioscrobbler as your Gnukebox server and your API key as the password. For Listenbrainz scrobblers, use yourserver.tld/api/s/listenbrainz as the API URL and your API key as token. +

+ If you use another browser or another music player, you could try to code your own extension. The API is super simple! Just send a POST HTTP request to + + yourserver.tld/api/newscrobble + + (make sure to use the public URL) with the key-value-pairs +
+
+ + + + + +
artist Artist String
title Title String
key API Key
seconds Duration of Scrobble - optional and currently not used
+

+ Finally, you could always manually scrobble! + +

+ +

Import your Last.FM data

+ + Switching from Last.fm? Download all your data and run the command maloja import (the file you just downloaded). +

+ +

Set up some rules

+ + After you've scrobbled for a bit, you might want to check the Issues page to see if you need to set up some rules. You can also manually add rules in your server's "rules" directory - just add your own .tsv file and read the instructions on how to declare a rule. +

+ + You can also set up some predefined rulesets right away! Enter your API key and click the buttons. +
+ +

+ + + + + + + + {% for rs in rulesets %} + + {% if rs.active %} + + {% else %} + + {% endif %} + + + + + {% endfor %} +
ModuleAuthorDescription
Remove:Add:{{ rs.name }}{{ rs.author }}{{ rs.desc }}
+ +

+ +

Say thanks

+ + Donations are never required, but always appreciated. If you really like Maloja, you can fund my next Buttergipfel via + PayPal, Bitcoin or Flattr. + +

+ +

View your stats

+ + Done! Visit yourserver.tld (or your public / proxy URL) to look at your overview page. Almost everything is clickable! + +{% endblock %} diff --git a/maloja/web/setup.html b/maloja/web/setup.html deleted file mode 100644 index fed262d..0000000 --- a/maloja/web/setup.html +++ /dev/null @@ -1,133 +0,0 @@ - - - - - - Maloja - Setup - - - - - - - - - - - - - - -
-
-
-

Maloja


- -

Welcome to your own Maloja server!

-
- -

Start Scrobbling

- - If you use Vivaldi, Brave, Iridium or any other Chromium-based browser and listen to music on Plex or YouTube Music, download the extension and simply enter the server URL as well as your API key in the relevant fields. They will turn green if the server is accessible. -

- You can also use any standard-compliant scrobbler. For GNUFM (audioscrobbler) scrobblers, enter yourserver.tld/api/s/audioscrobbler as your Gnukebox server and your API key as the password. For Listenbrainz scrobblers, use yourserver.tld/api/s/listenbrainz as the API URL and your API key as token. -

- If you use another browser or another music player, you could try to code your own extension. The API is super simple! Just send a POST HTTP request to - - yourserver.tld/api/newscrobble - - (make sure to use the public URL) with the key-value-pairs -
-
- - - - - -
artist Artist String
title Title String
key API Key
seconds Duration of Scrobble - optional and currently not used
-

- Finally, you could always manually scrobble! - -

- -

Import your Last.FM data

- - Switching from Last.fm? Download all your data and run the command maloja import (the file you just downloaded). -

- -

Set up some rules

- - After you've scrobbled for a bit, you might want to check the Issues page to see if you need to set up some rules. You can also manually add rules in your server's "rules" directory - just add your own .tsv file and read the instructions on how to declare a rule. -

- - You can also set up some predefined rulesets right away! Enter your API key and click the buttons. -
- API Key: - - -

- KEY_PREDEFINED_RULESETS - -

- -

Say thanks

- - Coding open source projects is fun, but not really monetizable. If you like Maloja, I would appreciate a small donation via - PayPal, Bitcoin or Flattr. - -

- -

View your stats

- - Done! Visit yourserver.tld (or your public / proxy URL) to look at your overview page. Almost everything is clickable! - - - - - diff --git a/maloja/web/setup.py b/maloja/web/setup.py deleted file mode 100644 index 596a3c1..0000000 --- a/maloja/web/setup.py +++ /dev/null @@ -1,57 +0,0 @@ -import os -from ..globalconf import datadir - -def instructions(keys): - - html = "" - - html += "" - - - validchars = "-_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" - for f in os.listdir(datadir("rules/predefined")): - if f.endswith(".tsv"): - - rawf = f.replace(".tsv","") - valid = True - for char in rawf: - if char not in validchars: - valid = False - break # don't even show up invalid filenames - - if not valid: continue - if not "_" in rawf: continue - - try: - with open(datadir("rules/predefined",f)) as tsvfile: - line1 = tsvfile.readline() - line2 = tsvfile.readline() - - if "# NAME: " in line1: - name = line1.replace("# NAME: ","") - else: name = rawf.split("_")[1] - if "# DESC: " in line2: - desc = line2.replace("# DESC: ","") - else: desc = "" - - author = rawf.split("_")[0] - except: - continue - - html += "" - - if os.path.exists(datadir("rules",f)): - html += "" - else: - html += "" - html += "" - html += "" - html += "" - - html += "" - html += "
ModuleAuthorDescription
Remove:Add:" + name + "" + author + "" + desc + "
" - - - pushresources = [] - replace = {"KEY_PREDEFINED_RULESETS":html} - return (replace,pushresources)