mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 04:53:01 +00:00
fix album having date = 0
This commit is contained in:
+4
-3
@@ -9,7 +9,8 @@ from tqdm import tqdm
|
||||
|
||||
from app import settings
|
||||
from app.db.sqlite.favorite import SQLiteFavoriteMethods as favdb
|
||||
from app.db.sqlite.lastfm.similar_artists import SQLiteLastFMSimilarArtists as lastfmdb
|
||||
from app.db.sqlite.lastfm.similar_artists import \
|
||||
SQLiteLastFMSimilarArtists as lastfmdb
|
||||
from app.db.sqlite.settings import SettingsSQLMethods as sdb
|
||||
from app.db.sqlite.tracks import SQLiteTrackMethods
|
||||
from app.lib.artistlib import CheckArtistImages
|
||||
@@ -90,7 +91,7 @@ class Populate:
|
||||
tried_to_download_new_images = True
|
||||
try:
|
||||
CheckArtistImages()
|
||||
except (RequestConnectionError, ReadTimeout):
|
||||
except (RequestConnectionError, ReadTimeout) as e:
|
||||
log.error(
|
||||
"Internet connection lost. Downloading artist images stopped."
|
||||
)
|
||||
@@ -123,7 +124,7 @@ class Populate:
|
||||
continue
|
||||
except FileNotFoundError:
|
||||
print(f"File not found: {track.filepath}")
|
||||
TrackStore.tracks.remove(track)
|
||||
TrackStore.remove_track_obj(track)
|
||||
remove_tracks_by_filepaths(track.filepath)
|
||||
|
||||
modified.add(track.filepath)
|
||||
|
||||
@@ -15,5 +15,5 @@ def validate_tracks() -> None:
|
||||
"""
|
||||
for track in tqdm(TrackStore.tracks, desc="Checking for deleted tracks"):
|
||||
if not os.path.exists(track.filepath):
|
||||
TrackStore.tracks.remove(track)
|
||||
TrackStore.remove_track_obj(track)
|
||||
tdb.remove_tracks_by_filepaths(track.filepath)
|
||||
|
||||
+26
-13
@@ -184,6 +184,7 @@ def remove_track(filepath: str) -> None:
|
||||
class Handler(PatternMatchingEventHandler):
|
||||
files_to_process = []
|
||||
files_to_process_windows = []
|
||||
file_sizes = {}
|
||||
|
||||
root_dirs = []
|
||||
dir_map = []
|
||||
@@ -215,6 +216,7 @@ class Handler(PatternMatchingEventHandler):
|
||||
"""
|
||||
self.files_to_process.append(event.src_path)
|
||||
self.files_to_process_windows.append(event.src_path)
|
||||
self.file_sizes[event.src_path] = os.path.getsize(event.src_path)
|
||||
|
||||
def on_deleted(self, event):
|
||||
"""
|
||||
@@ -269,18 +271,29 @@ class Handler(PatternMatchingEventHandler):
|
||||
if event.src_path not in self.files_to_process_windows:
|
||||
return
|
||||
|
||||
file_size = -1
|
||||
# Check if file write operation is complete
|
||||
current_size = os.path.getsize(event.src_path)
|
||||
previous_size = self.file_sizes.get(event.src_path, -1)
|
||||
|
||||
while file_size != os.path.getsize(event.src_path):
|
||||
file_size = os.path.getsize(event.src_path)
|
||||
time.sleep(0.1)
|
||||
if current_size == previous_size:
|
||||
# Wait for a short duration to ensure the file write operation is complete
|
||||
time.sleep(0.5)
|
||||
|
||||
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:
|
||||
# File is locked, skipping
|
||||
pass
|
||||
# Check the file size again
|
||||
current_size = os.path.getsize(event.src_path)
|
||||
|
||||
if current_size == previous_size:
|
||||
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)
|
||||
del self.file_sizes[event.src_path]
|
||||
except OSError:
|
||||
# File is locked, skipping
|
||||
pass
|
||||
return
|
||||
|
||||
# Update the file size for the next iteration
|
||||
self.file_sizes[event.src_path] = current_size
|
||||
|
||||
Reference in New Issue
Block a user