mirror of
https://github.com/tcsenpai/swingmusic.git
synced 2025-06-06 19:25:34 +00:00
fix album having date = 0
This commit is contained in:
parent
65d21d07da
commit
4a7416853a
@ -9,8 +9,7 @@ from flask import Blueprint, request
|
||||
|
||||
from app.db.sqlite.albums import SQLiteAlbumMethods as adb
|
||||
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.models import FavType, Track
|
||||
from app.serializers.album import serialize_for_card
|
||||
from app.serializers.track import track_serializer
|
||||
@ -38,7 +37,7 @@ def get_album_tracks_and_info():
|
||||
return error_msg, 400
|
||||
|
||||
try:
|
||||
albumhash = data["hash"]
|
||||
albumhash: str = data["albumhash"]
|
||||
except KeyError:
|
||||
return error_msg, 400
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -191,5 +191,6 @@ class Album:
|
||||
|
||||
if len(dates) == 0:
|
||||
self.date = 0
|
||||
return
|
||||
|
||||
self.date = datetime.datetime.fromtimestamp(min(dates)).year
|
||||
|
@ -2,8 +2,13 @@ from dataclasses import dataclass
|
||||
|
||||
from app.settings import get_flag, ParserFlags
|
||||
from app.utils.hashing import create_hash
|
||||
from app.utils.parsers import split_artists, remove_prod, parse_feat_from_title, clean_title, \
|
||||
get_base_title_and_versions
|
||||
from app.utils.parsers import (
|
||||
split_artists,
|
||||
remove_prod,
|
||||
parse_feat_from_title,
|
||||
clean_title,
|
||||
get_base_title_and_versions,
|
||||
)
|
||||
from .artist import ArtistMinimal
|
||||
|
||||
|
||||
@ -64,7 +69,9 @@ class Track:
|
||||
self.title = new_title
|
||||
|
||||
if get_flag(ParserFlags.CLEAN_ALBUM_TITLE):
|
||||
self.album, _ = get_base_title_and_versions(self.album, get_versions=False)
|
||||
self.album, _ = get_base_title_and_versions(
|
||||
self.album, get_versions=False
|
||||
)
|
||||
|
||||
if get_flag(ParserFlags.MERGE_ALBUM_VERSIONS):
|
||||
self.recreate_albumhash()
|
||||
@ -93,7 +100,9 @@ class Track:
|
||||
if self.og_title == self.title and self.og_album == self.album:
|
||||
return
|
||||
|
||||
self.trackhash = create_hash(", ".join([a.name for a in self.artist]), self.og_album, self.title)
|
||||
self.trackhash = create_hash(
|
||||
", ".join([a.name for a in self.artist]), self.og_album, self.title
|
||||
)
|
||||
|
||||
def recreate_artists_hash(self):
|
||||
"""
|
||||
|
@ -78,9 +78,9 @@ class Paths:
|
||||
|
||||
# defaults
|
||||
class Defaults:
|
||||
THUMB_SIZE = 400
|
||||
SM_THUMB_SIZE = 144
|
||||
SM_ARTIST_IMG_SIZE = 144
|
||||
THUMB_SIZE = 500
|
||||
SM_THUMB_SIZE = 64
|
||||
SM_ARTIST_IMG_SIZE = 64
|
||||
"""
|
||||
The size of extracted images in pixels
|
||||
"""
|
||||
|
@ -1,8 +1,8 @@
|
||||
from tqdm import tqdm
|
||||
|
||||
from app.models import Track
|
||||
from app.db.sqlite.favorite import SQLiteFavoriteMethods as favdb
|
||||
from app.db.sqlite.tracks import SQLiteTrackMethods as tdb
|
||||
from app.models import Track
|
||||
from app.utils.bisection import UseBisection
|
||||
from app.utils.remove_duplicates import remove_duplicates
|
||||
|
||||
@ -41,6 +41,16 @@ class TrackStore:
|
||||
|
||||
cls.tracks.extend(tracks)
|
||||
|
||||
@classmethod
|
||||
def remove_track_obj(cls, track: Track):
|
||||
"""
|
||||
Removes a single track from the store.
|
||||
"""
|
||||
try:
|
||||
cls.tracks.remove(track)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def remove_track_by_filepath(cls, filepath: str):
|
||||
"""
|
||||
@ -49,7 +59,7 @@ class TrackStore:
|
||||
|
||||
for track in cls.tracks:
|
||||
if track.filepath == filepath:
|
||||
cls.tracks.remove(track)
|
||||
cls.remove_track_obj(track)
|
||||
break
|
||||
|
||||
@classmethod
|
||||
@ -58,10 +68,9 @@ class TrackStore:
|
||||
Removes multiple tracks from the store by their filepaths.
|
||||
"""
|
||||
|
||||
|
||||
for track in cls.tracks:
|
||||
if track.filepath in filepaths:
|
||||
cls.tracks.remove(track)
|
||||
cls.remove_track_obj(track)
|
||||
|
||||
@classmethod
|
||||
def remove_tracks_by_dir_except(cls, dirs: list[str]):
|
||||
|
Loading…
x
Reference in New Issue
Block a user