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 -*-
|
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
|
2021-10-30 12:05:08 +02:00
|
|
|
from urllib.parse import urljoin
|
2023-06-18 13:02:53 +02:00
|
|
|
from urllib.parse import urlparse
|
2013-02-12 19:43:37 +01:00
|
|
|
|
2015-09-06 14:19:10 +02:00
|
|
|
from svtplay_dl.error import ServiceError
|
2023-03-15 06:53:24 +01:00
|
|
|
from svtplay_dl.fetcher.dash import dashparse
|
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
|
2021-11-13 14:31:47 +01:00
|
|
|
from svtplay_dl.utils.http import download_thumbnails
|
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-02-28 23:14:34 +01:00
|
|
|
urldata = self.get_urldata()
|
2021-10-30 12:05:08 +02:00
|
|
|
match = re.search(r"__NEXT_DATA__\" type=\"application\/json\">({.+})<\/script>", urldata)
|
2014-01-03 12:15:21 +01:00
|
|
|
if not match:
|
2021-10-30 12:05:08 +02:00
|
|
|
yield ServiceError("Can't find video 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
|
|
|
|
2023-03-15 06:53:24 +01:00
|
|
|
vid = jsondata["props"]["pageProps"]["program"]["id"]
|
2021-10-30 12:05:08 +02:00
|
|
|
jsondata = jsondata["props"]["pageProps"]["program"]
|
2020-10-10 13:30:44 +02:00
|
|
|
|
2023-03-15 06:53:24 +01:00
|
|
|
res = self.http.get(f"https://media-api.urplay.se/config-streaming/v1/urplay/sources/{vid}")
|
2021-02-28 23:14:34 +01:00
|
|
|
|
2023-03-15 06:53:24 +01:00
|
|
|
if "dash" in res.json()["sources"]:
|
|
|
|
yield from dashparse(
|
|
|
|
self.config,
|
|
|
|
self.http.request("get", res.json()["sources"]["dash"]),
|
|
|
|
res.json()["sources"]["dash"],
|
|
|
|
output=self.output,
|
|
|
|
)
|
|
|
|
if "hls" in res.json()["sources"]:
|
|
|
|
yield from hlsparse(self.config, self.http.request("get", res.json()["sources"]["hls"]), res.json()["sources"]["hls"], output=self.output)
|
2020-10-10 13:30:44 +02:00
|
|
|
|
2023-03-15 06:53:24 +01:00
|
|
|
self.outputfilename(jsondata, urldata)
|
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
|
|
|
|
2021-10-30 12:05:08 +02:00
|
|
|
match = re.search(r"__NEXT_DATA__\" type=\"application\/json\">({.+})<\/script>", self.get_urldata())
|
2020-10-10 13:30:44 +02:00
|
|
|
if not match:
|
2021-10-30 12:05:08 +02:00
|
|
|
logging.error("Can't find video info.")
|
2021-12-18 20:18:25 +01:00
|
|
|
return episodes
|
2020-10-10 13:30:44 +02:00
|
|
|
|
|
|
|
data = unescape(match.group(1))
|
|
|
|
jsondata = json.loads(data)
|
2021-10-30 12:05:08 +02:00
|
|
|
seasons = jsondata["props"]["pageProps"]["superSeriesSeasons"]
|
2023-06-18 13:02:53 +02:00
|
|
|
|
|
|
|
parse = urlparse(self.url)
|
|
|
|
url = f"https://{parse.netloc}{parse.path}"
|
|
|
|
episodes.append(url)
|
2021-10-30 12:05:08 +02:00
|
|
|
if seasons:
|
|
|
|
for season in seasons:
|
|
|
|
res = self.http.get(f'https://urplay.se/api/v1/series?id={season["id"]}')
|
|
|
|
for episode in res.json()["programs"]:
|
2023-06-18 13:02:53 +02:00
|
|
|
url = urljoin("https://urplay.se", episode["link"])
|
|
|
|
if url not in episodes:
|
|
|
|
episodes.append(url)
|
2021-10-30 12:05:08 +02:00
|
|
|
else:
|
|
|
|
for episode in jsondata["props"]["pageProps"]["accessibleEpisodes"]:
|
2023-06-18 13:02:53 +02:00
|
|
|
url = urljoin("https://urplay.se", episode["link"])
|
|
|
|
if url not in episodes:
|
|
|
|
episodes.append(url)
|
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
|
2021-02-28 23:14:34 +01:00
|
|
|
|
|
|
|
def outputfilename(self, data, urldata):
|
|
|
|
if "seriesTitle" in data:
|
|
|
|
self.output["title"] = data["seriesTitle"]
|
|
|
|
self.output["title_nice"] = data["seriesTitle"]
|
|
|
|
if "episodeNumber" in data and data["episodeNumber"]:
|
|
|
|
self.output["episode"] = str(data["episodeNumber"])
|
|
|
|
if "title" in data:
|
2021-04-15 19:50:56 +02:00
|
|
|
if self.output["title"] is None:
|
|
|
|
self.output["title"] = data["title"]
|
|
|
|
else:
|
|
|
|
self.output["episodename"] = data["title"]
|
2021-02-28 23:14:34 +01:00
|
|
|
if "id" in data and data["id"]:
|
|
|
|
self.output["id"] = str(data["id"])
|
|
|
|
|
2021-11-13 14:31:47 +01:00
|
|
|
self.output["episodethumbnailurl"] = data["image"]["1280x720"]
|
|
|
|
|
2021-10-30 12:05:08 +02:00
|
|
|
seasonmatch = re.search(r"data-testid=\"season-name-label\">S.song (\d+)...<\/span", urldata)
|
2021-02-28 23:14:34 +01:00
|
|
|
if seasonmatch:
|
|
|
|
self.output["season"] = seasonmatch.group(1)
|
|
|
|
else:
|
|
|
|
self.output["season"] = "1" # No season info - probably show without seasons
|
2021-11-13 14:31:47 +01:00
|
|
|
|
|
|
|
def get_thumbnail(self, options):
|
|
|
|
download_thumbnails(self.output, options, [(False, self.output["episodethumbnailurl"])])
|