1
0
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:
Johan Andersson 2015-12-27 14:40:27 +01:00
parent eb7bd48d5a
commit 66898565b3

View File

@ -11,7 +11,6 @@ from svtplay_dl.utils import filenamify, ensure_unicode
from svtplay_dl.utils.urllib import urlparse, urljoin from svtplay_dl.utils.urllib import urlparse, urljoin
from svtplay_dl.fetcher.hds import hdsparse from svtplay_dl.fetcher.hds import hdsparse
from svtplay_dl.fetcher.hls import hlsparse from svtplay_dl.fetcher.hls import hlsparse
from svtplay_dl.fetcher.rtmp import RTMP
from svtplay_dl.fetcher.http import HTTP from svtplay_dl.fetcher.http import HTTP
from svtplay_dl.subtitle import subtitle from svtplay_dl.subtitle import subtitle
from svtplay_dl.error import ServiceError 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'] supported_domains = ['svtplay.se', 'svt.se', 'beta.svtplay.se', 'svtflow.se']
def get(self): def get(self):
if re.findall("svt.se", self.url): old = False
data = self.get_urldata()
match = re.search(r"data-json-href=\"(.*)\"", data) parse = urlparse(self.url)
if match: if parse.netloc == "www.svtplay.se":
filename = match.group(1).replace("&", "&").replace("&format=json", "") if parse.path[:6] != "/video":
url = "http://www.svt.se%s" % filename yield ServiceError("This mode is not supported anymore. need the url with the video")
else:
yield ServiceError("Can't find video file for: %s" % self.url)
return return
else: match = re.search('data-video-id="([^"]+)"', self.get_urldata())
url = self.url 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
url = "http://www.svt.se/videoplayer-api/video/%s" % vid
if "svt.se" in url: data = self.http.request("get", url)
params = {"format": "json"}
else:
params = {"output": "json"}
data = self.http.request("get", url, params=params)
if data.status_code == 404: if data.status_code == 404:
yield ServiceError("Can't get the json file for %s" % url) yield ServiceError("Can't get the json file for %s" % url)
return return
data = data.json() data = data.json()
if "live" in data["video"]: if "live" in data:
self.options.live = data["video"]["live"] 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: if self.options.output_auto:
self.options.service = "svtplay" 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): if self.exclude(self.options):
yield ServiceError("Excluding video") yield ServiceError("Excluding video")
return 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: try:
suburl = data["video"]["subtitleReferences"][0]["url"] suburl = dataj["video"]["subtitleReferences"][0]["url"]
except KeyError: except KeyError:
pass pass
if suburl and len(suburl) > 0: if suburl and len(suburl) > 0:
@ -65,32 +75,23 @@ class Svtplay(Service, OpenGraphThumbMixin):
if self.options.force_subtitle: if self.options.force_subtitle:
return return
if len(data["video"].get("videoReferences", [])) == 0: if len(data["videoReferences"]) == 0:
yield ServiceError("Media doesn't have any associated videos (yet?)") yield ServiceError("Media doesn't have any associated videos (yet?)")
return return
for i in data["video"]["videoReferences"]: for i in data["videoReferences"]:
parse = urlparse(i["url"]) if i["format"] == "hls":
if parse.path.find("m3u8") > 0:
streams = hlsparse(self.options, self.http.request("get", i["url"]), i["url"]) streams = hlsparse(self.options, self.http.request("get", i["url"]), i["url"])
if streams: if streams:
for n in list(streams.keys()): for n in list(streams.keys()):
yield streams[n] yield streams[n]
elif parse.path.find("f4m") > 0: if i["format"] == "hds":
match = re.search(r"\/se\/secure\/", i["url"]) match = re.search(r"\/se\/secure\/", i["url"])
if not match: if not match:
streams = hdsparse(self.options, self.http.request("get", i["url"], params={"hdcore": "3.7.0"}), i["url"]) streams = hdsparse(self.options, self.http.request("get", i["url"], params={"hdcore": "3.7.0"}), i["url"])
if streams: if streams:
for n in list(streams.keys()): for n in list(streams.keys()):
yield streams[n] 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: else:
yield HTTP(copy.copy(self.options), i["url"], "0") yield HTTP(copy.copy(self.options), i["url"], "0")
@ -118,8 +119,9 @@ class Svtplay(Service, OpenGraphThumbMixin):
return sorted(episodes_new) return sorted(episodes_new)
def outputfilename(data, filename, raw): def outputfilename(self, data, filename, raw):
directory = os.path.dirname(filename) directory = os.path.dirname(filename)
if "statistics" in data:
name = data["statistics"]["folderStructure"] name = data["statistics"]["folderStructure"]
if name.find(".") > 0: if name.find(".") > 0:
name = name[:name.find(".")] name = name[:name.find(".")]
@ -127,12 +129,21 @@ def outputfilename(data, filename, raw):
if match: if match:
name = name.replace("arkiv-", "") name = name.replace("arkiv-", "")
name = name.replace("-", ".") name = name.replace("-", ".")
season = seasoninfo(raw)
other = filenamify(data["context"]["title"]) other = filenamify(data["context"]["title"])
if season: id = data["videoId"]
title = "%s.%s.%s-%s-svtplay" % (name, season, other, data["videoId"])
else: 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) title = filenamify(title)
if len(directory): if len(directory):
output = os.path.join(directory, title) output = os.path.join(directory, title)
@ -141,7 +152,7 @@ def outputfilename(data, filename, raw):
return output return output
def seasoninfo(data): def seasoninfo(self, data):
match = re.search(r'play_video-area-aside__sub-title">([^<]+)<span', data) match = re.search(r'play_video-area-aside__sub-title">([^<]+)<span', data)
if match: if match:
line = match.group(1) line = match.group(1)