simpler time conversion

This commit is contained in:
Jonathan Baecker 2019-10-31 17:35:29 +01:00
parent ece2411624
commit 390396200d
2 changed files with 9 additions and 27 deletions

View File

@ -92,7 +92,7 @@ live_protocols = ["http", "https", "ftp", "rtmp", "rtmpe", "rtmps", "rtp", "rtsp
[PLAYLIST] [PLAYLIST]
playlist_mode = True playlist_mode = True
path = /playlists path = /playlists
day_start = 05:59:25.000 day_start = 05:59:25
length = 24:00:00 length = 24:00:00

View File

@ -104,17 +104,12 @@ def load_config():
""" """
cfg = configparser.ConfigParser() cfg = configparser.ConfigParser()
def validate_time(t):
timeformat = "%H:%M:%S"
try:
datetime.strptime(t, timeformat)
return True
except ValueError:
print('wrong time format!')
sys.exit(1)
def str_to_sec(s): def str_to_sec(s):
return float(s[0]) * 3600 + float(s[1]) * 60 + float(s[2]) s = s.split(':')
try:
return float(s[0]) * 3600 + float(s[1]) * 60 + float(s[2])
except ValueError:
return None
if stdin_args.config: if stdin_args.config:
cfg.read(stdin_args.config) cfg.read(stdin_args.config)
@ -124,24 +119,11 @@ def load_config():
cfg.read('ffplayout.conf') cfg.read('ffplayout.conf')
if stdin_args.start: if stdin_args.start:
if stdin_args.start == 'now': p_start = str_to_sec(stdin_args.start)
p_start = None
elif validate_time(stdin_args.start):
p_start = str_to_sec(stdin_args.start.split(':'))
else: else:
stime = cfg.get('PLAYLIST', 'day_start') p_start = str_to_sec(cfg.get('PLAYLIST', 'day_start'))
if validate_time(stime): p_length = str_to_sec(cfg.get('PLAYLIST', 'length'))
p_start = str_to_sec(stime.split(':'))
else:
p_start = None
ltime = cfg.get('PLAYLIST', 'length').split(':')
if ltime[0] and ltime[1] and ltime[2]:
p_length = str_to_sec(ltime)
else:
p_length = None
_general.stop = cfg.getboolean('GENERAL', 'stop_on_error') _general.stop = cfg.getboolean('GENERAL', 'stop_on_error')
_general.threshold = cfg.getfloat('GENERAL', 'stop_threshold') _general.threshold = cfg.getfloat('GENERAL', 'stop_threshold')