mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 04:53:01 +00:00
add file watcher
- disable double flask instances - remove unused files - play song by id (instead of from nginx)
This commit is contained in:
+12
-6
@@ -4,9 +4,8 @@ import os
|
||||
from watchdog.observers import Observer
|
||||
from watchdog.events import PatternMatchingEventHandler
|
||||
|
||||
|
||||
class OnMyWatch:
|
||||
watchDirectory = "/home/cwilvx/Music"
|
||||
directory = "/home/cwilvx/Music"
|
||||
|
||||
def __init__(self):
|
||||
self.observer = Observer()
|
||||
@@ -14,8 +13,10 @@ class OnMyWatch:
|
||||
def run(self):
|
||||
event_handler = Handler()
|
||||
self.observer.schedule(
|
||||
event_handler, self.watchDirectory, recursive=True)
|
||||
event_handler, self.directory, recursive=True
|
||||
)
|
||||
self.observer.start()
|
||||
|
||||
try:
|
||||
while True:
|
||||
time.sleep(5)
|
||||
@@ -38,21 +39,26 @@ def create_thumb_dir(filepath):
|
||||
|
||||
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()
|
||||
# if __name__ == '__main__':
|
||||
watch = OnMyWatch()
|
||||
# watch.run()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user