55 lines
1.1 KiB
Python
55 lines
1.1 KiB
Python
import os
|
|
from player import play_song
|
|
import random
|
|
import sys
|
|
|
|
if len(sys.argv) < 2:
|
|
print("❌ No playlist path provided!")
|
|
sys.exit(1)
|
|
|
|
playlist_path = sys.argv[1]
|
|
|
|
if not os.path.exists(playlist_path):
|
|
print(f"❌ Playlist not found: {playlist_path}")
|
|
sys.exit(1)
|
|
|
|
|
|
playlist = []
|
|
|
|
#finds and cleans up text
|
|
with open(playlist_path, "r") as f:
|
|
for line in f:
|
|
path = line.strip()
|
|
if not path or path.startswith('#'):
|
|
continue
|
|
playlist.append(path)
|
|
|
|
random.shuffle(playlist)
|
|
|
|
shuffle_enabled = True
|
|
loop_enabled = True
|
|
exit_requested = False
|
|
last_song = None
|
|
|
|
while True:
|
|
if shuffle_enabled:
|
|
random.shuffle(playlist)
|
|
|
|
if last_song and playlist[0] == last_song:
|
|
random.shuffle(playlist)
|
|
|
|
|
|
for song in playlist:
|
|
result = play_song(song)
|
|
print("Song ended with status:", result)
|
|
|
|
if result == "skip":
|
|
continue
|
|
|
|
elif result == "quit":
|
|
print ("Stopping playlist early")
|
|
exit_requested = True
|
|
break
|
|
|
|
if not loop_enabled or exit_requested:
|
|
break |