mirror of
https://github.com/radio95-rnt/RadioPlayer.git
synced 2026-07-31 08:19:16 +02:00
man
This commit is contained in:
+48
-47
@@ -365,45 +365,15 @@ def play_playlist(playlist_path, custom_playlist: bool=False, play_newest_first=
|
||||
if do_shuffle:
|
||||
random.shuffle(tracks)
|
||||
|
||||
return_pending = False
|
||||
|
||||
for i, track in enumerate(tracks[start_index:], start_index):
|
||||
if return_pending:
|
||||
stop_all_processes()
|
||||
clear_current_state()
|
||||
return
|
||||
track_path = os.path.abspath(os.path.expanduser(track))
|
||||
track_name = os.path.basename(track_path)
|
||||
if current_process:
|
||||
time.sleep(cross_for_cross_time)
|
||||
|
||||
# Check if we need to stop due to control files
|
||||
action = check_control_files()
|
||||
if action == "quit":
|
||||
stop_all_processes()
|
||||
clear_state()
|
||||
exit()
|
||||
elif action == "reload":
|
||||
logger.info("Reload requested during playback...")
|
||||
stop_all_processes()
|
||||
return "reload"
|
||||
|
||||
logger.info(f"Starting cross-to-cross to: {os.path.basename(track_name)}")
|
||||
with process_lock:
|
||||
next_process = create_audio_process(track_path, fade_in=True, fade_out=True)
|
||||
update_rds(track_name)
|
||||
|
||||
# Wait for crossfade to complete
|
||||
time.sleep(CROSSFADE_DURATION * 1.5)
|
||||
|
||||
with process_lock:
|
||||
if current_process and current_process.poll() is None:
|
||||
try:
|
||||
current_process.terminate()
|
||||
current_process.wait(5)
|
||||
except (subprocess.TimeoutExpired, ProcessLookupError):
|
||||
pass
|
||||
current_process = next_process
|
||||
next_process = None
|
||||
else:
|
||||
# No crossfade, just wait for current track to finish
|
||||
current_process.wait()
|
||||
with process_lock:
|
||||
current_process = None
|
||||
|
||||
current_modified_time = get_playlist_modification_time(playlist_path)
|
||||
if current_modified_time > last_modified_time:
|
||||
@@ -422,27 +392,57 @@ def play_playlist(playlist_path, custom_playlist: bool=False, play_newest_first=
|
||||
if DAY_START <= current_hour < DAY_END and not custom_playlist:
|
||||
if playlist_path != day_playlist_path:
|
||||
logger.info("Time changed to day hours, switching playlist...")
|
||||
stop_all_processes()
|
||||
clear_current_state()
|
||||
return
|
||||
return_pending = True
|
||||
elif MORNING_START <= current_hour < MORNING_END and not custom_playlist:
|
||||
if playlist_path != morning_playlist_path:
|
||||
logger.info("Time changed to morning hours, switching playlist...")
|
||||
stop_all_processes()
|
||||
clear_current_state()
|
||||
return
|
||||
return_pending = True
|
||||
elif LATE_NIGHT_START <= current_hour < LATE_NIGHT_END and not custom_playlist:
|
||||
if playlist_path != late_night_playlist_path:
|
||||
logger.info("Time changed to late night hours, switching playlist...")
|
||||
stop_all_processes()
|
||||
clear_current_state()
|
||||
return
|
||||
return_pending = True
|
||||
else:
|
||||
if playlist_path != night_playlist_path and not custom_playlist:
|
||||
logger.info("Time changed to night hours, switching playlist...")
|
||||
return_pending = True
|
||||
|
||||
if current_process:
|
||||
time.sleep(cross_for_cross_time)
|
||||
|
||||
# Check if we need to stop due to control files
|
||||
action = check_control_files()
|
||||
if action == "quit":
|
||||
stop_all_processes()
|
||||
clear_current_state()
|
||||
return
|
||||
clear_state()
|
||||
exit()
|
||||
elif action == "reload":
|
||||
logger.info("Reload requested during playback...")
|
||||
stop_all_processes()
|
||||
return "reload"
|
||||
|
||||
logger.info(f"Starting cross-to-cross to: {os.path.basename(track_name)}")
|
||||
with process_lock:
|
||||
next_process = create_audio_process(track_path, fade_in=True, fade_out=True)
|
||||
update_rds(track_name)
|
||||
update_current_state(track_path, playlist_path, i)
|
||||
|
||||
# Wait for crossfade to complete
|
||||
time.sleep(CROSSFADE_DURATION * 1.5)
|
||||
|
||||
with process_lock:
|
||||
if current_process and current_process.poll() is None:
|
||||
try:
|
||||
current_process.terminate()
|
||||
current_process.wait(5)
|
||||
except (subprocess.TimeoutExpired, ProcessLookupError):
|
||||
pass
|
||||
current_process = next_process
|
||||
next_process = None
|
||||
else:
|
||||
# No crossfade, just wait for current track to finish
|
||||
current_process.wait()
|
||||
with process_lock:
|
||||
current_process = None
|
||||
|
||||
# Update state before playing
|
||||
update_current_state(track_path, playlist_path, i)
|
||||
@@ -534,6 +534,7 @@ def play_playlist(playlist_path, custom_playlist: bool=False, play_newest_first=
|
||||
logger.info("Reload requested, restarting with new arguments...")
|
||||
stop_all_processes()
|
||||
return "reload"
|
||||
clear_state()
|
||||
|
||||
def can_delete_file(filepath):
|
||||
if not os.path.isfile(filepath):
|
||||
|
||||
Reference in New Issue
Block a user