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

Add support for caption subtitles

This commit is contained in:
Johan Andersson 2023-10-09 00:09:27 +02:00
parent 5ba3aead98
commit f15f366cd5
3 changed files with 14 additions and 4 deletions

View File

@ -281,6 +281,9 @@ def _dashparse(config, text, url, output, cookies, **kwargs):
**kwargs, **kwargs,
) )
for sub in subtitles: for sub in subtitles:
if len(subtitles) > 1:
if sub["role"] and sub["role"] != "main" and sub["role"] != "subtitle":
sub["lang"] = f'{sub["lang"]}-{sub["role"]}'
yield from subtitle_probe(copy.copy(config), url, subfix=sub["lang"], output=copy.copy(loutput), files=sub["files"], **kwargs) yield from subtitle_probe(copy.copy(config), url, subfix=sub["lang"], output=copy.copy(loutput), files=sub["files"], **kwargs)

View File

@ -89,13 +89,16 @@ def _hlsparse(config, text, url, output, **kwargs):
segments = False segments = False
if i["TYPE"] == "SUBTITLES": if i["TYPE"] == "SUBTITLES":
if "URI" in i: if "URI" in i:
caption = None
if i["GROUP-ID"] not in subtitles: if i["GROUP-ID"] not in subtitles:
subtitles[i["GROUP-ID"]] = [] subtitles[i["GROUP-ID"]] = []
if "LANGUAGE" in i: if "LANGUAGE" in i:
lang = i["LANGUAGE"] lang = i["LANGUAGE"]
else: else:
lang = "und" lang = "und"
item = [i["URI"], lang] if "CHARACTERISTICS" in i:
caption = True
item = [i["URI"], lang, caption]
if item not in subtitles[i["GROUP-ID"]]: if item not in subtitles[i["GROUP-ID"]]:
subtitles[i["GROUP-ID"]].append(item) subtitles[i["GROUP-ID"]].append(item)
continue continue
@ -165,8 +168,12 @@ def _hlsparse(config, text, url, output, **kwargs):
if subtitles: if subtitles:
for sub in list(subtitles.keys()): for sub in list(subtitles.keys()):
for n in subtitles[sub]: for n in subtitles[sub]:
subfix = n[2]
if len(subtitles[sub]) > 1:
if subfix:
subfix = f"{n[1]}-caption"
yield from subtitle_probe( yield from subtitle_probe(
copy.copy(config), get_full_url(n[0], url), output=copy.copy(output), subfix=n[1], cookies=cookies, **kwargs copy.copy(config), get_full_url(n[0], url), output=copy.copy(output), subfix=subfix, cookies=cookies, **kwargs
) )
elif m3u8.media_segment: elif m3u8.media_segment:

View File

@ -32,7 +32,7 @@ def subtitle_probe(config, url, **kwargs):
elif subdata.text.startswith("#EXTM3U"): elif subdata.text.startswith("#EXTM3U"):
m3u8 = M3U8(subdata.text) m3u8 = M3U8(subdata.text)
yield subtitle(config, "wrstsegment", url, **kwargs, m3u8=m3u8) yield subtitle(config, "wrstsegment", url, **kwargs, m3u8=m3u8)
elif "<?xml" in subdata.text: elif "<?xml" in subdata.text or "<MPD" in subdata.text:
xmldata = ET.fromstring(subdata.text) xmldata = ET.fromstring(subdata.text)
if xmldata.tag.endswith("MPD"): if xmldata.tag.endswith("MPD"):
data = http.get(kwargs.get("files")[0]).content data = http.get(kwargs.get("files")[0]).content
@ -57,7 +57,7 @@ class subtitle:
self.kwargs = kwargs self.kwargs = kwargs
def __repr__(self): def __repr__(self):
return f"<Subtitle(type={self.subtype}, url={self.url}>" return f"<Subtitle(type={self.subtype}, url={self.url} subfix={self.subfix}>"
def download(self): def download(self):
output_ext = "srt" output_ext = "srt"