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:
parent
9756bcfbd1
commit
d6dc139925
@ -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"]
|
for n in list(streams.keys()):
|
||||||
http = "https://{}/{}".format(basedomain, jsondata["file_http"])
|
yield streams[n]
|
||||||
hd = None
|
url = "https://{}/{}playlist.m3u8".format(loadbalancer, stream["hd"]["location"])
|
||||||
if len(jsondata["file_http_hd"]) > 0:
|
streams = hlsparse(self.config, self.http.request("get", url), url, output=self.output)
|
||||||
http_hd = "https://{}/{}".format(basedomain, jsondata["file_http_hd"])
|
for n in list(streams.keys()):
|
||||||
hls_hd = "{}{}".format(http_hd, jsondata["streaming_config"]["http_streaming"]["hls_file"])
|
yield streams[n]
|
||||||
hd = True
|
if not self.config.get("get_all_subtitles"):
|
||||||
hls = "{}{}".format(http, jsondata["streaming_config"]["http_streaming"]["hls_file"])
|
yield subtitle(copy.copy(self.config), "tt", stream["tt"]["location"], output=self.output)
|
||||||
streams = hlsparse(self.config, self.http.request("get", hls), hls, output=self.output)
|
|
||||||
for n in list(streams.keys()):
|
if self.config.get("get_all_subtitles") and "tt" in stream:
|
||||||
yield streams[n]
|
label = stream["tt"]["language"]
|
||||||
if hd:
|
if stream["tt"]["scope"] != "complete":
|
||||||
streams = hlsparse(self.config, self.http.request("get", hls_hd), hls_hd, output=self.output)
|
label = "{}-{}".format(label, stream["tt"]["scope"])
|
||||||
for n in list(streams.keys()):
|
yield subtitle(copy.copy(self.config), "tt", stream["tt"]["location"], label, output=self.output)
|
||||||
yield streams[n]
|
|
||||||
|
|
||||||
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()
|
if not match:
|
||||||
match = re.search('data-limit="[^"]+" href="([^"]+)"', data)
|
logging.error("Can't find json info")
|
||||||
if match:
|
return
|
||||||
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:
|
|
||||||
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))
|
|
||||||
|
|
||||||
|
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:
|
||||||
|
Loading…
Reference in New Issue
Block a user