Commit dbb804db authored by fred's avatar fred

deal with program segments

parent 40d56a7a
...@@ -179,6 +179,33 @@ def period_program(date_start, date_end, prefetch_sounds=True, ...@@ -179,6 +179,33 @@ def period_program(date_start, date_end, prefetch_sounds=True,
program = [x for x in program if x is not None] program = [x for x in program if x is not None]
# add back emissions between short episodes
new_programs = []
for i, slot in enumerate(program[:]):
if not isinstance(slot, Schedule):
continue
slot_end = slot.datetime + timedelta(minutes=slot.emission.duration)
j = i+1
while j < len(program)-1:
if program[j]:
this_slot_end = program[j].datetime + timedelta(minutes=program[j].get_duration())
if slot_end > this_slot_end:
# duplicate episode with a different time
schedule = Schedule()
schedule.emission = slot.emission
schedule.weeks = slot.weeks
schedule.datetime = slot.datetime.replace(hour=this_slot_end.hour, minute=this_slot_end.minute)
schedule.duration = (program[j+1].datetime - this_slot_end).seconds / 60
new_programs.append(schedule)
j += 1
if new_programs:
program = program + new_programs
program.sort(key=lambda x: x.datetime)
if not include_nonstop: if not include_nonstop:
return program return program
......
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