Commit 3fe25f31 authored by fred's avatar fred

stamina: compute shorter playlists

parent d061b4fa
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment