forked from DRMTalks/devine
Fix possible soft-lock in HLS if Queue is left empty after error
This commit is contained in:
parent
7df6aa42b4
commit
c3a22431f0
|
@ -222,49 +222,53 @@ class HLS:
|
||||||
segment_save_path = (save_dir / filename).with_suffix(".mp4")
|
segment_save_path = (save_dir / filename).with_suffix(".mp4")
|
||||||
|
|
||||||
newest_segment_key = segment_key.get()
|
newest_segment_key = segment_key.get()
|
||||||
if segment.key and newest_segment_key[1] != segment.key:
|
try:
|
||||||
try:
|
if segment.key and newest_segment_key[1] != segment.key:
|
||||||
drm = HLS.get_drm(
|
try:
|
||||||
# TODO: We append master.keys because m3u8 class only puts the last EXT-X-KEY
|
drm = HLS.get_drm(
|
||||||
# to the segment.key property, not supporting multi-drm scenarios.
|
# TODO: We append master.keys because m3u8 class only puts the last EXT-X-KEY
|
||||||
# By re-adding every single EXT-X-KEY found, we can at least try to get
|
# to the segment.key property, not supporting multi-drm scenarios.
|
||||||
# a suitable key. However, it may not match the right segment/timeframe!
|
# By re-adding every single EXT-X-KEY found, we can at least try to get
|
||||||
# It will try to use the first key provided where possible.
|
# a suitable key. However, it may not match the right segment/timeframe!
|
||||||
keys=[segment.key] + master.keys,
|
# It will try to use the first key provided where possible.
|
||||||
proxy=proxy
|
keys=[segment.key] + master.keys,
|
||||||
)
|
proxy=proxy
|
||||||
except NotImplementedError as e:
|
)
|
||||||
log.error(str(e))
|
except NotImplementedError as e:
|
||||||
sys.exit(1)
|
log.error(str(e))
|
||||||
else:
|
sys.exit(1)
|
||||||
if drm:
|
else:
|
||||||
drm = drm[0] # just use the first supported DRM system for now
|
if drm:
|
||||||
log.debug("Got segment key, %s", drm)
|
drm = drm[0] # just use the first supported DRM system for now
|
||||||
if isinstance(drm, Widevine):
|
log.debug("Got segment key, %s", drm)
|
||||||
# license and grab content keys
|
if isinstance(drm, Widevine):
|
||||||
if not license_widevine:
|
# license and grab content keys
|
||||||
raise ValueError("license_widevine func must be supplied to use Widevine DRM")
|
if not license_widevine:
|
||||||
license_widevine(drm)
|
raise ValueError("license_widevine func must be supplied to use Widevine DRM")
|
||||||
newest_segment_key = (drm, segment.key)
|
license_widevine(drm)
|
||||||
segment_key.put(newest_segment_key)
|
newest_segment_key = (drm, segment.key)
|
||||||
|
finally:
|
||||||
|
segment_key.put(newest_segment_key)
|
||||||
|
|
||||||
if callable(track.OnSegmentFilter) and track.OnSegmentFilter(segment):
|
if callable(track.OnSegmentFilter) and track.OnSegmentFilter(segment):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
newest_init_data = init_data.get()
|
newest_init_data = init_data.get()
|
||||||
if segment.init_section and (not newest_init_data or segment.discontinuity):
|
try:
|
||||||
# Only use the init data if there's no init data yet (e.g., start of file)
|
if segment.init_section and (not newest_init_data or segment.discontinuity):
|
||||||
# or if EXT-X-DISCONTINUITY is reached at the same time as EXT-X-MAP.
|
# Only use the init data if there's no init data yet (e.g., start of file)
|
||||||
# Even if a new EXT-X-MAP is supplied, it may just be duplicate and would
|
# or if EXT-X-DISCONTINUITY is reached at the same time as EXT-X-MAP.
|
||||||
# be unnecessary and slow to re-download the init data each time.
|
# Even if a new EXT-X-MAP is supplied, it may just be duplicate and would
|
||||||
if not segment.init_section.uri.startswith(segment.init_section.base_uri):
|
# be unnecessary and slow to re-download the init data each time.
|
||||||
segment.init_section.uri = segment.init_section.base_uri + segment.init_section.uri
|
if not segment.init_section.uri.startswith(segment.init_section.base_uri):
|
||||||
|
segment.init_section.uri = segment.init_section.base_uri + segment.init_section.uri
|
||||||
|
|
||||||
log.debug("Got new init segment, %s", segment.init_section.uri)
|
log.debug("Got new init segment, %s", segment.init_section.uri)
|
||||||
res = session.get(segment.init_section.uri)
|
res = session.get(segment.init_section.uri)
|
||||||
res.raise_for_status()
|
res.raise_for_status()
|
||||||
newest_init_data = res.content
|
newest_init_data = res.content
|
||||||
init_data.put(newest_init_data)
|
finally:
|
||||||
|
init_data.put(newest_init_data)
|
||||||
|
|
||||||
if not segment.uri.startswith(segment.base_uri):
|
if not segment.uri.startswith(segment.base_uri):
|
||||||
segment.uri = segment.base_uri + segment.uri
|
segment.uri = segment.base_uri + segment.uri
|
||||||
|
|
Loading…
Reference in New Issue