2013-03-02 21:26:28 +01:00
|
|
|
# ex:ts=4:sw=4:sts=4:et
|
|
|
|
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
2014-06-07 20:43:40 +02:00
|
|
|
import copy
|
2019-08-25 00:40:39 +02:00
|
|
|
import json
|
2018-11-18 12:47:19 +01:00
|
|
|
import logging
|
2019-08-25 00:40:39 +02:00
|
|
|
import re
|
2020-10-10 13:30:44 +02:00
|
|
|
from html import unescape
|
2013-02-12 19:43:37 +01:00
|
|
|
|
2015-09-06 14:19:10 +02:00
|
|
|
from svtplay_dl.error import ServiceError
|
2019-08-25 00:40:39 +02:00
|
|
|
from svtplay_dl.fetcher.hls import hlsparse
|
|
|
|
from svtplay_dl.service import OpenGraphThumbMixin
|
|
|
|
from svtplay_dl.service import Service
|
2014-08-31 01:20:36 +02:00
|
|
|
from svtplay_dl.subtitle import subtitle
|
2013-02-12 19:43:37 +01:00
|
|
|
|
2015-09-15 20:10:32 +02:00
|
|
|
|
2014-01-19 14:26:48 +01:00
|
|
|
class Urplay(Service, OpenGraphThumbMixin):
|
2019-08-25 00:27:31 +02:00
|
|
|
supported_domains = ["urplay.se", "ur.se", "betaplay.ur.se", "urskola.se"]
|
2013-01-17 00:21:47 +01:00
|
|
|
|
2015-12-26 11:46:14 +01:00
|
|
|
def get(self):
|
2021-01-18 21:41:44 +01:00
|
|
|
key = "currentProduct"
|
2020-10-10 13:30:44 +02:00
|
|
|
match = re.search(r'/Player/Player" data-react-props="([^\"]+)\"', self.get_urldata())
|
2014-01-03 12:15:21 +01:00
|
|
|
if not match:
|
2021-01-18 21:41:44 +01:00
|
|
|
key = "program"
|
|
|
|
match = re.search(r'/ProgramContainer" data-react-props="([^\"]+)\"', self.get_urldata())
|
|
|
|
if not match:
|
|
|
|
yield ServiceError("Can't find json info")
|
|
|
|
return
|
2014-12-22 17:41:40 +01:00
|
|
|
|
2020-10-10 13:30:44 +02:00
|
|
|
data = unescape(match.group(1))
|
2013-03-03 10:58:37 +01:00
|
|
|
jsondata = json.loads(data)
|
2016-11-30 23:21:42 +01:00
|
|
|
|
2020-10-10 13:30:44 +02:00
|
|
|
res = self.http.get("https://streaming-loadbalancer.ur.se/loadbalancer.json")
|
|
|
|
loadbalancer = res.json()["redirect"]
|
|
|
|
|
2021-01-18 21:41:44 +01:00
|
|
|
for streaminfo in jsondata[key]["streamingInfo"].keys():
|
|
|
|
stream = jsondata[key]["streamingInfo"][streaminfo]
|
2020-10-21 09:06:05 +02:00
|
|
|
if streaminfo == "raw":
|
2020-12-29 14:08:31 +01:00
|
|
|
if "sd" in stream:
|
|
|
|
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" in stream:
|
|
|
|
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]
|
2020-10-21 09:06:05 +02:00
|
|
|
if not (self.config.get("get_all_subtitles")) and (stream["default"]):
|
|
|
|
yield subtitle(copy.copy(self.config), "tt", stream["tt"]["location"], output=self.output)
|
2020-10-10 13:30:44 +02:00
|
|
|
|
|
|
|
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)
|
2014-01-11 23:02:47 +01:00
|
|
|
|
2018-05-13 13:06:45 +02:00
|
|
|
def find_all_episodes(self, config):
|
2016-12-06 22:42:54 +01:00
|
|
|
episodes = []
|
2017-09-16 17:36:37 +02:00
|
|
|
|
2020-10-10 13:30:44 +02:00
|
|
|
match = re.search(r'/Player/Player" data-react-props="([^\"]+)\"', self.get_urldata())
|
|
|
|
if not match:
|
|
|
|
logging.error("Can't find json info")
|
|
|
|
return
|
|
|
|
|
|
|
|
data = unescape(match.group(1))
|
|
|
|
jsondata = json.loads(data)
|
2014-04-03 21:09:42 +02:00
|
|
|
|
2020-10-10 13:30:44 +02:00
|
|
|
for episode in jsondata["accessibleEpisodes"]:
|
|
|
|
episodes.append("https://urplay.se/program/{}".format(episode["slug"]))
|
2014-12-21 13:45:44 +01:00
|
|
|
episodes_new = []
|
|
|
|
n = 0
|
|
|
|
for i in episodes:
|
2018-05-13 13:06:45 +02:00
|
|
|
if n == config.get("all_last"):
|
2014-12-21 13:45:44 +01:00
|
|
|
break
|
2015-09-06 22:41:49 +02:00
|
|
|
if i not in episodes_new:
|
|
|
|
episodes_new.append(i)
|
2014-12-21 13:45:44 +01:00
|
|
|
n += 1
|
2015-03-07 10:43:21 +01:00
|
|
|
return episodes_new
|