mirror of
https://github.com/tcsenpai/swingmusic.git
synced 2025-06-10 21:17:33 +00:00

- disable double flask instances - remove unused files - play song by id (instead of from nginx)
65 lines
1.5 KiB
Python
65 lines
1.5 KiB
Python
import time
|
|
import os
|
|
|
|
from watchdog.observers import Observer
|
|
from watchdog.events import PatternMatchingEventHandler
|
|
|
|
class OnMyWatch:
|
|
directory = "/home/cwilvx/Music"
|
|
|
|
def __init__(self):
|
|
self.observer = Observer()
|
|
|
|
def run(self):
|
|
event_handler = Handler()
|
|
self.observer.schedule(
|
|
event_handler, self.directory, recursive=True
|
|
)
|
|
self.observer.start()
|
|
|
|
try:
|
|
while True:
|
|
time.sleep(5)
|
|
except:
|
|
self.observer.stop()
|
|
print("Observer Stopped")
|
|
|
|
self.observer.join()
|
|
|
|
|
|
def create_thumb_dir(filepath):
|
|
f_name = filepath.split('/')[-1]
|
|
parent_dir = filepath.replace(f_name, '')
|
|
|
|
thumb_dir = parent_dir + ".thumbnails"
|
|
|
|
if not os.path.exists(thumb_dir):
|
|
os.makedirs(thumb_dir)
|
|
|
|
|
|
class Handler(PatternMatchingEventHandler):
|
|
def __init__(self):
|
|
print("💠 started watchxx")
|
|
PatternMatchingEventHandler.__init__(
|
|
self, patterns=['*.flac', '*.mp3'], ignore_directories=True, case_sensitive=False)
|
|
|
|
def on_created(self, event):
|
|
print("🔵 created +++")
|
|
print(event.src_path)
|
|
create_thumb_dir(event.src_path)
|
|
|
|
def on_deleted(self, event):
|
|
print("🔴 deleted ---")
|
|
print(event.src_path)
|
|
|
|
def on_moved(self, event):
|
|
print("🔘 moved -->")
|
|
print(event.src_path)
|
|
print(event.dest_path)
|
|
|
|
|
|
# if __name__ == '__main__':
|
|
watch = OnMyWatch()
|
|
# watch.run()
|
|
|