mirror of
https://github.com/spaam/svtplay-dl.git
synced 2024-11-24 12:15:40 +01:00
svtplay: support for the next version of the page.
video id is left to fix... dunno how to do it in a good way
This commit is contained in:
parent
eb7bd48d5a
commit
66898565b3
@ -11,7 +11,6 @@ from svtplay_dl.utils import filenamify, ensure_unicode
|
||||
from svtplay_dl.utils.urllib import urlparse, urljoin
|
||||
from svtplay_dl.fetcher.hds import hdsparse
|
||||
from svtplay_dl.fetcher.hls import hlsparse
|
||||
from svtplay_dl.fetcher.rtmp import RTMP
|
||||
from svtplay_dl.fetcher.http import HTTP
|
||||
from svtplay_dl.subtitle import subtitle
|
||||
from svtplay_dl.error import ServiceError
|
||||
@ -21,42 +20,53 @@ class Svtplay(Service, OpenGraphThumbMixin):
|
||||
supported_domains = ['svtplay.se', 'svt.se', 'beta.svtplay.se', 'svtflow.se']
|
||||
|
||||
def get(self):
|
||||
if re.findall("svt.se", self.url):
|
||||
data = self.get_urldata()
|
||||
match = re.search(r"data-json-href=\"(.*)\"", data)
|
||||
if match:
|
||||
filename = match.group(1).replace("&", "&").replace("&format=json", "")
|
||||
url = "http://www.svt.se%s" % filename
|
||||
else:
|
||||
yield ServiceError("Can't find video file for: %s" % self.url)
|
||||
old = False
|
||||
|
||||
parse = urlparse(self.url)
|
||||
if parse.netloc == "www.svtplay.se":
|
||||
if parse.path[:6] != "/video":
|
||||
yield ServiceError("This mode is not supported anymore. need the url with the video")
|
||||
return
|
||||
else:
|
||||
url = self.url
|
||||
match = re.search('data-video-id="([^"]+)"', self.get_urldata())
|
||||
if not match:
|
||||
match = re.search("/video/([0-9]+)/", parse.path)
|
||||
if not match:
|
||||
yield ServiceError("Cant find video id for this video")
|
||||
return
|
||||
vid = match.group(1)
|
||||
if re.match("^[0-9]+$", vid):
|
||||
old = True
|
||||
|
||||
|
||||
if "svt.se" in url:
|
||||
params = {"format": "json"}
|
||||
else:
|
||||
params = {"output": "json"}
|
||||
|
||||
data = self.http.request("get", url, params=params)
|
||||
url = "http://www.svt.se/videoplayer-api/video/%s" % vid
|
||||
data = self.http.request("get", url)
|
||||
if data.status_code == 404:
|
||||
yield ServiceError("Can't get the json file for %s" % url)
|
||||
return
|
||||
|
||||
data = data.json()
|
||||
if "live" in data["video"]:
|
||||
self.options.live = data["video"]["live"]
|
||||
if "live" in data:
|
||||
self.options.live = data["live"]
|
||||
if old:
|
||||
params = {"output": "json"}
|
||||
dataj = self.http.request("get", self.url, params=params).json()
|
||||
else:
|
||||
dataj = data
|
||||
|
||||
if self.options.output_auto:
|
||||
self.options.service = "svtplay"
|
||||
self.options.output = outputfilename(data, self.options.output, ensure_unicode(self.get_urldata()))
|
||||
self.options.output = self.outputfilename(dataj, self.options.output, ensure_unicode(self.get_urldata()))
|
||||
|
||||
if self.exclude(self.options):
|
||||
yield ServiceError("Excluding video")
|
||||
return
|
||||
|
||||
if data["video"]["subtitleReferences"]:
|
||||
if "subtitleReferences" in data:
|
||||
for i in data["subtitleReferences"]:
|
||||
if i["format"] == "wsrt":
|
||||
yield subtitle(copy.copy(self.options), "wrst", i["url"])
|
||||
if old and dataj["video"]["subtitleReferences"]:
|
||||
try:
|
||||
suburl = data["video"]["subtitleReferences"][0]["url"]
|
||||
suburl = dataj["video"]["subtitleReferences"][0]["url"]
|
||||
except KeyError:
|
||||
pass
|
||||
if suburl and len(suburl) > 0:
|
||||
@ -65,32 +75,23 @@ class Svtplay(Service, OpenGraphThumbMixin):
|
||||
if self.options.force_subtitle:
|
||||
return
|
||||
|
||||
if len(data["video"].get("videoReferences", [])) == 0:
|
||||
if len(data["videoReferences"]) == 0:
|
||||
yield ServiceError("Media doesn't have any associated videos (yet?)")
|
||||
return
|
||||
|
||||
for i in data["video"]["videoReferences"]:
|
||||
parse = urlparse(i["url"])
|
||||
|
||||
if parse.path.find("m3u8") > 0:
|
||||
for i in data["videoReferences"]:
|
||||
if i["format"] == "hls":
|
||||
streams = hlsparse(self.options, self.http.request("get", i["url"]), i["url"])
|
||||
if streams:
|
||||
for n in list(streams.keys()):
|
||||
yield streams[n]
|
||||
elif parse.path.find("f4m") > 0:
|
||||
if i["format"] == "hds":
|
||||
match = re.search(r"\/se\/secure\/", i["url"])
|
||||
if not match:
|
||||
streams = hdsparse(self.options, self.http.request("get", i["url"], params={"hdcore": "3.7.0"}), i["url"])
|
||||
if streams:
|
||||
for n in list(streams.keys()):
|
||||
yield streams[n]
|
||||
elif parse.scheme == "rtmp":
|
||||
embedurl = "%s?type=embed" % url
|
||||
data = self.http.request("get", embedurl).text
|
||||
match = re.search(r"value=\"(/(public)?(statiskt)?/swf(/video)?/svtplayer-[0-9\.a-f]+swf)\"", data)
|
||||
swf = "http://www.svtplay.se%s" % match.group(1)
|
||||
self.options.other = "-W %s" % swf
|
||||
yield RTMP(copy.copy(self.options), i["url"], i["bitrate"])
|
||||
else:
|
||||
yield HTTP(copy.copy(self.options), i["url"], "0")
|
||||
|
||||
@ -118,8 +119,9 @@ class Svtplay(Service, OpenGraphThumbMixin):
|
||||
return sorted(episodes_new)
|
||||
|
||||
|
||||
def outputfilename(data, filename, raw):
|
||||
def outputfilename(self, data, filename, raw):
|
||||
directory = os.path.dirname(filename)
|
||||
if "statistics" in data:
|
||||
name = data["statistics"]["folderStructure"]
|
||||
if name.find(".") > 0:
|
||||
name = name[:name.find(".")]
|
||||
@ -127,12 +129,21 @@ def outputfilename(data, filename, raw):
|
||||
if match:
|
||||
name = name.replace("arkiv-", "")
|
||||
name = name.replace("-", ".")
|
||||
season = seasoninfo(raw)
|
||||
other = filenamify(data["context"]["title"])
|
||||
if season:
|
||||
title = "%s.%s.%s-%s-svtplay" % (name, season, other, data["videoId"])
|
||||
id = data["videoId"]
|
||||
else:
|
||||
title = "%s.%s-%s-svtplay" % (name, other, data["videoId"])
|
||||
name = data["programTitle"]
|
||||
if name.find(".") > 0:
|
||||
name = name[:name.find(".")]
|
||||
name = name.replace(" - ", ".")
|
||||
other = filenamify(data["episodeTitle"])
|
||||
id = data["programVersionId"]
|
||||
|
||||
season = self.seasoninfo(raw)
|
||||
if season:
|
||||
title = "%s.%s.%s-%s-svtplay" % (name, season, other, id)
|
||||
else:
|
||||
title = "%s.%s-%s-svtplay" % (name, other, id)
|
||||
title = filenamify(title)
|
||||
if len(directory):
|
||||
output = os.path.join(directory, title)
|
||||
@ -141,7 +152,7 @@ def outputfilename(data, filename, raw):
|
||||
return output
|
||||
|
||||
|
||||
def seasoninfo(data):
|
||||
def seasoninfo(self, data):
|
||||
match = re.search(r'play_video-area-aside__sub-title">([^<]+)<span', data)
|
||||
if match:
|
||||
line = match.group(1)
|
||||
|
Loading…
Reference in New Issue
Block a user