handle filenotfound in created_date

+ move store loaders up in populate.py
This commit is contained in:
mungai-njoroge 2023-12-13 23:15:25 +03:00
parent c451c0e329
commit 300c614a2f
7 changed files with 23 additions and 8 deletions

View File

@ -145,7 +145,11 @@ def get_recently_added_playlist(cutoff: int = 14):
) )
tracks = get_recent_tracks(cutoff) tracks = get_recent_tracks(cutoff)
date = datetime.fromtimestamp(tracks[0].created_date) try:
date = datetime.fromtimestamp(tracks[0].created_date)
except IndexError:
return playlist, []
playlist.last_updated = date_string_to_time_passed(create_new_date(date)) playlist.last_updated = date_string_to_time_passed(create_new_date(date))
images = get_first_4_images(tracks=tracks) images = get_first_4_images(tracks=tracks)

View File

@ -92,6 +92,10 @@ class Populate:
tried_to_download_new_images = False tried_to_download_new_images = False
ArtistStore.load_artists(instance_key)
AlbumStore.load_albums(instance_key)
TrackStore.load_all_tracks(instance_key)
if has_connection(): if has_connection():
tried_to_download_new_images = True tried_to_download_new_images = True
try: try:
@ -114,8 +118,6 @@ class Populate:
log.warn(e) log.warn(e)
return return
ArtistStore.load_artists(instance_key)
@staticmethod @staticmethod
def remove_modified(tracks: Generator[Track, None, None]): def remove_modified(tracks: Generator[Track, None, None]):
""" """

View File

@ -50,7 +50,10 @@ class Track:
created_date: float = 0.0 created_date: float = 0.0
def set_created_date(self): def set_created_date(self):
self.created_date = Path(self.filepath).stat().st_ctime try:
self.created_date = Path(self.filepath).stat().st_ctime
except FileNotFoundError:
pass
def __post_init__(self): def __post_init__(self):
self.og_title = self.title self.og_title = self.title

View File

@ -76,7 +76,7 @@ class LyricsProvider(LRCProvider):
try: try:
response = self.session.get(url, params=query, timeout=10) response = self.session.get(url, params=query, timeout=10)
except requests.exceptions.ConnectionError: except:
return None return None
if response is not None and response.ok: if response is not None and response.ok:

View File

@ -37,6 +37,7 @@ class AlbumStore:
cls.albums = [] cls.albums = []
print("Loading albums... ", end="")
tracks = remove_duplicates(TrackStore.tracks) tracks = remove_duplicates(TrackStore.tracks)
tracks = sorted(tracks, key=lambda t: t.albumhash) tracks = sorted(tracks, key=lambda t: t.albumhash)
grouped = groupby(tracks, lambda t: t.albumhash) grouped = groupby(tracks, lambda t: t.albumhash)
@ -72,6 +73,8 @@ class AlbumStore:
_al.set_colors(colors) _al.set_colors(colors)
break break
print("Done!")
@classmethod @classmethod
def add_album(cls, album: Album): def add_album(cls, album: Album):
""" """

View File

@ -23,7 +23,7 @@ class ArtistStore:
global ARTIST_LOAD_KEY global ARTIST_LOAD_KEY
ARTIST_LOAD_KEY = instance_key ARTIST_LOAD_KEY = instance_key
print("Loading artists... ", end=" ") print("Loading artists... ", end="")
cls.artists = get_all_artists(TrackStore.tracks, AlbumStore.albums) cls.artists = get_all_artists(TrackStore.tracks, AlbumStore.albums)
print("Done!") print("Done!")
for artist in ardb.get_all_artists(): for artist in ardb.get_all_artists():

View File

@ -18,6 +18,8 @@ class TrackStore:
""" """
Loads all tracks from the database into the store. Loads all tracks from the database into the store.
""" """
print("Loading tracks... ", end="")
global TRACKS_LOAD_KEY global TRACKS_LOAD_KEY
TRACKS_LOAD_KEY = instance_key TRACKS_LOAD_KEY = instance_key
@ -26,14 +28,15 @@ class TrackStore:
fav_hashes = favdb.get_fav_tracks() fav_hashes = favdb.get_fav_tracks()
fav_hashes = " ".join([t[1] for t in fav_hashes]) fav_hashes = " ".join([t[1] for t in fav_hashes])
print("\n") # adds space between progress bars and startup info for track in cls.tracks:
for track in tqdm(cls.tracks, desc="Loading tracks"):
if instance_key != TRACKS_LOAD_KEY: if instance_key != TRACKS_LOAD_KEY:
return return
if track.trackhash in fav_hashes: if track.trackhash in fav_hashes:
track.is_favorite = True track.is_favorite = True
print("Done!")
@classmethod @classmethod
def add_track(cls, track: Track): def add_track(cls, track: Track):
""" """