if isinstance(slot, Nonstop):
self.playlist = self.get_playlist(slot, now, slot.end_datetime)
self.playhead = 0
+ self.softstop = False
while True:
now = datetime.datetime.now()
try:
print(now, track.title, track.duration,
'- future tracks:', [x.title for x in self.playlist[self.playhead + 1:self.playhead + 3]])
await self.player_process(track)
- # TODO: detect "soft spot", to switch to another nonstop
- # tranche
+ if self.softstop:
+ # track was left to finish, but now the playlist should stop.
+ break
self.playhead += 1
elif slot.is_stream():
print(now, 'playing stream', slot.stream)
expected_slot = self.slot
if current_slot != expected_slot:
print(now, 'unexpected change', current_slot, 'vs', expected_slot)
- if isinstance(current_slot, Nonstop) and not isinstance(expected_slot, Nonstop):
+ if isinstance(current_slot, Nonstop) and isinstance(expected_slot, Nonstop):
+ # ask for a softstop, i.e. finish the track then switch.
+ self.softstop = True
+ else:
# interrupt nonstop
print('interrupting nonstop')
self.play_task.cancel()