1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-27 13:44:14 +01:00

viafree: they have m3u8 subtitles in json

For some reason they got some bad data in the first file that we need to skip
fixes: #1332
This commit is contained in:
Johan Andersson 2021-03-05 00:41:49 +01:00
parent 998f51fdf6
commit cb3612b313
2 changed files with 18 additions and 2 deletions

View File

@ -11,6 +11,7 @@ from urllib.parse import urlparse
from svtplay_dl.error import ServiceError
from svtplay_dl.fetcher.hls import hlsparse
from svtplay_dl.fetcher.hls import M3U8
from svtplay_dl.service import OpenGraphThumbMixin
from svtplay_dl.service import Service
from svtplay_dl.subtitle import subtitle
@ -62,7 +63,17 @@ class Viaplay(Service, OpenGraphThumbMixin):
self._autoname(video)
if "subtitles" in video["_embedded"]["program"] and "subtitlesWebvtt" in video["_embedded"]["program"]["subtitles"]:
yield subtitle(copy.copy(self.config), "wrst", video["_embedded"]["program"]["subtitles"]["subtitlesWebvtt"], output=self.output)
if "m3u8" in video["_embedded"]["program"]["subtitles"]["subtitlesWebvtt"]:
m3u8s = M3U8(self.http.get(video["_embedded"]["program"]["subtitles"]["subtitlesWebvtt"]).text)
yield subtitle(
copy.copy(self.config),
"wrstsegment",
video["_embedded"]["program"]["subtitles"]["subtitlesWebvtt"],
output=copy.copy(self.output),
m3u8=m3u8s,
)
else:
yield subtitle(copy.copy(self.config), "wrst", video["_embedded"]["program"]["subtitles"]["subtitlesWebvtt"], output=self.output)
res = self.http.get(video["_embedded"]["program"]["_links"]["streamLink"]["href"])
janson = res.json()

View File

@ -281,6 +281,8 @@ class subtitle:
cont = self.http.get(itemurl)
if "cmore" in self.url:
cont.encoding = "utf-8"
if "mtgx" in self.url:
cont.encoding = "utf-8"
text = cont.text.split("\n")
for t in text: # is in text[1] for tv4play, but this should be more future proof
if "X-TIMESTAMP-MAP=MPEGTS" in t:
@ -294,6 +296,7 @@ class subtitle:
several_items = False
skip = False
pre_date_skip = True
sub = []
for x in range(len(itmes)):
@ -304,6 +307,7 @@ class subtitle:
second = str2sec(ha3.group(2)) + time
subs[-1][0] = "{} --> {}".format(ha.group(1), sec2str(second))
skip = True
pre_date_skip = False
continue
has_date = strdate(item)
if has_date:
@ -315,7 +319,8 @@ class subtitle:
second = str2sec(has_date.group(2)) + time
sub.append("{} --> {}".format(sec2str(first), sec2str(second)))
several_items = True
elif has_date is None and skip is False:
pre_date_skip = False
elif has_date is None and skip is False and pre_date_skip is False:
sub.append(item)
if sub: