forked from Wobbl/Wobuzz
Implemented saving of playlists to disk.
This commit is contained in:
parent
a7fc19f98b
commit
1007ac045f
7 changed files with 62 additions and 12 deletions
|
@ -1,8 +1,7 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from PyQt6.QtCore import Qt
|
||||
from PyQt6.QtGui import QIcon
|
||||
from PyQt6.QtWidgets import QTabWidget, QTreeWidgetItem
|
||||
import os
|
||||
from PyQt6.QtWidgets import QTabWidget
|
||||
from ..player.playlist import Playlist
|
||||
from ..ui.library_dock import LibraryDock
|
||||
from ..ui.playlist import PlaylistView
|
||||
|
@ -22,6 +21,32 @@ class Library:
|
|||
self.temporary_playlist = Playlist(self.app, "Temporary Playlist")
|
||||
self.playlists = [self.temporary_playlist]
|
||||
|
||||
def load(self):
|
||||
path_playlists = f"{self.app.settings.library_path}/playlists"
|
||||
if not os.path.exists(path_playlists):
|
||||
os.makedirs(path_playlists)
|
||||
|
||||
self.load_playlist_views()
|
||||
|
||||
return
|
||||
|
||||
folder_content = os.listdir(path_playlists)
|
||||
|
||||
for file_name in folder_content:
|
||||
if file_name.endswith(".m3u"):
|
||||
path = f"{path_playlists}/{file_name}"
|
||||
|
||||
if file_name == "Temporary_Playlist.wbz.m3u":
|
||||
playlist = self.temporary_playlist
|
||||
|
||||
else:
|
||||
playlist = Playlist(self.app, file_name.replace("_", " ").split(".")[0])
|
||||
self.playlists.append(playlist)
|
||||
|
||||
playlist.load_from_m3u(path)
|
||||
|
||||
self.load_playlist_views()
|
||||
|
||||
def load_playlist_views(self):
|
||||
for library_dock in self.library_docks:
|
||||
playlist_tabs: QTabWidget = library_dock.library.playlist_tabs
|
||||
|
@ -32,3 +57,7 @@ class Library:
|
|||
playlist_view = PlaylistView(playlist)
|
||||
playlist_tabs.addTab(playlist_view, playlist.title)
|
||||
|
||||
def on_exit(self, event):
|
||||
for playlist in self.playlists:
|
||||
playlist.save()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue