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 0000000..4cd23b7 Binary files /dev/null and b/mediacache differ diff --git a/server.py b/server.py index 649a110..0194430 100755 --- a/server.py +++ b/server.py @@ -68,7 +68,7 @@ def shutdown(): graceful_exit() def graceful_exit(sig=None,frame=None): - urllib.request.urlopen("http://localhost:" + str(DATABASE_PORT) + "/sync") + urllib.request.urlopen("http://[::1]:" + str(DATABASE_PORT) + "/sync") log("Server shutting down...") os._exit(42) diff --git a/utilities.py b/utilities.py index ba652f0..224cae1 100644 --- a/utilities.py +++ b/utilities.py @@ -2,6 +2,7 @@ import re import os import hashlib from threading import Thread +import pickle ### TSV files @@ -211,6 +212,25 @@ def apirequest(artists=None,artist=None,title=None): cachedTracks = {} cachedArtists = {} +def saveCache(): + fl = open("mediacache","wb") + stream = pickle.dumps((cachedTracks,cachedArtists)) + fl.write(stream) + fl.close() + +def loadCache(): + try: + fl = open("mediacache","rb") + except: + return + + try: + ob = pickle.loads(fl.read()) + global cachedTracks, cachedArtists + (cachedTracks, cachedArtists) = ob + finally: + fl.close() + def getTrackInfo(artists,title): obj = (frozenset(artists),title)