]> git.0d.be Git - django-panik-nonstop.git/commitdiff
stamina: add "soft stop" in nonstop zones
authorFrédéric Péters <fpeters@0d.be>
Sun, 14 Jun 2020 20:11:53 +0000 (22:11 +0200)
committerFrédéric Péters <fpeters@0d.be>
Thu, 2 Jul 2020 08:01:29 +0000 (10:01 +0200)
nonstop/management/commands/stamina.py

index 4bfecc65583434f51eb490cca76dc89a118f7ae5..344d89ef9ae6ef253ea7736db2d5fd6bd36d596c 100644 (file)
@@ -120,6 +120,7 @@ class Command(BaseCommand):
         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:
@@ -130,8 +131,9 @@ class Command(BaseCommand):
                 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)
@@ -245,7 +247,10 @@ class Command(BaseCommand):
             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()