Did some memory optimisation, moved some files and created a completely not tested gui class that will list an artist's tracks.

Made tracks return an already existing object when they get created with a path of an already existing track object.
This commit is contained in:
The Wobbler 2025-03-06 16:35:13 +01:00
parent 9ae1704e4a
commit 7edaebc3c3
7 changed files with 77 additions and 4 deletions

View file

@ -46,6 +46,9 @@ class Track:
self.app = app
self.path = path
# add self to loaded tracks to make sure that no other track object is created for this track
app.library.loaded_tracks[self.path] = self
if metadata is None:
# load metadata from audio file
tags = TinyTag.get(path, ignore_errors=True, duration=False)
@ -66,6 +69,18 @@ class Track:
if cache:
self.cache()
def __new__(cls, app, path: str, cache: bool=False, metadata: TrackMetadata=None):
loaded_track = app.library.loaded_track(path)
if loaded_track is not None:
if cache:
loaded_track.cache()
return loaded_track
else:
return super().__new__(cls)
def set_occurrences(self):
# set track item for every occurrence of track in a playlist