add file watcher

- disable double flask instances
- remove unused files
- play song by id (instead of from nginx)
This commit is contained in:
geoffrey45
2022-02-16 15:02:36 +03:00
parent 1802e02179
commit 1caef9d3a2
9 changed files with 60 additions and 169 deletions
+13 -9
View File
@@ -9,24 +9,26 @@ from typing import List
import requests
from io import BytesIO
from PIL import Image
from app import instances
from app import functions
from app import watchdoge
home_dir = os.path.expanduser('~') + '/'
app_dir = os.path.join(home_dir, '.musicx')
LAST_FM_API_KEY = "762db7a44a9e6fb5585661f5f2bdf23a"
def background(f):
def background(func):
"""
a threading decorator
use @background above the function you want to run in the background
"""
def background_func(*a, **kw):
threading.Thread(target=f, args=a, kwargs=kw).start()
threading.Thread(target=func, args=a, kwargs=kw).start()
return background_func
@@ -44,6 +46,11 @@ def check_for_new_songs():
time.sleep(300)
@background
def start_watchdog():
watchdoge.watch.run()
def run_fast_scandir(_dir: str, ext: list):
"""
Scans a directory for files with a specific extension. Returns a list of files and folders in the directory.
@@ -89,7 +96,7 @@ def remove_duplicates(array: list) -> list:
def save_image(url: str, path: str) -> None:
"""
Saves an image from a url to a path.
Saves an image from an url to a path.
"""
response = requests.get(url)
@@ -138,14 +145,11 @@ def get_all_songs() -> List:
tracks = []
for track in instances.songs_instance.get_all_songs():
track = functions.create_track_class(track)
try:
os.chmod(os.path.join(home_dir, track.filepath), 0o755)
os.chmod(os.path.join(track["filepath"]), 0o755)
except FileNotFoundError:
print("")
instances.songs_instance.remove_song_by_filepath(track.filepath)
instances.songs_instance.remove_song_by_filepath(track['filepath'])
tracks.append(track)
tracks.append(functions.create_track_class(track))
return tracks