put delta calculation in separate function

This commit is contained in:
Jonathan Baecker 2019-11-05 17:47:29 +01:00
parent 95f768064c
commit 980adf87d3

View File

@ -732,19 +732,15 @@ def src_or_dummy(src, dur, seek, out):
return gen_dummy(out - seek)
def gen_input(src, begin, dur, seek, out, first, last):
def get_delta(begin, seek, first):
"""
prepare input clip
check begin and length from clip
return clip only if we are in 24 hours time range
get difference between current time and begin from clip in playlist
"""
if _playlist.start:
if _playlist.length:
target_playtime = _playlist.length
else:
target_playtime = 86400.0
ref_time = target_playtime + _playlist.start
current_time = get_time('full_sec')
if _playlist.start >= current_time and not begin == _playlist.start:
@ -755,7 +751,8 @@ def gen_input(src, begin, dur, seek, out, first, last):
else:
time_delta = begin - current_time
messenger.debug('time_delta: {}'.format(time_delta))
if math.isclose(time_delta, 86400.0, abs_tol=6):
time_delta -= 86400.0
# check that we are in tolerance time
if _general.stop and abs(time_delta) > _general.threshold:
@ -765,6 +762,24 @@ def gen_input(src, begin, dur, seek, out, first, last):
terminate_processes()
sys.exit(1)
messenger.debug('time_delta: {}'.format(time_delta))
return target_playtime, time_delta
def gen_input(src, begin, dur, seek, out, first, last):
"""
prepare input clip
check begin and length from clip
return clip only if we are in 24 hours time range
"""
if _playlist.start:
# TODO: there is no rule at then moment,
# when no _playlist.start is set, but _playlist.length exists
target_playtime, time_delta = get_delta(begin, seek, first)
ref_time = target_playtime + _playlist.start
if (begin + out + time_delta < ref_time and not last) \
or not _playlist.length:
# when we are in the 24 houre range, get the clip
@ -773,7 +788,7 @@ def gen_input(src, begin, dur, seek, out, first, last):
elif begin + time_delta > ref_time:
messenger.info(
'Start time is over {}, skip clip:\n{}'.format(
timedelta(seconds=_playlist.length), src))
timedelta(seconds=target_playtime), src))
return None, 0, 0, True
elif begin + out + time_delta > ref_time or last:
@ -782,6 +797,8 @@ def gen_input(src, begin, dur, seek, out, first, last):
if seek > 0:
new_out = seek + new_length
else:
new_out = new_length
# prevent looping
if new_out > dur:
new_out = dur