Playlists now get loaded when they are started and removed debug prints.

This commit is contained in:
The Wobbler 2025-02-12 13:50:12 +01:00
parent 0879575882
commit 0c2c91389d
5 changed files with 12 additions and 30 deletions

View file

@ -23,9 +23,7 @@ def main():
app.post_init()
if arguments.playlist:
playlist = Playlist(app, "Temporary Playlist")
playlist.load_from_m3u(arguments.playlist)
playlist = Playlist(app, "Temporary Playlist", arguments.playlist)
app.library.playlists.append(playlist)
@ -34,15 +32,7 @@ def main():
app.library.temporary_playlist = playlist
if arguments.track:
# make track paths absolute
tracks = []
for track in arguments.track:
tracks.append(os.path.abspath(track))
playlist = Playlist(app, "Temporary Playlist")
playlist.load_from_paths(tracks)
playlist = Playlist(app, "Temporary Playlist", arguments.track)
app.library.playlists.append(playlist)

View file

@ -58,7 +58,8 @@ class Library:
def on_exit(self, event):
for playlist in self.playlists:
playlist.save()
if playlist.loaded: # only save loaded playlists, unloaded are empty
playlist.save()
if self.app.player.current_playlist is not None:
self.app.settings.latest_playlist = self.app.player.current_playlist.path

View file

@ -2,6 +2,7 @@
import os
import threading
from PyQt6.QtCore import Qt
from .track import Track
@ -44,14 +45,10 @@ class Playlist:
path = paths[i]
if os.path.isfile(path):
self.tracks.append(Track(self.app, path, cache=i==0)) # first track is cached
self.append_track(Track(self.app, path, cache=i==0)) # first track is cached
i += 1
self.save()
self.tracks = []
def load(self):
loading_thread = threading.Thread(target=self.loading_thread)
loading_thread.start()
@ -60,8 +57,11 @@ class Playlist:
if self.load_from is None: # if the playlist is in the library
self.load_from_wbz(self.path)
elif self.load_from is list:
pass
elif isinstance(self.load_from, str):
self.load_from_m3u(self.load_from)
elif isinstance(self.load_from, list):
self.load_from_paths(self.load_from)
def load_from_m3u(self, path):
file = open(path, "r")
@ -86,8 +86,6 @@ class Playlist:
i += 1
print("kolupp")
# set current track to the first track if there is no currently playing track
if self.current_track is None and self.has_tracks():
self.current_track = self.tracks[0]
@ -177,9 +175,6 @@ class Playlist:
self.tracks.append(track)
print(track.tags.title)
def h_last_track(self):
# get last track in history (only gets used in player.history)

View file

@ -14,7 +14,7 @@ class Track:
self.app = app
self.path = path
self.tags = TinyTag.get(self.path, ignore_errors=False, duration=False)
self.tags = TinyTag.get(self.path, ignore_errors=True, duration=False)
self.cached = False
self.audio = None

View file

@ -41,8 +41,6 @@ class PlaylistView(QTreeWidget):
self.setHeaderLabels(headers)
#self.load_tracks()
self.itemActivated.connect(self.on_track_activation)
def on_user_sort(self):
@ -143,8 +141,6 @@ class PlaylistView(QTreeWidget):
if track:
playlist_tabs.setTabIcon(index, self.playing_mark) # mark this playlist
print(self.app.player.current_playlist.current_track_index)
# mark the current track in this playlist
item = self.topLevelItem(self.app.player.current_playlist.current_track_index)
item.setIcon(0, self.playing_mark)