1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-27 21:54:17 +01:00

hls: support for detecting codecs

This commit is contained in:
Johan Andersson 2020-07-28 21:26:13 +02:00
parent 566738b8f1
commit 7c35b3032f

View File

@ -50,7 +50,8 @@ def hlsparse(config, res, url, **kwargs):
authorization = kwargs.pop("authorization", None) authorization = kwargs.pop("authorization", None)
httpobject = kwargs.pop("httpobject", None) httpobject = kwargs.pop("httpobject", None)
output = kwargs.pop("output", None) output = kwargs.pop("output", None)
channels = kwargs.pop("channels", None)
codec = kwargs.pop("codec", "h264")
media = {} media = {}
subtitles = {} subtitles = {}
segments = None segments = None
@ -58,6 +59,8 @@ def hlsparse(config, res, url, **kwargs):
if m3u8.master_playlist: if m3u8.master_playlist:
for i in m3u8.master_playlist: for i in m3u8.master_playlist:
audio_url = None audio_url = None
vcodec = None
chans = None
if i["TAG"] == "EXT-X-MEDIA": if i["TAG"] == "EXT-X-MEDIA":
if "AUTOSELECT" in i and (i["AUTOSELECT"].upper() == "YES"): if "AUTOSELECT" in i and (i["AUTOSELECT"].upper() == "YES"):
if i["TYPE"] and i["TYPE"] != "SUBTITLES": if i["TYPE"] and i["TYPE"] != "SUBTITLES":
@ -66,7 +69,10 @@ def hlsparse(config, res, url, **kwargs):
segments = True segments = True
if i["GROUP-ID"] not in media: if i["GROUP-ID"] not in media:
media[i["GROUP-ID"]] = [] media[i["GROUP-ID"]] = []
media[i["GROUP-ID"]].append(i["URI"]) if "CHANNELS" in i:
if i["CHANNELS"] == "6":
chans = "51"
media[i["GROUP-ID"]].append([i["URI"], chans])
else: else:
segments = False segments = False
if i["TYPE"] == "SUBTITLES": if i["TYPE"] == "SUBTITLES":
@ -82,11 +88,20 @@ def hlsparse(config, res, url, **kwargs):
bit_rate = float(i["AVERAGE-BANDWIDTH"]) / 1000 bit_rate = float(i["AVERAGE-BANDWIDTH"]) / 1000
else: else:
bit_rate = float(i["BANDWIDTH"]) / 1000 bit_rate = float(i["BANDWIDTH"]) / 1000
if "CODECS" in i:
if i["CODECS"][:3] == "hvc":
vcodec = "hevc"
if i["CODECS"][:3] == "avc":
vcodec = "h264"
if "AUDIO" in i and (i["AUDIO"] in media): if "AUDIO" in i and (i["AUDIO"] in media):
audio_url = get_full_url(media[i["AUDIO"]][0], url) chans = media[i["AUDIO"]][0][1]
audio_url = get_full_url(media[i["AUDIO"]][0][0], url)
urls = get_full_url(i["URI"], url) urls = get_full_url(i["URI"], url)
else: else:
continue # Needs to be changed to utilise other tags. continue # Needs to be changed to utilise other tags.
chans = chans if audio_url else channels
codec = vcodec if vcodec else codec
streams[int(bit_rate)] = HLS( streams[int(bit_rate)] = HLS(
copy.copy(config), copy.copy(config),
urls, urls,
@ -97,7 +112,9 @@ def hlsparse(config, res, url, **kwargs):
audio=audio_url, audio=audio_url,
output=output, output=output,
segments=bool(segments), segments=bool(segments),
kwargs=kwargs, channels=chans,
codec=codec,
**kwargs,
) )
if subtitles and httpobject: if subtitles and httpobject: