Initial commit of BGMusic
This commit is contained in:
+55
@@ -0,0 +1,55 @@
|
||||
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
|
||||
Reference in New Issue
Block a user