|
|
@ -17,11 +17,12 @@ import prometheus_client as prom
|
|
|
|
import requests
|
|
|
|
import requests
|
|
|
|
from monotonic import monotonic
|
|
|
|
from monotonic import monotonic
|
|
|
|
|
|
|
|
|
|
|
|
import twitch
|
|
|
|
|
|
|
|
import common
|
|
|
|
import common
|
|
|
|
import common.dateutil
|
|
|
|
import common.dateutil
|
|
|
|
import common.requests
|
|
|
|
import common.requests
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from . import twitch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
segments_downloaded = prom.Counter(
|
|
|
|
segments_downloaded = prom.Counter(
|
|
|
|
"segments_downloaded",
|
|
|
|
"segments_downloaded",
|
|
|
@ -328,7 +329,7 @@ class StreamWorker(object):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
self.logger.info("Worker stopped")
|
|
|
|
self.logger.info("Worker stopped")
|
|
|
|
finally:
|
|
|
|
finally:
|
|
|
|
for getter in self.getters.values():
|
|
|
|
for getter in list(self.getters.values()):
|
|
|
|
getter.done.wait()
|
|
|
|
getter.done.wait()
|
|
|
|
self.done.set()
|
|
|
|
self.done.set()
|
|
|
|
self.manager.stream_workers[self.quality].remove(self)
|
|
|
|
self.manager.stream_workers[self.quality].remove(self)
|
|
|
@ -392,8 +393,9 @@ class StreamWorker(object):
|
|
|
|
if date is not None:
|
|
|
|
if date is not None:
|
|
|
|
date += datetime.timedelta(seconds=segment.duration)
|
|
|
|
date += datetime.timedelta(seconds=segment.duration)
|
|
|
|
|
|
|
|
|
|
|
|
# Clean up any old segment getters
|
|
|
|
# Clean up any old segment getters.
|
|
|
|
for url, getter in self.getters.items():
|
|
|
|
# Note use of list() to make a copy to avoid modification-during-iteration
|
|
|
|
|
|
|
|
for url, getter in list(self.getters.items()):
|
|
|
|
# If segment is done and wasn't in latest fetch
|
|
|
|
# If segment is done and wasn't in latest fetch
|
|
|
|
if getter.done.is_set() and not any(
|
|
|
|
if getter.done.is_set() and not any(
|
|
|
|
segment.uri == url for segment in playlist.segments
|
|
|
|
segment.uri == url for segment in playlist.segments
|
|
|
@ -512,7 +514,7 @@ class SegmentGetter(object):
|
|
|
|
partial: Segment is incomplete. Hash is included.
|
|
|
|
partial: Segment is incomplete. Hash is included.
|
|
|
|
temp: Segment has not been downloaded yet. A random uuid is added.
|
|
|
|
temp: Segment has not been downloaded yet. A random uuid is added.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
arg = str(uuid.uuid4()) if type == "temp" else b64encode(hash.digest(), b"-_").encode().rstrip("=")
|
|
|
|
arg = str(uuid.uuid4()) if type == "temp" else b64encode(hash.digest(), b"-_").decode().rstrip("=")
|
|
|
|
return "{}-{}-{}.ts".format(self.prefix, type, arg)
|
|
|
|
return "{}-{}-{}.ts".format(self.prefix, type, arg)
|
|
|
|
|
|
|
|
|
|
|
|
def exists(self):
|
|
|
|
def exists(self):
|
|
|
|