diff --git a/README.md b/README.md index 4bdcf7a..bc3105f 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,9 @@ The software works fairly well and has a few web views, but there is only one sc ## Requirements -* [bottle.py](https://github.com/bottlepy/bottle) -* [waitress](https://github.com/Pylons/waitress) +* [python3](https://www.python.org/) - [GitHub](https://github.com/python/cpython) +* [bottle.py](https://bottlepy.org/) - [GitHub](https://github.com/bottlepy/bottle) +* [waitress](https://docs.pylonsproject.org/projects/waitress/) - [GitHub](https://github.com/Pylons/waitress) ## How to install @@ -35,7 +36,13 @@ Installing Maloja is fairly easy on a Linux machine. Don't ask me how to do it o ./maloja start -If you're missing packages, the console output will tell you so. Install them. + If you're missing packages, the console output will tell you so. Install them. + + You can also only download the maloja file itself and run + + ./maloja update + + to download the rest of the repository, then start it as described above. 2) (Recommended) Put your server behind a reverse proxy for SSL encryption. Configure that proxy to rewrite /db/ requests to the database port. In nginx this would look as follows: diff --git a/database.py b/database.py index 21c1183..dc748c8 100644 --- a/database.py +++ b/database.py @@ -232,7 +232,6 @@ def get_tracks_external(): def get_tracks(artist=None): - if artist is not None: artistid = ARTISTS.index(artist) else: diff --git a/htmlgenerators.py b/htmlgenerators.py index 39b93ac..66d16d9 100644 --- a/htmlgenerators.py +++ b/htmlgenerators.py @@ -1,8 +1,9 @@ +import urllib +from bottle import FormsDict +import datetime - -def artistLink(name): - import urllib +def artistLink(name): return "" + name + "" def artistLinks(artists): @@ -11,25 +12,21 @@ def artistLinks(artists): #def trackLink(artists,title): def trackLink(track): artists,title = track["artists"],track["title"] - import urllib return "" + title + "" #def scrobblesTrackLink(artists,title,timekeys,amount=None,pixels=None): def scrobblesTrackLink(track,timekeys,amount=None,percent=None): artists,title = track["artists"],track["title"] - import urllib inner = str(amount) if amount is not None else "
" return "" + inner + "" def scrobblesArtistLink(artist,timekeys,amount=None,percent=None,associated=False): - import urllib inner = str(amount) if amount is not None else "
" askey = "&associated" if associated else "" return "" + inner + "" # necessary because urllib.parse.urlencode doesnt handle multidicts def keysToUrl(*dicts): - import urllib st = "" keys = removeIdentical(*dicts) for k in keys: @@ -39,8 +36,6 @@ def keysToUrl(*dicts): return st def removeIdentical(*dicts): - from bottle import FormsDict - #combine multiple dicts keys = FormsDict() for d in dicts: @@ -61,7 +56,6 @@ def removeIdentical(*dicts): return new def getTimeDesc(timestamp,short=False): - import datetime tim = datetime.datetime.utcfromtimestamp(timestamp) if short: now = datetime.datetime.now(tz=datetime.timezone.utc) @@ -87,7 +81,6 @@ def getTimeDesc(timestamp,short=False): # limit a multidict to only the specified keys # would be a simple constructor expression, but multidicts apparently don't let me do that def pickKeys(d,*keys): - from bottle import FormsDict if isinstance(d,dict): return {k:d.get(k) for k in d if k in keys} else: @@ -103,7 +96,6 @@ def pickKeys(d,*keys): # removes all duplicate keys, except artists when a title is specified def clean(d): - from bottle import FormsDict if isinstance(d,dict): return else: diff --git a/logs/.gitignore b/logs/.gitignore index 2211df6..397b4a7 100644 --- a/logs/.gitignore +++ b/logs/.gitignore @@ -1 +1 @@ -*.txt +*.log diff --git a/maloja b/maloja index 30a431a..c22443d 100755 --- a/maloja +++ b/maloja @@ -13,25 +13,100 @@ neededmodules = [ "setproctitle" ] +recommendedmodules = [ + "wand" +] + SOURCE_URL = "https://github.com/krateng/maloja/archive/master.zip" def install(): toinstall = [] + toinstallr = [] for m in neededmodules: try: exec("import " + m) #I'm sorry except: toinstall.append(m) + for m in recommendedmodules: + try: + exec("import " + m) + except: + toinstallr.append(m) + if toinstall != []: print("The following python modules need to be installed:") for m in toinstall: print("\t" + m) - else: - return + if toinstallr != []: + print("The following python modules are highly recommended, some features will not work without them:") + for m in toinstallr: + print("\t" + m) + if toinstall != [] or toinstallr != []: + if os.geteuid() != 0: + print("Installing python modules should be fairly straight-forward, but Maloja can try to install \ + them automatically. For this, you need to run this script as a root user.") + return False + else: + print("Installing python modules should be fairly straight-forward, but Maloja can try to install \ + them automatically, This might or might not work / bloat your system / cause a nuclear war.") + fail = False + if toinstall != []: + print("Attempt to install required modules? [Y/n]") + answer = input() + + if answer.lower() in ["y","yes","yea","1","positive","true"]: + for m in neededmodules: + try: + print("Installing " + m + " with pip...") + import pip + #os.system("pip3 install " + m) + pip.main(["install",m]) + print("Success!") + except: + print("Failure!") + fail = True + + elif answer.lower() in ["n","no","nay","0","negative","false"]: + return False #if you dont want to auto install required, you probably dont want to install recommended + else: + print("What?") + return False + if toinstallr != []: + print("Attempt to install recommended modules? [Y/n]") + answer = input() + + if answer.lower() in ["y","yes","yea","1","positive","true",""]: + for m in recommendedmodules: + try: + print("Installing " + m + " with pip...") + import pip + #os.system("pip3 install " + m) + pip.main(["install",m]) + print("Success!") + except: + print("Failure!") + fail = True + + elif answer.lower() in ["n","no","nay","0","negative","false"]: + return False + else: + print("What?") + return False + + if fail: return False + print("All modules successfully installed!") + return True + + else: + print("All necessary modules seem to be installed.") + return True + + + def getInstance(): try: output = subprocess.check_output(["pidof","Maloja"]) @@ -44,15 +119,16 @@ def getInstance(): def start(): - install() + if install(): - try: - p = subprocess.Popen(["python3","server.py"],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL) - print("Maloja started! PID: " + str(p.pid)) - return True - except: - print("Error while starting Maloja. Are you sure it's not already running?") - return False + try: + p = subprocess.Popen(["python3","server.py"],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL) + print("Maloja started! PID: " + str(p.pid)) + return True + except: + print("Error while starting Maloja. Are you sure it's not already running?") + return False + def restart(): @@ -73,8 +149,8 @@ def stop(): print("Server is not running") return False else: - print("Stopping " + str(pid)) os.kill(pid,signal.SIGTERM) + print("Maloja stopped! PID: " + str(pid)) return True def update(): @@ -93,7 +169,7 @@ def update(): with zipfile.ZipFile(tmpfile.name,"r") as z: for f in z.namelist(): - print("extracting " + f) + #print("extracting " + f) z.extract(f) @@ -112,4 +188,5 @@ if __name__ == "__main__": elif sys.argv[1] == "restart": restart() elif sys.argv[1] == "stop": stop() elif sys.argv[1] == "update": update() + else: print("Valid commands: start restart stop update") diff --git a/utilities.py b/utilities.py index 613d41d..8a46ac3 100644 --- a/utilities.py +++ b/utilities.py @@ -162,7 +162,8 @@ def log(msg): module = inspect.getmodule(inspect.stack()[1][0]).__name__ if module == "__main__": module = "mainserver" print("[" + module + "] " + msg) - # best function ever + with open("logs/" + module + ".log","a") as logfile: + logfile.write(msg + "\n") ### Media info diff --git a/website/start.html b/website/start.html index 617d876..88f05c1 100644 --- a/website/start.html +++ b/website/start.html @@ -272,7 +272,7 @@