1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-28 06:04:17 +01:00
svtplay-dl/lib/svtplay_dl/service/urplay.py

102 lines
4.1 KiB
Python
Raw Normal View History

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 -*-
from __future__ import absolute_import
import re
import json
2014-06-07 20:43:40 +02:00
import copy
2018-01-30 22:07:21 +01:00
from urllib.parse import urljoin, urlparse
from svtplay_dl.service import Service, OpenGraphThumbMixin
from svtplay_dl.fetcher.hls import hlsparse
2015-09-06 22:41:29 +02:00
from svtplay_dl.log import log
from svtplay_dl.error import ServiceError
from svtplay_dl.subtitle import subtitle
2015-09-15 20:10:32 +02:00
class Urplay(Service, OpenGraphThumbMixin):
supported_domains = ['urplay.se', 'ur.se', 'betaplay.ur.se', 'urskola.se']
def get(self):
data = self.get_urldata()
2014-12-08 23:07:02 +01:00
match = re.search(r"urPlayer.init\((.*)\);", data)
if not match:
yield ServiceError("Can't find json info")
2014-10-06 23:21:43 +02:00
return
data = 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"
2018-05-13 13:06:45 +02:00
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)
2015-10-25 02:07:25 +02:00
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
2015-10-25 02:07:25 +02:00
lbjson = json.loads(lbjson)
basedomain = lbjson["redirect"]
2018-01-04 22:09:17 +01:00
http = "https://{0}/{1}".format(basedomain, jsondata["file_http"])
2014-01-09 00:32:14 +01:00
hd = None
if len(jsondata["file_http_hd"]) > 0:
2018-01-04 22:09:17 +01:00
http_hd = "https://{0}/{1}".format(basedomain, jsondata["file_http_hd"])
hls_hd = "{0}{1}".format(http_hd, jsondata["streaming_config"]["http_streaming"]["hls_file"])
2014-01-09 00:32:14 +01:00
hd = True
hls = "{0}{1}".format(http, jsondata["streaming_config"]["http_streaming"]["hls_file"])
streams = hlsparse(self.config, self.http.request("get", hls), hls, output=self.output)
2014-04-21 21:55:39 +02:00
for n in list(streams.keys()):
yield streams[n]
2014-01-09 00:32:14 +01:00
if hd:
streams = hlsparse(self.config, self.http.request("get", hls_hd), hls_hd, output=self.output)
2014-04-21 21:55:39 +02:00
for n in list(streams.keys()):
yield streams[n]
2018-05-13 13:06:45 +02:00
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:
2018-01-04 22:16:49 +01:00
res = self.http.get(urljoin("https://urskola.se", match.group(1)))
data = res.text
2018-01-04 22:16:49 +01:00
tags = re.findall('<a class="puff program tv video" title="[^"]+" href="([^"]+)"', data)
for i in tags:
2018-01-04 22:16:49 +01:00
url = urljoin("https://urskola.se/", i)
if url not in episodes:
episodes.append(url)
else:
match = re.search("/program/\d+-(\w+)-", parse.path)
if not match:
log.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("/program/\d+-(\w+)-", i)
if match and match.group(1) == keyword:
2018-01-04 22:09:17 +01:00
episodes.append(urljoin("https://urplay.se/", i))
2014-04-03 21:09:42 +02:00
episodes_new = []
n = 0
for i in episodes:
2018-05-13 13:06:45 +02:00
if n == config.get("all_last"):
break
2015-09-06 22:41:49 +02:00
if i not in episodes_new:
episodes_new.append(i)
n += 1
return episodes_new