Adder Playlist.path property to Playlist so we dont always have to get the path by the title.
This commit is contained in:
parent
429ec8e683
commit
8dddeac673
1 changed files with 13 additions and 16 deletions
|
@ -20,6 +20,10 @@ class Playlist:
|
||||||
self.current_track: Track | None = None
|
self.current_track: Track | None = None
|
||||||
self.view = None
|
self.view = None
|
||||||
|
|
||||||
|
self.path = os.path.expanduser(
|
||||||
|
f"{app.settings.library_path}/playlists/{self.title.replace(" ", "_")}.wbz.m3u"
|
||||||
|
)
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
self.sorting: list[Qt.SortOrder] | None = None
|
self.sorting: list[Qt.SortOrder] | None = None
|
||||||
self.tracks = []
|
self.tracks = []
|
||||||
|
@ -119,36 +123,29 @@ class Playlist:
|
||||||
for track in self.tracks:
|
for track in self.tracks:
|
||||||
wbz_data += f"{track.path}\n"
|
wbz_data += f"{track.path}\n"
|
||||||
|
|
||||||
wbz = open(
|
wbz = open(self.path, "w")
|
||||||
os.path.expanduser(
|
|
||||||
f"{self.app.settings.library_path}/playlists/{self.title.replace(" ", "_")}.wbz.m3u"
|
|
||||||
),
|
|
||||||
"w"
|
|
||||||
)
|
|
||||||
wbz.write(wbz_data)
|
wbz.write(wbz_data)
|
||||||
wbz.close()
|
wbz.close()
|
||||||
|
|
||||||
def rename(self, title: str):
|
def rename(self, title: str):
|
||||||
# remove from unique names so a new playlist can have the old name and delete old playlist.
|
# remove from unique names so a new playlist can have the old name and delete old playlist.
|
||||||
|
|
||||||
path = f"{self.app.settings.library_path}/playlists/{self.title.replace(" ", "_")}.wbz.m3u"
|
if os.path.exists(self.path):
|
||||||
path = os.path.expanduser(path)
|
os.remove(self.path)
|
||||||
|
|
||||||
if os.path.exists(path):
|
|
||||||
os.remove(os.path.expanduser(path))
|
|
||||||
|
|
||||||
old_title = self.title
|
old_title = self.title
|
||||||
self.title = self.app.utils.unique_name(title, ignore=old_title)
|
self.title = self.app.utils.unique_name(title, ignore=old_title)
|
||||||
|
|
||||||
|
self.path = os.path.expanduser(
|
||||||
|
f"{self.app.settings.library_path}/playlists/{self.title.replace(" ", "_")}.wbz.m3u"
|
||||||
|
)
|
||||||
|
|
||||||
if not old_title == self.title: # remove only when the playlist actually has a different name
|
if not old_title == self.title: # remove only when the playlist actually has a different name
|
||||||
self.app.utils.unique_names.remove(old_title)
|
self.app.utils.unique_names.remove(old_title)
|
||||||
|
|
||||||
def delete(self):
|
def delete(self):
|
||||||
path = f"{self.app.settings.library_path}/playlists/{self.title.replace(" ", "_")}.wbz.m3u"
|
if os.path.exists(self.path):
|
||||||
path = os.path.expanduser(path)
|
os.remove(self.path)
|
||||||
|
|
||||||
if os.path.exists(path):
|
|
||||||
os.remove(os.path.expanduser(path))
|
|
||||||
|
|
||||||
self.app.utils.unique_names.remove(self.title)
|
self.app.utils.unique_names.remove(self.title)
|
||||||
self.app.library.playlists.remove(self)
|
self.app.library.playlists.remove(self)
|
||||||
|
|
Loading…
Add table
Reference in a new issue