Backfill chat archives under the "chat" quality

pull/300/head
Mike Lang 2 years ago committed by Mike Lang
parent 05ddd39504
commit f8b3ace148

@ -131,9 +131,17 @@ def get_remote_segment(base_dir, node, channel, quality, hour, missing_segment,
return return
dir_name = os.path.dirname(path) dir_name = os.path.dirname(path)
if quality == "chat":
# chat segment
_, filename_hash = os.path.basename(path).split('-', 1)
temp_name = "{}.{}.temp".format(os.path.basename(path), uuid4())
else:
# video segment
date, duration, _ = os.path.basename(path).split('-', 2) date, duration, _ = os.path.basename(path).split('-', 2)
temp_name = "-".join([date, duration, "temp", str(uuid.uuid4())]) filename_hash = common.parse_segment_path(missing_segment).hash
temp_path = os.path.join(dir_name, "{}.ts".format(temp_name)) temp_name = "{}.ts".format("-".join([date, duration, "temp", str(uuid.uuid4())]))
temp_path = os.path.join(dir_name, temp_name)
common.ensure_directory(temp_path) common.ensure_directory(temp_path)
hash = hashlib.sha256() hash = hashlib.sha256()
@ -149,7 +157,6 @@ def get_remote_segment(base_dir, node, channel, quality, hour, missing_segment,
common.writeall(f.write, chunk) common.writeall(f.write, chunk)
hash.update(chunk) hash.update(chunk)
filename_hash = common.parse_segment_path(missing_segment).hash
if filename_hash != hash.digest(): if filename_hash != hash.digest():
logger.warn('Hash of segment {} does not match. Discarding segment'.format(missing_segment)) logger.warn('Hash of segment {} does not match. Discarding segment'.format(missing_segment))
hash_mismatches.labels(remote=node, channel=channel, quality=quality, hour=hour).inc() hash_mismatches.labels(remote=node, channel=channel, quality=quality, hour=hour).inc()

@ -187,6 +187,7 @@ class Archiver(object):
def write_batch(path, batch_time, messages): def write_batch(path, batch_time, messages):
"""Batches are named PATH/YYYY-MM-DDTHH/MM:SS-HASH.json"""
output = (format_batch(messages) + '\n').encode('utf-8') output = (format_batch(messages) + '\n').encode('utf-8')
hash = base64.b64encode(hashlib.sha256(output).digest(), b"-_").decode().rstrip("=") hash = base64.b64encode(hashlib.sha256(output).digest(), b"-_").decode().rstrip("=")
hour = datetime.utcfromtimestamp(batch_time).strftime("%Y-%m-%dT%H") hour = datetime.utcfromtimestamp(batch_time).strftime("%Y-%m-%dT%H")

@ -181,6 +181,9 @@ def generate_master_playlist(channel):
playlists = {} playlists = {}
for quality in qualities: for quality in qualities:
# "chat" is text only, not an actual video quality
if quality == "chat":
continue
# If start or end are given, try to restrict offered qualities to ones which exist for that # If start or end are given, try to restrict offered qualities to ones which exist for that
# time range. # time range.
if start is not None or end is not None: if start is not None or end is not None:

Loading…
Cancel
Save