started on checking the hash

pull/97/head
Christopher Usher 5 years ago
parent 875e4271a6
commit 120a5a7de0

@ -2,6 +2,7 @@
import datetime import datetime
import errno import errno
import hashlib
import logging import logging
import os import os
import random import random
@ -9,6 +10,7 @@ import signal
import socket import socket
import urlparse import urlparse
import uuid import uuid
from base64 import b64encode
import argh import argh
import gevent.backdoor import gevent.backdoor
@ -88,6 +90,8 @@ def get_remote_segment(base_dir, node, channel, quality, hour, missing_segment,
temp_path = os.path.join(dir_name, "{}.ts".format(temp_name)) temp_path = os.path.join(dir_name, "{}.ts".format(temp_name))
common.ensure_directory(temp_path) common.ensure_directory(temp_path)
hash = hashlib.sha256()
try: try:
logging.debug('Fetching segment {} from {}'.format(path, node)) logging.debug('Fetching segment {} from {}'.format(path, node))
uri = '{}/segments/{}/{}/{}/{}'.format(node, channel, quality, hour, missing_segment) uri = '{}/segments/{}/{}/{}/{}'.format(node, channel, quality, hour, missing_segment)
@ -98,6 +102,10 @@ def get_remote_segment(base_dir, node, channel, quality, hour, missing_segment,
with open(temp_path, 'w') as f: with open(temp_path, 'w') as f:
for chunk in resp.iter_content(8192): for chunk in resp.iter_content(8192):
f.write(chunk) f.write(chunk)
hash.update(chunk)
hash_str = b64encode(hash.digest(), "-_").rstrip("=")
logger.info('{} {}'.format(missing_segment, hash_str))
#try to get rid of the temp file if an exception is raised. #try to get rid of the temp file if an exception is raised.
except Exception: except Exception:

Loading…
Cancel
Save