better handling when storage got lost

This commit is contained in:
jb-alvarado 2018-03-29 10:30:18 +02:00
parent d57bb7afee
commit a38f174165

View File

@ -263,15 +263,22 @@ def gen_dummy(duration):
# when source path exist, generate input with seek and out time # when source path exist, generate input with seek and out time
# when path not exist, get dummy clip # when path not exist, generate dummy clip
def src_or_dummy(src, duration, seek, out): def src_or_dummy(src, duration, seek, out, dummy_len=None):
if check_file_exist(src): if check_file_exist(src):
if seek > 0.0 or out < duration: if seek > 0.0 or out < duration:
return seek_in_cut_end(src, duration, seek, out) return seek_in_cut_end(src, duration, seek, out)
else: else:
return ['-i', src] return ['-i', src]
else: else:
return gen_dummy(out - seek) mail_or_log(
'Clip not exist:', get_time(None),
src
)
if dummy_len:
return gen_dummy(dummy_len)
else:
return gen_dummy(out - seek)
# compare clip play time with real time, # compare clip play time with real time,
@ -310,7 +317,7 @@ def gen_input(src, begin, dur, seek, out, last):
if (time_diff <= ref_time or begin < day_in_sec) and not last: if (time_diff <= ref_time or begin < day_in_sec) and not last:
# when we are in the 24 houre range, get the clip # when we are in the 24 houre range, get the clip
return src_or_dummy(src, dur, seek, out), None return src_or_dummy(src, dur, seek, out, 20), None
elif time_diff < ref_time and last: elif time_diff < ref_time and last:
# when last clip is passed and we still have too much time left # when last clip is passed and we still have too much time left
# check if duration is larger then out - seek # check if duration is larger then out - seek
@ -326,11 +333,10 @@ def gen_input(src, begin, dur, seek, out, last):
else: else:
src_cmd = src_or_dummy(src, dur, 0, new_len) src_cmd = src_or_dummy(src, dur, 0, new_len)
else: else:
# TODO: fix missing time
src_cmd = src_or_dummy(src, dur, 0, dur) src_cmd = src_or_dummy(src, dur, 0, dur)
mail_or_log( mail_or_log(
'playlist is not long enough', get_time(None), 'playlist is not long enough:', get_time(None),
str(new_len) + ' seconds needed.' str(new_len) + ' seconds needed.'
) )
@ -366,12 +372,33 @@ def is_float(value, text, convert):
return text return text
# check last item, when it is None or a dummy clip,
# set true and seek in playlist
def check_last_item(src_cmd, last_time, last):
if None in src_cmd and not last:
first = True
last_time = get_time('full_sec')
if 0 <= last_time < _playlist.start * 3600:
last_time += 86400
elif 'lavfi' in src_cmd and not last:
first = True
last_time = get_time('full_sec') + _buffer.length + _buffer.tol
if 0 <= last_time < _playlist.start * 3600:
last_time += 86400
else:
first = False
return first, last_time
# validate xml values in new Thread # validate xml values in new Thread
# and test if file path exist # and test if file path exist
def validate_thread(clip_nodes): def validate_thread(clip_nodes):
def check_xml(xml_nodes): def check_xml(xml_nodes):
error = '' error = ''
# check if all values are valid
for xml_node in xml_nodes: for xml_node in xml_nodes:
if check_file_exist(xml_node.get('src')): if check_file_exist(xml_node.get('src')):
a = '' a = ''
@ -389,8 +416,20 @@ def validate_thread(clip_nodes):
if error: if error:
mail_or_log( mail_or_log(
'Validation error, check xml playlist, values are missing:\n', 'Validation error, check xml playlist, values are missing!',
get_time(None), error get_time(None), ":\n" + error
)
# check if playlist is long enough
last_begin = is_float(clip_nodes[-1].get('begin'), 0, True)
last_duration = is_float(clip_nodes[-1].get('dur'), 0, True)
start = float(_playlist.start * 3600)
total_play_time = last_begin + last_duration - start
if total_play_time < 86395.0:
mail_or_log(
'xml playlist is not long enough!',
get_time(None), "total play time is: " + str(total_play_time)
) )
validate = Thread(name='check_xml', target=check_xml, args=(clip_nodes,)) validate = Thread(name='check_xml', target=check_xml, args=(clip_nodes,))
@ -398,16 +437,17 @@ def validate_thread(clip_nodes):
validate.start() validate.start()
def exeption(message, dummy_length, path, last): # exaption gets called, when there is no playlist,
src_cmd = gen_dummy(dummy_length) # or the playlist is not long enough
def exeption(message, dummy_len, path, last):
src_cmd = gen_dummy(dummy_len)
if last: if last:
last_time = float(_playlist.start * 3600 - 5) last_time = float(_playlist.start * 3600 - 5)
first = False first = False
else: else:
last_time = ( last_time = (
get_time('full_sec') + dummy_length + get_time('full_sec') + dummy_len + _buffer.length + _buffer.tol
_buffer.length + _buffer.tol
) )
if 0 <= last_time < _playlist.start * 3600: if 0 <= last_time < _playlist.start * 3600:
@ -426,14 +466,12 @@ def exeption(message, dummy_length, path, last):
# read values from xml playlist # read values from xml playlist
def iter_src_commands(): def iter_src_commands():
last_time = get_time('full_sec') last_time = None
if 0 <= last_time < _playlist.start * 3600:
last_time += 86400
last_mod_time = 0.0 last_mod_time = 0.0
first = True src_cmd = [None]
last = False last = False
list_date = get_date(True) list_date = get_date(True)
dummy_length = 60 dummy_len = 60
while True: while True:
year, month, day = re.split('-', list_date) year, month, day = re.split('-', list_date)
@ -443,20 +481,26 @@ def iter_src_commands():
# check last modification from playlist # check last modification from playlist
mod_time = path.getmtime(xml_path) mod_time = path.getmtime(xml_path)
if mod_time > last_mod_time: if mod_time > last_mod_time:
xml_root = ET.parse(open(xml_path, "r")).getroot() xml_file = open(xml_path, "r")
xml_root = ET.parse(xml_file).getroot()
clip_nodes = xml_root.findall('body/video') clip_nodes = xml_root.findall('body/video')
xml_file.close()
last_mod_time = mod_time last_mod_time = mod_time
logger.info('open: ' + xml_path) logger.info('open: ' + xml_path)
validate_thread(clip_nodes) validate_thread(clip_nodes)
last_node = clip_nodes[-1] last_node = clip_nodes[-1]
# when last clip is None or a dummy,
# we have to jump to the right place in the playlist
first, last_time = check_last_item(src_cmd, last_time, last)
# loop through all clips in playlist # loop through all clips in playlist
for clip_node in clip_nodes: for clip_node in clip_nodes:
src = clip_node.get('src') src = clip_node.get('src')
begin = is_float(clip_node.get('begin'), last_time, True) begin = is_float(clip_node.get('begin'), last_time, True)
duration = is_float(clip_node.get('dur'), 60, True) duration = is_float(clip_node.get('dur'), dummy_len, True)
seek = is_float(clip_node.get('in'), 0, True) seek = is_float(clip_node.get('in'), 0, True)
out = is_float(clip_node.get('out'), 60, True) out = is_float(clip_node.get('out'), dummy_len, True)
# first time we end up here # first time we end up here
if first and last_time < begin + duration: if first and last_time < begin + duration:
@ -488,7 +532,7 @@ def iter_src_commands():
# when playlist is finish and we have time left # when playlist is finish and we have time left
last_time = begin last_time = begin
list_date = get_date(False) list_date = get_date(False)
dummy_length = time_left dummy_len = time_left
else: else:
# when there is no time left and we are in time, # when there is no time left and we are in time,
@ -502,12 +546,12 @@ def iter_src_commands():
# when playlist exist but is empty, or not long enough, # when playlist exist but is empty, or not long enough,
# generate dummy and send log # generate dummy and send log
src_cmd, last_time, first = exeption( src_cmd, last_time, first = exeption(
'Playlist is not valid!', dummy_length, xml_path, last 'Playlist is not valid!', dummy_len, xml_path, last
) )
begin = last_time begin = get_time('full_sec') + _buffer.length + _buffer.tol
last = False last = False
dummy_length = 60 dummy_len = 60
last_mod_time = 0.0 last_mod_time = 0.0
else: else:
@ -515,12 +559,12 @@ def iter_src_commands():
# then we generate a black clip # then we generate a black clip
# and calculate the seek in time, for when the playlist comes back # and calculate the seek in time, for when the playlist comes back
src_cmd, last_time, first = exeption( src_cmd, last_time, first = exeption(
'Playlist not exist:', dummy_length, xml_path, last 'Playlist not exist:', dummy_len, xml_path, last
) )
begin = last_time begin = get_time('full_sec') + _buffer.length + _buffer.tol
last = False last = False
dummy_length = 60 dummy_len = 60
last_mod_time = 0.0 last_mod_time = 0.0
if src_cmd is not None: if src_cmd is not None: