simplify code, make last clip min one second long. handle missing lists
This commit is contained in:
parent
d9c03932ec
commit
871b3c2c05
@ -65,8 +65,8 @@ def get_delta(begin):
|
|||||||
|
|
||||||
def handle_list_init(current_delta, total_delta, node):
|
def handle_list_init(current_delta, total_delta, node):
|
||||||
"""
|
"""
|
||||||
# handle init clip, but this clip can be the last one in playlist,
|
handle init clip, but this clip can be the last one in playlist,
|
||||||
# this we have to figure out and calculate the right length
|
this we have to figure out and calculate the right length
|
||||||
"""
|
"""
|
||||||
new_seek = abs(current_delta) + node['seek']
|
new_seek = abs(current_delta) + node['seek']
|
||||||
new_out = node['out']
|
new_out = node['out']
|
||||||
@ -100,6 +100,9 @@ def handle_list_end(new_length, node):
|
|||||||
new_out = node['out']
|
new_out = node['out']
|
||||||
messenger.debug('List end')
|
messenger.debug('List end')
|
||||||
|
|
||||||
|
# make last clip always minimum a second long
|
||||||
|
new_length += 1
|
||||||
|
|
||||||
if node['seek'] > 0:
|
if node['seek'] > 0:
|
||||||
new_out = node['seek'] + new_length
|
new_out = node['seek'] + new_length
|
||||||
else:
|
else:
|
||||||
@ -108,7 +111,7 @@ def handle_list_end(new_length, node):
|
|||||||
if new_out > node['duration']:
|
if new_out > node['duration']:
|
||||||
new_out = node['duration']
|
new_out = node['duration']
|
||||||
else:
|
else:
|
||||||
messenger.info(f'We are over time, new length is: {new_length:.2f}')
|
messenger.warning(f'We are over time, new length is: {new_length:.2f}')
|
||||||
|
|
||||||
missing_secs = abs(new_length - (node['duration'] - node['seek']))
|
missing_secs = abs(new_length - (node['duration'] - node['seek']))
|
||||||
|
|
||||||
@ -117,8 +120,7 @@ def handle_list_end(new_length, node):
|
|||||||
node['out'] = new_out
|
node['out'] = new_out
|
||||||
node = src_or_dummy(node)
|
node = src_or_dummy(node)
|
||||||
elif node['duration'] > new_length > 0.0:
|
elif node['duration'] > new_length > 0.0:
|
||||||
time.sleep(new_length)
|
messenger.warning(
|
||||||
messenger.info(
|
|
||||||
f'Last clip less then 1 second long, skip:\n{node["source"]}')
|
f'Last clip less then 1 second long, skip:\n{node["source"]}')
|
||||||
node = None
|
node = None
|
||||||
|
|
||||||
@ -307,6 +309,7 @@ class GetSourceFromPlaylist:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.prev_date = get_date(True)
|
||||||
self.list_start = _playlist.start
|
self.list_start = _playlist.start
|
||||||
self.first = True
|
self.first = True
|
||||||
self.last = False
|
self.last = False
|
||||||
@ -316,6 +319,7 @@ class GetSourceFromPlaylist:
|
|||||||
self.prev_node = None
|
self.prev_node = None
|
||||||
self.next_node = None
|
self.next_node = None
|
||||||
self.playlist = PlaylistReader(get_date(True), 0.0)
|
self.playlist = PlaylistReader(get_date(True), 0.0)
|
||||||
|
self.last_error = False
|
||||||
|
|
||||||
def get_playlist(self):
|
def get_playlist(self):
|
||||||
"""
|
"""
|
||||||
@ -324,6 +328,14 @@ class GetSourceFromPlaylist:
|
|||||||
"""
|
"""
|
||||||
self.playlist.read()
|
self.playlist.read()
|
||||||
|
|
||||||
|
if self.last_error and not self.playlist.error and \
|
||||||
|
self.playlist.list_date == self.prev_date:
|
||||||
|
# when last playlist where not exists but now is there and
|
||||||
|
# is still the same playlist date,
|
||||||
|
# set self.first to true to seek in clip
|
||||||
|
# only in this situation seek in is correct!!
|
||||||
|
self.first = True
|
||||||
|
|
||||||
if self.playlist.nodes.get('program'):
|
if self.playlist.nodes.get('program'):
|
||||||
self.clip_nodes = self.playlist.nodes.get('program')
|
self.clip_nodes = self.playlist.nodes.get('program')
|
||||||
self.node_count = len(self.clip_nodes)
|
self.node_count = len(self.clip_nodes)
|
||||||
@ -333,6 +345,8 @@ class GetSourceFromPlaylist:
|
|||||||
self.node_count = 0
|
self.node_count = 0
|
||||||
self.playlist.last_mod_time = 0.0
|
self.playlist.last_mod_time = 0.0
|
||||||
|
|
||||||
|
self.last_error = self.playlist.error
|
||||||
|
|
||||||
def init_time(self):
|
def init_time(self):
|
||||||
"""
|
"""
|
||||||
get current time in second and shift it when is necessary
|
get current time in second and shift it when is necessary
|
||||||
@ -353,6 +367,7 @@ class GetSourceFromPlaylist:
|
|||||||
to get the date for a new playlist
|
to get the date for a new playlist
|
||||||
"""
|
"""
|
||||||
if self.node is None:
|
if self.node is None:
|
||||||
|
# a node is necessary for calculation
|
||||||
return
|
return
|
||||||
|
|
||||||
# calculate the length when current clip is done
|
# calculate the length when current clip is done
|
||||||
@ -361,11 +376,11 @@ class GetSourceFromPlaylist:
|
|||||||
current_length = self.node['begin'] - _playlist.start + (
|
current_length = self.node['begin'] - _playlist.start + (
|
||||||
self.node['out'] - seek)
|
self.node['out'] - seek)
|
||||||
|
|
||||||
if _playlist.length and self.node and math.isclose(
|
if _playlist.length and math.isclose(
|
||||||
_playlist.length, current_length, abs_tol=_general.threshold):
|
_playlist.length, current_length, abs_tol=_general.threshold):
|
||||||
|
|
||||||
shift = self.node['out'] - seek
|
shift = self.node['out'] - seek
|
||||||
self.playlist.list_date = get_date(False, shift)
|
self.prev_date = get_date(False, shift)
|
||||||
|
self.playlist.list_date = self.prev_date
|
||||||
self.playlist.last_mod_time = 0.0
|
self.playlist.last_mod_time = 0.0
|
||||||
self.last_time = _playlist.start - 1
|
self.last_time = _playlist.start - 1
|
||||||
self.clip_nodes = []
|
self.clip_nodes = []
|
||||||
@ -390,12 +405,14 @@ class GetSourceFromPlaylist:
|
|||||||
self.node['filter'] = build_filtergraph(self.node, self.prev_node,
|
self.node['filter'] = build_filtergraph(self.node, self.prev_node,
|
||||||
self.next_node)
|
self.next_node)
|
||||||
|
|
||||||
def eof_handling(self, duration):
|
def fill_the_gap(self, duration):
|
||||||
"""
|
"""
|
||||||
handle except playlist end
|
when playlist not exists, or is not long enough,
|
||||||
|
fill the gap
|
||||||
"""
|
"""
|
||||||
self.node = {
|
self.node = {
|
||||||
'begin': get_time('full_sec'),
|
'begin': get_time('full_sec'),
|
||||||
|
'number': 0,
|
||||||
'in': 0,
|
'in': 0,
|
||||||
'seek': 0,
|
'seek': 0,
|
||||||
'out': duration,
|
'out': duration,
|
||||||
@ -406,6 +423,28 @@ class GetSourceFromPlaylist:
|
|||||||
self.generate_cmd()
|
self.generate_cmd()
|
||||||
self.check_for_next_playlist()
|
self.check_for_next_playlist()
|
||||||
|
|
||||||
|
def eof_handling(self, begin):
|
||||||
|
"""
|
||||||
|
handle except playlist end
|
||||||
|
"""
|
||||||
|
if stdin_args.loop and self.node:
|
||||||
|
# when loop paramter is set and playlist node exists,
|
||||||
|
# jump to playlist start and play again
|
||||||
|
self.list_start = self.node['begin'] + (
|
||||||
|
self.node['out'] - self.node['seek'])
|
||||||
|
self.node = None
|
||||||
|
messenger.info('Loop playlist')
|
||||||
|
|
||||||
|
elif begin == _playlist.start or not self.clip_nodes:
|
||||||
|
# playlist not exist or is corrupt/empty
|
||||||
|
messenger.error('Clip nodes are empty!')
|
||||||
|
self.first = False
|
||||||
|
self.fill_the_gap(30)
|
||||||
|
|
||||||
|
else:
|
||||||
|
messenger.error('Playlist not long enough!')
|
||||||
|
self.fill_the_gap(60)
|
||||||
|
|
||||||
def next(self):
|
def next(self):
|
||||||
"""
|
"""
|
||||||
endless loop for reading playlists
|
endless loop for reading playlists
|
||||||
@ -453,32 +492,13 @@ class GetSourceFromPlaylist:
|
|||||||
|
|
||||||
begin += self.node['out'] - self.node['seek']
|
begin += self.node['out'] - self.node['seek']
|
||||||
else:
|
else:
|
||||||
if stdin_args.loop and self.node:
|
if not _playlist.length and not stdin_args.loop:
|
||||||
# when loop paramter is set and playlist node exists,
|
|
||||||
# jump to playlist start and play again
|
|
||||||
self.list_start = self.node['begin'] + (
|
|
||||||
self.node['out'] - self.node['seek'])
|
|
||||||
self.node = None
|
|
||||||
messenger.info('Loop playlist')
|
|
||||||
|
|
||||||
elif not _playlist.length and not stdin_args.loop:
|
|
||||||
# when we reach playlist end, stop script
|
# when we reach playlist end, stop script
|
||||||
# TODO: take next playlist, without sync check
|
# TODO: take next playlist, without sync check
|
||||||
messenger.info('Playlist reached end!')
|
messenger.info('Playlist reached end!')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
elif begin == _playlist.start or not self.clip_nodes:
|
|
||||||
# playlist not exist or is corrupt/empty
|
|
||||||
messenger.error('Clip nodes are empty!')
|
|
||||||
self.first = True
|
|
||||||
self.last = False
|
|
||||||
self.eof_handling(30)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
messenger.error('Playlist not long enough!')
|
self.eof_handling(begin)
|
||||||
self.first = False
|
|
||||||
self.last = False
|
|
||||||
self.eof_handling(60)
|
|
||||||
|
|
||||||
if self.node:
|
if self.node:
|
||||||
yield self.node
|
yield self.node
|
||||||
|
Loading…
x
Reference in New Issue
Block a user