1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-24 04:05:39 +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.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,52 +119,62 @@ class Svtplay(Service, OpenGraphThumbMixin):
return sorted(episodes_new)
def outputfilename(data, filename, raw):
directory = os.path.dirname(filename)
name = data["statistics"]["folderStructure"]
if name.find(".") > 0:
name = name[:name.find(".")]
match = re.search("^arkiv-", name)
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"])
else:
title = "%s.%s-%s-svtplay" % (name, other, data["videoId"])
title = filenamify(title)
if len(directory):
output = os.path.join(directory, title)
else:
output = title
return output
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(".")]
match = re.search("^arkiv-", name)
if match:
name = name.replace("arkiv-", "")
name = name.replace("-", ".")
other = filenamify(data["context"]["title"])
id = data["videoId"]
else:
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)
else:
output = title
return output
def seasoninfo(data):
match = re.search(r'play_video-area-aside__sub-title">([^<]+)<span', data)
if match:
line = match.group(1)
else:
match = re.search(r'data-title="([^"]+)"', data)
def seasoninfo(self, data):
match = re.search(r'play_video-area-aside__sub-title">([^<]+)<span', data)
if match:
line = match.group(1)
else:
return None
match = re.search(r'data-title="([^"]+)"', data)
if match:
line = match.group(1)
else:
return None
line = re.sub(" +", "", match.group(1)).replace('\n', '')
match = re.search(r"(song(\d+)-)?Avsnitt(\d+)", line)
if match:
if match.group(2) is None:
season = 1
line = re.sub(" +", "", match.group(1)).replace('\n', '')
match = re.search(r"(song(\d+)-)?Avsnitt(\d+)", line)
if match:
if match.group(2) is None:
season = 1
else:
season = int(match.group(2))
if season < 10:
season = "0%s" % season
episode = int(match.group(3))
if episode < 10:
episode = "0%s" % episode
return "S%sE%s" % (season, episode)
else:
season = int(match.group(2))
if season < 10:
season = "0%s" % season
episode = int(match.group(3))
if episode < 10:
episode = "0%s" % episode
return "S%sE%s" % (season, episode)
else:
return None
return None