From 8b25fc4844b7dbf491e200c44f3b6575a9a615ba Mon Sep 17 00:00:00 2001 From: geoffrey45 Date: Wed, 16 Feb 2022 18:32:34 +0300 Subject: [PATCH] minor refactoring --- server/app/api.py | 11 +++++++---- server/app/functions.py | 2 +- server/app/helpers.py | 5 ++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/server/app/api.py b/server/app/api.py index 8dd5daa..e3d2b0f 100644 --- a/server/app/api.py +++ b/server/app/api.py @@ -16,7 +16,7 @@ def initialize() -> None: Runs all the necessary setup functions. """ helpers.create_config_dir() - helpers.check_for_new_songs() + helpers.reindex_tracks() helpers.start_watchdog() @@ -197,7 +197,7 @@ def get_artist_data(artist: str): @bp.route("/f/") -@cache.cached() +# @cache.cached(30) def get_folder_tree(folder: str): """ Returns a list of all the folders and tracks in the given folder. @@ -291,7 +291,10 @@ def send_track_file(track_id): """ Returns an audio file that matches the passed id to the client. """ + try: + filepath = instances.songs_instance.get_song_by_id(track_id)['filepath'] + return send_file(filepath, mimetype="audio/mp3") + except FileNotFoundError: + return "File not found", 404 - filepath = instances.songs_instance.get_song_by_id(track_id)['filepath'] - return send_file(filepath, mimetype="audio/mp3") diff --git a/server/app/functions.py b/server/app/functions.py index 44b5c54..89ffde1 100644 --- a/server/app/functions.py +++ b/server/app/functions.py @@ -42,7 +42,7 @@ def populate(): instances.songs_instance.insert_song(tags) api.all_the_f_music = helpers.get_all_songs() - + print("\n check done") end = time.time() diff --git a/server/app/helpers.py b/server/app/helpers.py index b7f9a22..0b8d3df 100644 --- a/server/app/helpers.py +++ b/server/app/helpers.py @@ -34,7 +34,7 @@ def background(func): @background -def check_for_new_songs(): +def reindex_tracks(): """ Checks for new songs every 5 minutes. """ @@ -48,6 +48,9 @@ def check_for_new_songs(): @background def start_watchdog(): + """ + Starts the file watcher. + """ watchdoge.watch.run()