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 -*-
|
2013-03-01 23:39:42 +01:00
|
|
|
from __future__ import absolute_import
|
2013-02-12 19:43:37 +01:00
|
|
|
import re
|
2013-03-03 10:58:37 +01:00
|
|
|
import json
|
2014-06-07 20:43:40 +02:00
|
|
|
import copy
|
2014-04-03 21:09:42 +02:00
|
|
|
import xml.etree.ElementTree as ET
|
2013-02-12 19:43:37 +01:00
|
|
|
|
2014-01-19 14:26:48 +01:00
|
|
|
from svtplay_dl.service import Service, OpenGraphThumbMixin
|
2015-03-07 10:43:21 +01:00
|
|
|
from svtplay_dl.utils.urllib import urljoin
|
2014-04-21 19:04:53 +02:00
|
|
|
from svtplay_dl.fetcher.rtmp import RTMP
|
2014-04-21 21:55:39 +02:00
|
|
|
from svtplay_dl.fetcher.hls import HLS, hlsparse
|
2015-09-06 22:41:29 +02:00
|
|
|
from svtplay_dl.log import log
|
2015-09-06 14:19:10 +02:00
|
|
|
from svtplay_dl.error import ServiceError
|
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):
|
2014-01-01 14:57:17 +01:00
|
|
|
supported_domains = ['urplay.se', 'ur.se']
|
2013-01-17 00:21:47 +01:00
|
|
|
|
2014-01-11 23:02:47 +01:00
|
|
|
def __init__(self, url):
|
|
|
|
Service.__init__(self, url)
|
|
|
|
self.subtitle = None
|
|
|
|
|
2014-01-06 23:14:06 +01:00
|
|
|
def get(self, options):
|
2015-08-30 00:06:20 +02:00
|
|
|
data = self.get_urldata()
|
2014-12-08 23:07:02 +01:00
|
|
|
match = re.search(r"urPlayer.init\((.*)\);", data)
|
2014-01-03 12:15:21 +01:00
|
|
|
if not match:
|
2015-09-06 14:19:10 +02:00
|
|
|
yield ServiceError("Can't find json info")
|
2014-10-06 23:21:43 +02:00
|
|
|
return
|
2014-12-22 17:41:40 +01:00
|
|
|
|
|
|
|
if self.exclude(options):
|
2015-09-06 23:04:48 +02:00
|
|
|
yield ServiceError("Excluding video")
|
2014-12-22 17:41:40 +01:00
|
|
|
return
|
|
|
|
|
2014-01-03 12:15:21 +01:00
|
|
|
data = match.group(1)
|
2013-03-03 10:58:37 +01:00
|
|
|
jsondata = json.loads(data)
|
2015-05-06 10:33:24 +02:00
|
|
|
if len(jsondata["subtitles"]) > 0:
|
|
|
|
yield subtitle(copy.copy(options), "tt", jsondata["subtitles"][0]["file"].split(",")[0])
|
2013-03-03 10:58:37 +01:00
|
|
|
basedomain = jsondata["streaming_config"]["streamer"]["redirect"]
|
2015-03-21 17:34:22 +01:00
|
|
|
http = "http://%s/%s" % (basedomain, jsondata["file_http"])
|
2014-01-09 00:32:14 +01:00
|
|
|
hd = None
|
2015-03-21 17:34:22 +01:00
|
|
|
if len(jsondata["file_http_hd"]) > 0:
|
|
|
|
http_hd = "http://%s/%s" % (basedomain, jsondata["file_http_hd"])
|
2014-01-09 00:32:14 +01:00
|
|
|
hls_hd = "%s%s" % (http_hd, jsondata["streaming_config"]["http_streaming"]["hls_file"])
|
2015-03-21 17:34:22 +01:00
|
|
|
tmp = jsondata["file_http_hd"]
|
2015-05-06 10:42:03 +02:00
|
|
|
match = re.search("(mp[34]:.*$)", tmp)
|
2014-02-02 18:22:35 +01:00
|
|
|
path_hd = match.group(1)
|
2014-01-09 00:32:14 +01:00
|
|
|
hd = True
|
2013-03-03 10:58:37 +01:00
|
|
|
hls = "%s%s" % (http, jsondata["streaming_config"]["http_streaming"]["hls_file"])
|
|
|
|
rtmp = "rtmp://%s/%s" % (basedomain, jsondata["streaming_config"]["rtmp"]["application"])
|
2015-05-06 10:42:03 +02:00
|
|
|
match = re.search("(mp[34]:.*$)", jsondata["file_rtmp"])
|
|
|
|
path = match.group(1)
|
2015-08-31 23:17:51 +02:00
|
|
|
streams = hlsparse(hls, self.http.request("get", hls).text)
|
2014-04-21 21:55:39 +02:00
|
|
|
for n in list(streams.keys()):
|
|
|
|
yield HLS(options, streams[n], n)
|
2014-04-21 19:04:53 +02:00
|
|
|
options.other = "-v -a %s -y %s" % (jsondata["streaming_config"]["rtmp"]["application"], path)
|
|
|
|
yield RTMP(options, rtmp, "480")
|
2014-01-09 00:32:14 +01:00
|
|
|
if hd:
|
2015-09-02 18:51:07 +02:00
|
|
|
streams = hlsparse(hls_hd, self.http.request("get", hls_hd).text)
|
2014-04-21 21:55:39 +02:00
|
|
|
for n in list(streams.keys()):
|
2014-06-07 20:43:40 +02:00
|
|
|
yield HLS(copy.copy(options), streams[n], n)
|
2014-04-21 19:04:53 +02:00
|
|
|
options.other = "-v -a %s -y %s" % (jsondata["streaming_config"]["rtmp"]["application"], path_hd)
|
2014-06-07 20:43:40 +02:00
|
|
|
yield RTMP(copy.copy(options), rtmp, "720")
|
2014-01-11 23:02:47 +01:00
|
|
|
|
2015-03-07 10:43:21 +01:00
|
|
|
def scrape_episodes(self, options):
|
|
|
|
res = []
|
|
|
|
for relurl in re.findall(r'<a class="puff tv video"\s+title="[^"]*"\s+href="([^"]*)"',
|
2015-08-30 00:06:20 +02:00
|
|
|
self.get_urldata()):
|
2015-03-07 10:43:21 +01:00
|
|
|
res.append(urljoin(self.url, relurl.replace("&", "&")))
|
|
|
|
|
|
|
|
if options.all_last != -1:
|
|
|
|
res = res[-options.all_last:]
|
|
|
|
|
|
|
|
return res
|
|
|
|
|
2014-04-03 21:09:42 +02:00
|
|
|
def find_all_episodes(self, options):
|
|
|
|
match = re.search(r'<link rel="alternate" type="application/rss\+xml" [^>]*href="([^"]+)"',
|
2015-08-30 00:06:20 +02:00
|
|
|
self.get_urldata())
|
2014-04-03 21:09:42 +02:00
|
|
|
if match is None:
|
2015-03-07 10:43:21 +01:00
|
|
|
log.info("Couldn't retrieve episode list as rss, trying to scrape")
|
|
|
|
return self.scrape_episodes(options)
|
|
|
|
|
2014-04-03 21:09:42 +02:00
|
|
|
url = "http://urplay.se%s" % match.group(1).replace("&", "&")
|
2015-08-31 19:45:15 +02:00
|
|
|
xml = ET.XML(self.http.request("get", url).content)
|
2014-04-03 21:09:42 +02:00
|
|
|
|
2014-12-21 13:45:44 +01:00
|
|
|
episodes = [x.text for x in xml.findall(".//item/link")]
|
|
|
|
episodes_new = []
|
|
|
|
n = 0
|
|
|
|
for i in episodes:
|
|
|
|
if n == options.all_last:
|
|
|
|
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
|