downloader: Include channel name in path, instead of assuming it's already in base_dir

Previously, downloader would put files under BASE_DIR/VARIANT/HOUR/FILE.ts
now, it will put files under BASE_DIR/STREAM/VARIANT/HOUR/FILE.ts

This brings downloader in line with restreamer's concept of base_dir
pull/15/head
Mike Lang 6 years ago committed by Mike Lang
parent 84097f4bbb
commit 7257fb9b73

@ -318,7 +318,7 @@ class StreamWorker(object):
if segment.uri not in self.getters: if segment.uri not in self.getters:
if date is None: if date is None:
raise ValueError("Cannot determine date of segment") raise ValueError("Cannot determine date of segment")
self.getters[segment.uri] = SegmentGetter(self.manager.base_dir, self.stream, segment, date) self.getters[segment.uri] = SegmentGetter(self.manager.base_dir, self.manager.channel, self.stream, segment, date)
gevent.spawn(self.getters[segment.uri].run) gevent.spawn(self.getters[segment.uri].run)
if date is not None: if date is not None:
date += datetime.timedelta(seconds=segment.duration) date += datetime.timedelta(seconds=segment.duration)
@ -362,8 +362,9 @@ class SegmentGetter(object):
FETCH_HEADERS_TIMEOUTS = 5, 30 FETCH_HEADERS_TIMEOUTS = 5, 30
FETCH_FULL_TIMEOUTS = 15, 240 FETCH_FULL_TIMEOUTS = 15, 240
def __init__(self, base_dir, stream, segment, date): def __init__(self, base_dir, channel, stream, segment, date):
self.base_dir = base_dir self.base_dir = base_dir
self.channel = channel
self.stream = stream self.stream = stream
self.segment = segment self.segment = segment
self.date = date self.date = date
@ -400,6 +401,7 @@ class SegmentGetter(object):
"""Generate leading part of filepath which doesn't change with the hash.""" """Generate leading part of filepath which doesn't change with the hash."""
return os.path.join( return os.path.join(
self.base_dir, self.base_dir,
self.channel,
self.stream, self.stream,
self.date.strftime("%Y-%m-%dT%H"), self.date.strftime("%Y-%m-%dT%H"),
"{date}-{duration}".format( "{date}-{duration}".format(

Loading…
Cancel
Save