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

Added predefined rule modules

This commit is contained in:
Krateng
2019-03-24 14:56:34 +01:00
parent 2246efb4b4
commit 3f22d6bc75
10 changed files with 279 additions and 41 deletions

View File

@@ -40,9 +40,9 @@ div.header {
left:0px;
padding:10px;
opacity:1;
color:black;
z-index:5;
}
@@ -111,7 +111,7 @@ div.footer input {
div.footer input:focus {
outline:none;
/**background-color:rgba(245,245,220,0.05);**/
}
div.searchresults {
@@ -139,7 +139,7 @@ div.searchresults tr {
margin-bottom:5px;
height:50px;
cursor:pointer;
}
div.searchresults tr:hover {
background-color:rgba(35,35,35,1);
@@ -253,7 +253,7 @@ span.stat_selector_pulse,span.stat_selector_topartists,span.stat_selector_toptra
table.list {
border-collapse:collapse;
}
table.list tr td {
@@ -263,7 +263,7 @@ table.list tr td {
overflow:hidden;
text-overflow:ellipsis;
padding-right:15px;
}
table.list tr:nth-child(even) {
@@ -272,7 +272,7 @@ table.list tr:nth-child(even) {
table.list tr:nth-child(5n) td {
border-color:rgba(120,120,120,0.2);
}
table.list tr:hover {
@@ -281,7 +281,7 @@ table.list tr:hover {
table.list td.time {
width:11%;
color:gray;
color:gray;
}
@@ -300,8 +300,16 @@ table.list td.icon div {
table.list td.artists,td.artist,td.title {
min-width:100px;
}
table th {
text-align: left;
}
table td.interaction {
width:65px;
}
@@ -317,14 +325,14 @@ table tr td.artists div span {
z-index:-2;
position:relative;
white-space:nowrap;
}
table tr:hover td.artists div span {
animation: bounce 3s linear infinite alternate;
}
@keyframes bounce {
0% {
}
100% {
//transform: translateX(-60px);
@@ -479,5 +487,5 @@ div.sidelist table {
}
div.sidelist table.list td.time {
width:17%;
width:17%;
}

View File

@@ -4,7 +4,7 @@
<head>
<meta charset="UTF-8" />
<title>Maloja - Setup</title>
<script>
function replaceurls() {
url = window.location.origin
@@ -13,23 +13,46 @@
s[i].innerHTML = url
}
}
function replace() {
replaceurls();
}
function activateRuleModule(e,filename) {
keys = "filename=" + encodeURIComponent(filename)
var xhttp = new XMLHttpRequest();
xhttp.open("POST","/db/importrules", true);
xhttp.send(keys);
e.innerHTML = e.innerHTML.replace("Add","Remove")
e.getAttributeNode("onclick").value = e.getAttribute("onclick").replace("activate","deactivate")
/* Nobody ever look at this code please */
}
function deactivateRuleModule(e,filename) {
keys = "remove&filename=" + encodeURIComponent(filename)
var xhttp = new XMLHttpRequest();
xhttp.open("POST","/db/importrules", true);
xhttp.send(keys);
e.innerHTML = e.innerHTML.replace("Remove","Add")
e.getAttributeNode("onclick").value = e.getAttribute("onclick").replace("deactivate","activate")
}
</script>
<style>
td {
padding-right:20px;
}
</style>
</head>
<body onload="replace()">
<table class="top_info">
<tr>
@@ -38,18 +61,18 @@
</td>
<td class="text">
<h1>Maloja</h1><br/>
<p class="desc">Welcome to your own Maloja server!</p>
</td>
</tr>
</table>
<h2>Start Scrobbling</h2>
If you use Vivaldi, Brave, Iridium or any other Chromium-based browser and listen to music on Plex, 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.
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.
<br/><br/>
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
<span class="stats"><span name="serverurl">yourserver.tld</span>/db/newscrobble</span>
(make sure to use the public URL) with the key-value-pairs
@@ -63,29 +86,35 @@
<tr> <td>seconds</td> <td><i>Duration of Scrobble - optional and currently not used</i></td> </tr>
</table>
</span>
<br/><br/>
<h2>Import your Last.FM data</h2>
Switching from Last.fm? <a class="textlink" href="https://benjaminbenben.com/lastfm-to-csv/">Download all your data</a> and place the resulting file in your Maloja main folder. Run the command <span class="stats">./lastfmconverter.py <i>(the file you just downloaded)</i> lastfmimport.tsv</span>.
<br/><br/>
<h2>Set up some rules</h2>
After you've scrobbled for a bit, you might want to check the <a class="textlink" href="/issues">Issues page</a> 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.
<br/><br/>
<h2>Say thanks</h2>
Coding open source projects is fun, but not really monetizable. If you like Maloja, I would appreciate a small donation via
<a class="textlink" target="_blank" rel="noopener noreferrer" href="https://paypal.me/krateng">PayPal</a> or <a class="textlink" href="bitcoin:1krat8JMniJBTiHftMfR1LtF3Y1w5DAxx">Bitcoin</a>.
You can also set up some predefined rulesets right away!
<br/><br/>
KEY_PREDEFINED_RULESETS
<br/><br/>
<h2>Say thanks</h2>
Coding open source projects is fun, but not really monetizable. If you like Maloja, I would appreciate a small donation via
<a class="textlink" target="_blank" rel="noopener noreferrer" href="https://paypal.me/krateng">PayPal</a> or <a class="textlink" href="bitcoin:1krat8JMniJBTiHftMfR1LtF3Y1w5DAxx">Bitcoin</a>.
<br/><br/>
<h2>View your stats</h2>
Done! Visit <a class="textlink" href="/"><span name="serverurl">yourserver.tld</span></a> (or your public / proxy URL) to look at your overview page. Almost everything is clickable!
</body>
</html>

44
website/setup.py Normal file
View File

@@ -0,0 +1,44 @@
import os
def instructions(keys):
html = "<table>"
html += "<tr><th></th><th>Module</th><th>Author</th><th>Description</th></tr>"
for f in os.listdir("rules/predefined"):
if f.endswith(".tsv"):
try:
with open("rules/predefined/" + f) as tsvfile:
line1 = tsvfile.readline()
line2 = tsvfile.readline()
if "# NAME: " in line1:
name = line1.replace("# NAME: ","")
else: name = f
if "# DESC: " in line2:
desc = line2.replace("# DESC: ","")
else: desc = ""
author = f.split("_")[0]
except:
continue
html += "<tr>"
if os.path.exists("rules/" + f):
html += "<td class='interaction' onclick=deactivateRuleModule(this,'" + f.replace(".tsv","") + "')><a class='textlink'>Remove:</a></td>"
else:
html += "<td class='interaction' onclick=activateRuleModule(this,'" + f.replace(".tsv","") + "')><a class='textlink'>Add:</a></td>"
html += "<td>" + name + "</td>"
html += "<td>" + author + "</td>"
html += "<td>" + desc + "</td>"
html += "</tr>"
html += "</table>"
pushresources = []
replace = {"KEY_PREDEFINED_RULESETS":html}
return (replace,pushresources)