From: Frédéric Péters Date: Fri, 19 Jun 2020 17:02:16 +0000 (+0200) Subject: stamina: compute shorter playlists X-Git-Url: https://git.0d.be/?p=django-panik-nonstop.git;a=commitdiff_plain;h=3fe25f3151a1c4a337adf3b80e43003be44132ec stamina: compute shorter playlists --- diff --git a/nonstop/management/commands/stamina.py b/nonstop/management/commands/stamina.py index 246ba52..09b5e1b 100644 --- a/nonstop/management/commands/stamina.py +++ b/nonstop/management/commands/stamina.py @@ -24,6 +24,13 @@ class Command(BaseCommand): current_datetime = start_datetime if self.last_jingle_datetime is None: self.last_jingle_datetime = current_datetime + # Define a max duration (1 hour), if it is reached, and far enough + # from end_datetime (30 minutes), return the playlist as is, not aligned + # on end time, so a new playlist gets computed once it's over. + # This avoids misalignments due to track durations not matching exactly + # or additional delays caused by the player program. + max_duration = datetime.timedelta(hours=1) + max_duration_leftover = datetime.timedelta(minutes=30) playlist = [] adjustment_counter = 0 try: @@ -32,6 +39,9 @@ class Command(BaseCommand): jingles = [] while current_datetime < end_datetime and adjustment_counter < 5: + if (current_datetime - start_datetime) > max_duration and ( + (end_datetime - current_datetime) > max_duration_leftover): + break if jingles and current_datetime - self.last_jingle_datetime > datetime.timedelta(minutes=20): # jingle time, every ~20 minutes