1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-24 04:05:39 +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 json
import logging import logging
import re import re
from urllib.parse import urljoin from html import unescape
from urllib.parse import urlparse
from svtplay_dl.error import ServiceError from svtplay_dl.error import ServiceError
from svtplay_dl.fetcher.hls import hlsparse 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"] supported_domains = ["urplay.se", "ur.se", "betaplay.ur.se", "urskola.se"]
def get(self): def get(self):
data = self.get_urldata() match = re.search(r'/Player/Player" data-react-props="([^\"]+)\"', self.get_urldata())
match = re.search(r"urPlayer.init\((.*)\);", data)
if not match: if not match:
yield ServiceError("Can't find json info") yield ServiceError("Can't find json info")
return return
data = match.group(1) data = unescape(match.group(1))
jsondata = json.loads(data) 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"]: res = self.http.get("https://streaming-loadbalancer.ur.se/loadbalancer.json")
basedomain = jsondata["streaming_config"]["streamer"]["redirect"] loadbalancer = res.json()["redirect"]
else:
url = jsondata["streaming_config"]["loadbalancer"] for streaminfo in jsondata["currentProduct"]["streamingInfo"].keys():
if url[:1] == "/": stream = jsondata["currentProduct"]["streamingInfo"][streaminfo]
url = "https:{}".format(url) if stream["default"]:
lbjson = self.http.request("get", url).text url = "https://{}/{}playlist.m3u8".format(loadbalancer, stream["sd"]["location"])
lbjson = json.loads(lbjson) streams = hlsparse(self.config, self.http.request("get", url), url, output=self.output)
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)
for n in list(streams.keys()): for n in list(streams.keys()):
yield streams[n] yield streams[n]
if hd: url = "https://{}/{}playlist.m3u8".format(loadbalancer, stream["hd"]["location"])
streams = hlsparse(self.config, self.http.request("get", hls_hd), hls_hd, output=self.output) streams = hlsparse(self.config, self.http.request("get", url), url, output=self.output)
for n in list(streams.keys()): for n in list(streams.keys()):
yield streams[n] 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): def find_all_episodes(self, config):
parse = urlparse(self.url)
episodes = [] episodes = []
if parse.netloc == "urskola.se": match = re.search(r'/Player/Player" data-react-props="([^\"]+)\"', self.get_urldata())
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)
if not match: if not match:
logging.error("Can't find any videos") logging.error("Can't find json info")
return None return
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))
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 = [] episodes_new = []
n = 0 n = 0
for i in episodes: for i in episodes: