mirror of
https://github.com/tcsenpai/swingmusic.git
synced 2025-06-06 19:25:34 +00:00
handle watchdog's file created event using the on_modified
handler + move processing thumbnails and album colors to the populate class + move processing artist colors behind the populate call in run_periodic_checks
This commit is contained in:
parent
5b71b95d66
commit
6818f9b0e8
@ -28,10 +28,6 @@ def run_periodic_checks():
|
||||
except PopulateCancelledError:
|
||||
pass
|
||||
|
||||
ProcessTrackThumbnails()
|
||||
ProcessAlbumColors()
|
||||
ProcessArtistColors()
|
||||
|
||||
if utils.Ping()():
|
||||
try:
|
||||
CheckArtistImages()
|
||||
@ -40,4 +36,6 @@ def run_periodic_checks():
|
||||
"Internet connection lost. Downloading artist images stopped."
|
||||
)
|
||||
|
||||
ProcessArtistColors()
|
||||
|
||||
time.sleep(300)
|
||||
|
@ -7,6 +7,7 @@ from app.db.sqlite.tracks import SQLiteTrackMethods
|
||||
from app.db.sqlite.settings import SettingsSQLMethods as sdb
|
||||
from app.db.sqlite.favorite import SQLiteFavoriteMethods as favdb
|
||||
from app.db.store import Store
|
||||
from app.lib.colorlib import ProcessAlbumColors
|
||||
|
||||
from app.lib.taglib import extract_thumb, get_tags
|
||||
from app.logger import log
|
||||
@ -65,6 +66,9 @@ class Populate:
|
||||
|
||||
self.tag_untagged(untagged, key)
|
||||
|
||||
ProcessTrackThumbnails()
|
||||
ProcessAlbumColors()
|
||||
|
||||
@staticmethod
|
||||
def filter_untagged(tracks: list[Track], files: list[str]):
|
||||
tagged_files = [t.filepath for t in tracks]
|
||||
|
@ -40,6 +40,8 @@ class Watcher:
|
||||
while trials < 10:
|
||||
try:
|
||||
dirs = sdb.get_root_dirs()
|
||||
dirs = [rf"{d}" for d in dirs]
|
||||
|
||||
dir_map = [
|
||||
{"original": d, "realpath": os.path.realpath(d)} for d in dirs
|
||||
]
|
||||
@ -59,7 +61,7 @@ class Watcher:
|
||||
)
|
||||
return
|
||||
|
||||
dir_map = [d for d in dir_map if d['realpath'] != d['original']]
|
||||
dir_map = [d for d in dir_map if d["realpath"] != d["original"]]
|
||||
|
||||
if len(dirs) > 0 and dirs[0] == "$home":
|
||||
dirs = [settings.USER_HOME_DIR]
|
||||
@ -179,6 +181,8 @@ def remove_track(filepath: str) -> None:
|
||||
|
||||
class Handler(PatternMatchingEventHandler):
|
||||
files_to_process = []
|
||||
files_to_process_windows = []
|
||||
|
||||
root_dirs = []
|
||||
dir_map = []
|
||||
|
||||
@ -208,6 +212,7 @@ class Handler(PatternMatchingEventHandler):
|
||||
Fired when a supported file is created.
|
||||
"""
|
||||
self.files_to_process.append(event.src_path)
|
||||
self.files_to_process_windows.append(event.src_path)
|
||||
|
||||
def on_deleted(self, event):
|
||||
"""
|
||||
@ -240,6 +245,7 @@ class Handler(PatternMatchingEventHandler):
|
||||
def on_closed(self, event):
|
||||
"""
|
||||
Fired when a created file is closed.
|
||||
NOT FIRED IN WINDOWS
|
||||
"""
|
||||
try:
|
||||
self.files_to_process.remove(event.src_path)
|
||||
@ -248,3 +254,27 @@ class Handler(PatternMatchingEventHandler):
|
||||
add_track(path)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
def on_modified(self, event):
|
||||
# this event handler is triggered twice on windows
|
||||
# for copy events. We need to test how this behaves in
|
||||
# Linux.
|
||||
|
||||
if event.src_path not in self.files_to_process_windows:
|
||||
return
|
||||
|
||||
file_size = -1
|
||||
|
||||
while file_size != os.path.getsize(event.src_path):
|
||||
file_size = os.path.getsize(event.src_path)
|
||||
time.sleep(0.1)
|
||||
|
||||
try:
|
||||
os.rename(event.src_path, event.src_path)
|
||||
path = self.get_abs_path(event.src_path)
|
||||
remove_track(path)
|
||||
add_track(path)
|
||||
self.files_to_process_windows.remove(event.src_path)
|
||||
except OSError:
|
||||
print("File is locked, skipping")
|
||||
pass
|
||||
|
Loading…
x
Reference in New Issue
Block a user