1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-23 19:55:38 +01:00

urplay: Fix so we can download videos again

This commit is contained in:
Johan Andersson 2020-10-10 13:30:44 +02:00
parent 9756bcfbd1
commit d6dc139925

View File

@ -4,8 +4,7 @@ import copy
import json
import logging
import re
from urllib.parse import urljoin
from urllib.parse import urlparse
from html import unescape
from svtplay_dl.error import ServiceError
from svtplay_dl.fetcher.hls import hlsparse
@ -18,78 +17,50 @@ class Urplay(Service, OpenGraphThumbMixin):
supported_domains = ["urplay.se", "ur.se", "betaplay.ur.se", "urskola.se"]
def get(self):
data = self.get_urldata()
match = re.search(r"urPlayer.init\((.*)\);", data)
match = re.search(r'/Player/Player" data-react-props="([^\"]+)\"', self.get_urldata())
if not match:
yield ServiceError("Can't find json info")
return
data = match.group(1)
data = unescape(match.group(1))
jsondata = json.loads(data)
if len(jsondata["subtitles"]) > 0:
for sub in jsondata["subtitles"]:
if "label" in sub:
absurl = urljoin(self.url, sub["file"].split(",")[0])
if absurl.endswith("vtt"):
subtype = "wrst"
else:
subtype = "tt"
if self.config.get("get_all_subtitles"):
yield subtitle(copy.copy(self.config), subtype, absurl, sub["label"], output=self.output)
else:
yield subtitle(copy.copy(self.config), subtype, absurl, output=self.output)
if "streamer" in jsondata["streaming_config"]:
basedomain = jsondata["streaming_config"]["streamer"]["redirect"]
else:
url = jsondata["streaming_config"]["loadbalancer"]
if url[:1] == "/":
url = "https:{}".format(url)
lbjson = self.http.request("get", url).text
lbjson = json.loads(lbjson)
basedomain = lbjson["redirect"]
http = "https://{}/{}".format(basedomain, jsondata["file_http"])
hd = None
if len(jsondata["file_http_hd"]) > 0:
http_hd = "https://{}/{}".format(basedomain, jsondata["file_http_hd"])
hls_hd = "{}{}".format(http_hd, jsondata["streaming_config"]["http_streaming"]["hls_file"])
hd = True
hls = "{}{}".format(http, jsondata["streaming_config"]["http_streaming"]["hls_file"])
streams = hlsparse(self.config, self.http.request("get", hls), hls, output=self.output)
res = self.http.get("https://streaming-loadbalancer.ur.se/loadbalancer.json")
loadbalancer = res.json()["redirect"]
for streaminfo in jsondata["currentProduct"]["streamingInfo"].keys():
stream = jsondata["currentProduct"]["streamingInfo"][streaminfo]
if stream["default"]:
url = "https://{}/{}playlist.m3u8".format(loadbalancer, stream["sd"]["location"])
streams = hlsparse(self.config, self.http.request("get", url), url, output=self.output)
for n in list(streams.keys()):
yield streams[n]
if hd:
streams = hlsparse(self.config, self.http.request("get", hls_hd), hls_hd, output=self.output)
url = "https://{}/{}playlist.m3u8".format(loadbalancer, stream["hd"]["location"])
streams = hlsparse(self.config, self.http.request("get", url), url, output=self.output)
for n in list(streams.keys()):
yield streams[n]
if not self.config.get("get_all_subtitles"):
yield subtitle(copy.copy(self.config), "tt", stream["tt"]["location"], output=self.output)
if self.config.get("get_all_subtitles") and "tt" in stream:
label = stream["tt"]["language"]
if stream["tt"]["scope"] != "complete":
label = "{}-{}".format(label, stream["tt"]["scope"])
yield subtitle(copy.copy(self.config), "tt", stream["tt"]["location"], label, output=self.output)
def find_all_episodes(self, config):
parse = urlparse(self.url)
episodes = []
if parse.netloc == "urskola.se":
data = self.get_urldata()
match = re.search('data-limit="[^"]+" href="([^"]+)"', data)
if match:
res = self.http.get(urljoin("https://urskola.se", match.group(1)))
data = res.text
tags = re.findall('<a class="puff program tv video" title="[^"]+" href="([^"]+)"', data)
for i in tags:
url = urljoin("https://urskola.se/", i)
if url not in episodes:
episodes.append(url)
else:
match = re.search(r"/program/\d+-(\w+)-", parse.path)
match = re.search(r'/Player/Player" data-react-props="([^\"]+)\"', self.get_urldata())
if not match:
logging.error("Can't find any videos")
return None
keyword = match.group(1)
all_links = re.findall('card-link" href="([^"]+)"', self.get_urldata())
for i in all_links:
match = re.search(r"/program/\d+-(\w+)-", i)
if match and match.group(1) == keyword:
episodes.append(urljoin("https://urplay.se/", i))
logging.error("Can't find json info")
return
data = unescape(match.group(1))
jsondata = json.loads(data)
for episode in jsondata["accessibleEpisodes"]:
episodes.append("https://urplay.se/program/{}".format(episode["slug"]))
episodes_new = []
n = 0
for i in episodes: