From 80686fd4e10019e68c00fb4df9f0ea634e612451 Mon Sep 17 00:00:00 2001 From: krateng Date: Fri, 15 Feb 2019 19:45:08 +0100 Subject: [PATCH 1/8] Minor fix --- database.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database.py b/database.py index 58d2074..d887726 100644 --- a/database.py +++ b/database.py @@ -698,7 +698,7 @@ def db_query(artists=None,title=None,track=None,since=None,to=None,within=None,a # Queries that... well... aggregate -def db_aggregate(by=None,since=None,to=None,withinin=None,artist=None): +def db_aggregate(by=None,since=None,to=None,within=None,artist=None): (since, to) = getTimestamps(since,to,within) if isinstance(artist, str): From 6540af0e5565837efad4347c5235400f6d72aa9d Mon Sep 17 00:00:00 2001 From: Krateng Date: Sat, 16 Feb 2019 16:42:45 +0100 Subject: [PATCH 2/8] Implemented caching of image links on disk --- database.py | 6 ++++++ mediacache | Bin 0 -> 9056 bytes server.py | 2 +- utilities.py | 20 ++++++++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 mediacache diff --git a/database.py b/database.py index d887726..b352967 100644 --- a/database.py +++ b/database.py @@ -618,6 +618,9 @@ def build_db(): global db_rulestate db_rulestate = consistentRulestate("scrobbles",cla.checksums) + # load cached images + loadCache() + @@ -653,6 +656,9 @@ def sync(): global lastsync lastsync = int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp()) log("Database saved to disk.") + + # save cached images + saveCache() diff --git a/mediacache b/mediacache new file mode 100644 index 0000000000000000000000000000000000000000..4cd23b759a42a85fe3e56a5feee55a239c68bad9 GIT binary patch literal 9056 zcmcIqXLKCLk*2In1u9wD_Q;k6&^C$5K@KuNkOU}zga#0}k}ccaJw4a~W@pg7v!Ir? zY&me8bCT1YFP|^xoOLgwvRs`2QBkEmVK zf{%)_DXQV_T-PUMHI&V6b-_dGX}!yL?b1SH+h56MrkEMc zIFUb`@pEBI*9#KQjb!NMnaE@oawm5K#-z*kZ&w@YvOe%!eiokHz;i{auAGSLdcfJ3 z_0?6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vgUcn3%vVpH__=7{|M6YORk#25iUBqtG4?dEW@<%Q6l_uQT^yOsi8G*%7Oxj040;Bw^^I4ivv$iym%E86V^3S zaJmMl@5d*gTt}1YFwF3%G|bpozY>yGzl!7?;UP9f zequ`;E<5&}I6^%tN6HxIju*j4&1N%9Oz=14Bn-962O-|Fpn3z^ICIz2|1)PK& zHh(pmRKJD>Q9x)F zo6w~C6!plWpO~G9qV_ThrT%GRD%L5!z-nWP>4H@+cx)N)a>wxZlcROY2wdLX5IzC z<`pD0yiIC37+XXmrGEE$fM5aEhHPI-R25LDilH3OB1z2ghV6S3lfQ>1Hr`z1IRjCc zEq7|2>Gz(8Lcx98V*wXljE!b75+%G4%TRbkWTYu<==Yso-#ptXGOAo7;OqCFhdQJ= zv6PMwHeP`Ry+TLWS*jmM*Y?ASkw0)+-K3a5c`(%Ks&(So%QYx^iB-XsdVNi1}enAj%Kp-tjF zn?yDYTU%nNv08Il_6Pc7B Date: Sat, 16 Feb 2019 16:47:01 +0100 Subject: [PATCH 3/8] Whoops --- images/.gitignore | 1 + mediacache | Bin 9056 -> 0 bytes utilities.py | 4 ++-- 3 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 images/.gitignore delete mode 100644 mediacache diff --git a/images/.gitignore b/images/.gitignore new file mode 100644 index 0000000..06cf653 --- /dev/null +++ b/images/.gitignore @@ -0,0 +1 @@ +cache diff --git a/mediacache b/mediacache deleted file mode 100644 index 4cd23b759a42a85fe3e56a5feee55a239c68bad9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9056 zcmcIqXLKCLk*2In1u9wD_Q;k6&^C$5K@KuNkOU}zga#0}k}ccaJw4a~W@pg7v!Ir? zY&me8bCT1YFP|^xoOLgwvRs`2QBkEmVK zf{%)_DXQV_T-PUMHI&V6b-_dGX}!yL?b1SH+h56MrkEMc zIFUb`@pEBI*9#KQjb!NMnaE@oawm5K#-z*kZ&w@YvOe%!eiokHz;i{auAGSLdcfJ3 z_0?6ay1F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n3%vVpH__=7{|M6YORk#25iUBqtG4?dEW@<%Q6l_uQT^yOsi8G*%7Oxj040;Bw^^I4ivv$iym%E86V^3S zaJmMl@5d*gTt}1YFwF3%G|bpozY>yGzl!7?;UP9f zequ`;E<5&}I6^%tN6HxIju*j4&1N%9Oz=14Bn-962O-|Fpn3z^ICIz2|1)PK& zHh(pmRKJD>Q9x)F zo6w~C6!plWpO~G9qV_ThrT%GRD%L5!z-nWP>4H@+cx)N)a>wxZlcROY2wdLX5IzC z<`pD0yiIC37+XXmrGEE$fM5aEhHPI-R25LDilH3OB1z2ghV6S3lfQ>1Hr`z1IRjCc zEq7|2>Gz(8Lcx98V*wXljE!b75+%G4%TRbkWTYu<==Yso-#ptXGOAo7;OqCFhdQJ= zv6PMwHeP`Ry+TLWS*jmM*Y?ASkw0)+-K3a5c`(%Ks&(So%QYx^iB-XsdVNi1}enAj%Kp-tjF zn?yDYTU%nNv08Il_6Pc7B Date: Sat, 16 Feb 2019 17:31:01 +0100 Subject: [PATCH 4/8] Added self-updater script --- updater.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 updater.py diff --git a/updater.py b/updater.py new file mode 100644 index 0000000..ebadcad --- /dev/null +++ b/updater.py @@ -0,0 +1,29 @@ +import urllib.request +import shutil +import tempfile +import zipfile +import distutils.dir_util +#import os + +SOURCE_URL = "https://github.com/krateng/maloja/archive/master.zip" + + +update() + +def update(): + print("Updating Maloja...") + with urllib.request.urlopen(SOURCE_URL) as response: + with tempfile.NamedTemporaryFile(delete=True) as tmpfile: + shutil.copyfileobj(response,tmpfile) + + with zipfile.ZipFile(tmpfile.name,"r") as z: + + for f in z.namelist(): + print("extracting " + f) + z.extract(f) + + + + distutils.dir_util.copy_tree("./maloja-master/","./",verbose=2) + shutil.rmtree("./maloja-master") + print("Done!") From 15a423060c76d29c98734212392664be6296be63 Mon Sep 17 00:00:00 2001 From: Krateng Date: Sat, 16 Feb 2019 20:10:12 +0100 Subject: [PATCH 5/8] Janky self-restarter --- README.md | 6 +----- restarter.py | 25 +++++++++++++++++++++++++ server.py | 7 +++++++ updater.py | 11 +++++++++-- 4 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 restarter.py diff --git a/README.md b/README.md index 1ca7432..0774bea 100644 --- a/README.md +++ b/README.md @@ -12,10 +12,6 @@ Maloja is self-hosted. You will always be able to access your data, and not have Maloja gets rid of all the extra stuff: social networking, radios, recommendations, etc. It only keeps track of your listening history and lets you analyze it. This focus on its core allows it to potentially implement much better database features. One example: Maloja supports multiple artists per track. This means artists who are often just "featuring" in the track title get a place in your charts, and collaborations between several artists finally get credited to all participants. -### Why not use the established API? - -Compatibility creates overhead effort. I only made this for myself, so I have no need to support lots of music players and scrobblers. Maloja has a significantly smaller API that allows it to be much simpler and implement its additional features. - ### Why Maloja? I like to name my projects after regions in Grisons, Switzerland. Don't waste your time trying to find a connection, I just picked one at random. Do visit Maloja though. It's a great pass to drive. @@ -28,7 +24,7 @@ The software works fairly well and has a few web views, but there is only one sc ## How to install -Installing Maloja is fairly easy on a Linux machine. Don't ask me how to do it on Windows, I have no clue. +Installing Maloja is fairly easy on a Linux machine. Don't ask me how to do it on Windows, I have no clue. Don't ask me to add any lines to make it work on Windows either, the code is already shitty enough. 1) Install the requirements: diff --git a/restarter.py b/restarter.py new file mode 100644 index 0000000..57b28ed --- /dev/null +++ b/restarter.py @@ -0,0 +1,25 @@ +import subprocess +import time + +def startserver(): + time.sleep(5) + print("Starting the Maloja server...") + + p = subprocess.Popen(["python3","server.py"]) + exit("Restarter has done his job and is exiting!") + + +def restart(): + #args = sys.argv[:] + print("Starting the restarter...") + + #args.insert(0, sys.executable) + #print(' '.join(args)) + + p = subprocess.Popen(["python3","restarter.py"]) + #exit("Exiting!") + + + +if __name__ == "__main__": + startserver() diff --git a/server.py b/server.py index 0194430..690032c 100755 --- a/server.py +++ b/server.py @@ -12,6 +12,7 @@ from urllib.error import * import sys import signal import os +import restarter MAIN_PORT = 42010 @@ -67,6 +68,12 @@ def database_post(pth): def shutdown(): graceful_exit() +@webserver.route("/restart") +def restart(): + urllib.request.urlopen("http://[::1]:" + str(DATABASE_PORT) + "/sync") + restarter.restart() + os._exit(42) + def graceful_exit(sig=None,frame=None): urllib.request.urlopen("http://[::1]:" + str(DATABASE_PORT) + "/sync") log("Server shutting down...") diff --git a/updater.py b/updater.py index ebadcad..d273317 100644 --- a/updater.py +++ b/updater.py @@ -4,12 +4,11 @@ import tempfile import zipfile import distutils.dir_util #import os +import sys SOURCE_URL = "https://github.com/krateng/maloja/archive/master.zip" -update() - def update(): print("Updating Maloja...") with urllib.request.urlopen(SOURCE_URL) as response: @@ -27,3 +26,11 @@ def update(): distutils.dir_util.copy_tree("./maloja-master/","./",verbose=2) shutil.rmtree("./maloja-master") print("Done!") + + + + + + +if __name__ == "__main__": + update() From 5c815b49f9f2375dedcba824567af6f5f9e87e75 Mon Sep 17 00:00:00 2001 From: Krateng Date: Sat, 16 Feb 2019 20:53:35 +0100 Subject: [PATCH 6/8] Improved daemon management --- maloja | 117 +++++++++++++++++++++++++++++++++++++++++++++------ restarter.py | 25 ----------- server.py | 10 ----- updater.py | 36 ---------------- 4 files changed, 104 insertions(+), 84 deletions(-) delete mode 100644 restarter.py delete mode 100644 updater.py diff --git a/maloja b/maloja index 742a562..83874a6 100755 --- a/maloja +++ b/maloja @@ -1,22 +1,113 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 + +import subprocess +import sys +import signal +import os + neededmodules = [ "bottle", "waitress" ] -toinstall = [] -for m in neededmodules: +SOURCE_URL = "https://github.com/krateng/maloja/archive/master.zip" + + + +def install(): + toinstall = [] + for m in neededmodules: + try: + exec("import " + m) #I'm sorry + except: + toinstall.append(m) + + if toinstall != []: + print("The following python modules need to be installed:") + for m in toinstall: + print("\t" + m) + else: + return + +def getInstance(): try: - exec("import " + m) #I'm sorry + output = subprocess.check_output(["pidof","Maloja"]) + pid = int(output) + return pid except: - toinstall.append(m) + return None + + + + +def start(): + 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 -if toinstall != []: - print("The following python modules need to be installed:") - for m in toinstall: - print("\t" + m) -else: - import subprocess - subprocess.Popen(["python","server.py"],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL) - print("Maloja started!") + +def restart(): + #pid = getInstance() + #if pid == None: + # print("Server is not running.") + #else: + # stop() + #start() + + wasrunning = stop() + start() + return wasrunning + +def stop(): + pid = getInstance() + if pid == None: + print("Server is not running") + return False + else: + print("Stopping " + str(pid)) + os.kill(pid,signal.SIGTERM) + return True + +def update(): + + import urllib.request + import shutil + import tempfile + import zipfile + import distutils.dir_util + + print("Updating Maloja...") + with urllib.request.urlopen(SOURCE_URL) as response: + with tempfile.NamedTemporaryFile(delete=True) as tmpfile: + shutil.copyfileobj(response,tmpfile) + + with zipfile.ZipFile(tmpfile.name,"r") as z: + + for f in z.namelist(): + print("extracting " + f) + z.extract(f) + + + + distutils.dir_util.copy_tree("./maloja-master/","./",verbose=2) + shutil.rmtree("./maloja-master") + print("Done!") + + os.chmod("maloja",stat.S_IXUSR) + + if stop(): start() #stop returns whether it was running before, in which case we restart it + + +if __name__ == "__main__": + if sys.argv[1] == "start": start() + elif sys.argv[1] == "restart": restart() + elif sys.argv[1] == "stop": stop() + elif sys.argv[1] == "update": update() + diff --git a/restarter.py b/restarter.py deleted file mode 100644 index 57b28ed..0000000 --- a/restarter.py +++ /dev/null @@ -1,25 +0,0 @@ -import subprocess -import time - -def startserver(): - time.sleep(5) - print("Starting the Maloja server...") - - p = subprocess.Popen(["python3","server.py"]) - exit("Restarter has done his job and is exiting!") - - -def restart(): - #args = sys.argv[:] - print("Starting the restarter...") - - #args.insert(0, sys.executable) - #print(' '.join(args)) - - p = subprocess.Popen(["python3","restarter.py"]) - #exit("Exiting!") - - - -if __name__ == "__main__": - startserver() diff --git a/server.py b/server.py index 690032c..0ca0b3d 100755 --- a/server.py +++ b/server.py @@ -12,7 +12,6 @@ from urllib.error import * import sys import signal import os -import restarter MAIN_PORT = 42010 @@ -64,15 +63,6 @@ def database_post(pth): return -@webserver.route("/exit") -def shutdown(): - graceful_exit() - -@webserver.route("/restart") -def restart(): - urllib.request.urlopen("http://[::1]:" + str(DATABASE_PORT) + "/sync") - restarter.restart() - os._exit(42) def graceful_exit(sig=None,frame=None): urllib.request.urlopen("http://[::1]:" + str(DATABASE_PORT) + "/sync") diff --git a/updater.py b/updater.py deleted file mode 100644 index d273317..0000000 --- a/updater.py +++ /dev/null @@ -1,36 +0,0 @@ -import urllib.request -import shutil -import tempfile -import zipfile -import distutils.dir_util -#import os -import sys - -SOURCE_URL = "https://github.com/krateng/maloja/archive/master.zip" - - -def update(): - print("Updating Maloja...") - with urllib.request.urlopen(SOURCE_URL) as response: - with tempfile.NamedTemporaryFile(delete=True) as tmpfile: - shutil.copyfileobj(response,tmpfile) - - with zipfile.ZipFile(tmpfile.name,"r") as z: - - for f in z.namelist(): - print("extracting " + f) - z.extract(f) - - - - distutils.dir_util.copy_tree("./maloja-master/","./",verbose=2) - shutil.rmtree("./maloja-master") - print("Done!") - - - - - - -if __name__ == "__main__": - update() From 79b2d0582497ccf9eb7fa51937b00414422b1641 Mon Sep 17 00:00:00 2001 From: Krateng Date: Sat, 16 Feb 2019 21:04:13 +0100 Subject: [PATCH 7/8] Fixed update bug --- maloja | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/maloja b/maloja index 83874a6..0f29f5f 100755 --- a/maloja +++ b/maloja @@ -4,6 +4,7 @@ import subprocess import sys import signal import os +import stat neededmodules = [ @@ -100,7 +101,7 @@ def update(): shutil.rmtree("./maloja-master") print("Done!") - os.chmod("maloja",stat.S_IXUSR) + os.chmod("./maloja",os.stat("./maloja").st_mode | stat.S_IXUSR) if stop(): start() #stop returns whether it was running before, in which case we restart it From e8fbf95c30745905ef5e867defc67d8b21560e5f Mon Sep 17 00:00:00 2001 From: Krateng Date: Sat, 16 Feb 2019 21:21:29 +0100 Subject: [PATCH 8/8] Added requirement --- maloja | 3 ++- server.py | 9 +++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/maloja b/maloja index 0f29f5f..30a431a 100755 --- a/maloja +++ b/maloja @@ -9,7 +9,8 @@ import stat neededmodules = [ "bottle", - "waitress" + "waitress", + "setproctitle" ] SOURCE_URL = "https://github.com/krateng/maloja/archive/master.zip" diff --git a/server.py b/server.py index 0ca0b3d..e5bba39 100755 --- a/server.py +++ b/server.py @@ -12,6 +12,7 @@ from urllib.error import * import sys import signal import os +import setproctitle MAIN_PORT = 42010 @@ -114,12 +115,8 @@ def static_html(name): signal.signal(signal.SIGINT, graceful_exit) signal.signal(signal.SIGTERM, graceful_exit) -#rename process, not important -try: - import setproctitle - setproctitle.setproctitle("Maloja") -except: - pass +#rename process, this is now required for the daemon manager to work +setproctitle.setproctitle("Maloja") ## start database server _thread.start_new_thread(SourceFileLoader("database","database.py").load_module().runserver,(DATABASE_PORT,))