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-01-08 23:36:57 +01:00
|
|
|
import sys
|
2013-02-12 19:43:37 +01:00
|
|
|
|
2014-01-19 14:26:48 +01:00
|
|
|
from svtplay_dl.service import Service, OpenGraphThumbMixin
|
2013-03-24 20:28:14 +01:00
|
|
|
from svtplay_dl.utils import get_http_data, subtitle_tt
|
2013-03-17 19:55:19 +01:00
|
|
|
from svtplay_dl.fetcher.rtmp import download_rtmp
|
|
|
|
from svtplay_dl.fetcher.hls import download_hls
|
2014-01-08 23:36:57 +01:00
|
|
|
from svtplay_dl.log import log
|
2013-02-12 19:43:37 +01: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):
|
2014-02-18 16:48:53 +01:00
|
|
|
match = re.search(r"urPlayer.init\((.*)\);", self.get_urldata())
|
2014-01-03 12:15:21 +01:00
|
|
|
if not match:
|
|
|
|
log.error("Can't find json info")
|
|
|
|
sys.exit(2)
|
|
|
|
data = match.group(1)
|
2013-03-03 10:58:37 +01:00
|
|
|
jsondata = json.loads(data)
|
2014-01-11 23:02:47 +01:00
|
|
|
self.subtitle = jsondata["subtitles"].split(",")[0]
|
2013-03-03 10:58:37 +01:00
|
|
|
basedomain = jsondata["streaming_config"]["streamer"]["redirect"]
|
|
|
|
http = "http://%s/%s" % (basedomain, jsondata["file_html5"])
|
2014-01-09 00:32:14 +01:00
|
|
|
hd = None
|
|
|
|
if len(jsondata["file_html5_hd"]) > 0:
|
|
|
|
http_hd = "http://%s/%s" % (basedomain, jsondata["file_html5_hd"])
|
|
|
|
hls_hd = "%s%s" % (http_hd, jsondata["streaming_config"]["http_streaming"]["hls_file"])
|
2014-02-02 18:22:35 +01:00
|
|
|
tmp = jsondata["file_html5_hd"]
|
|
|
|
match = re.search(".*(mp[34]:.*$)", tmp)
|
|
|
|
path_hd = match.group(1)
|
2014-01-09 00:32:14 +01:00
|
|
|
hd = True
|
2013-04-21 12:33:35 +02:00
|
|
|
#hds = "%s%s" % (http, jsondata["streaming_config"]["http_streaming"]["hds_file"])
|
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"])
|
|
|
|
path = "mp%s:%s" % (jsondata["file_flash"][-1], jsondata["file_flash"])
|
2014-01-09 00:32:14 +01:00
|
|
|
available = {"sd":{"hls":{"http":http, "playlist":hls}, "rtmp":{"server":rtmp, "path":path}}}
|
|
|
|
if hd:
|
|
|
|
available.update({"hd":{"hls":{"http":http_hd, "playlist":hls_hd}, "rtmp":{"server":rtmp, "path":path_hd}}})
|
|
|
|
|
|
|
|
if options.quality:
|
|
|
|
try:
|
|
|
|
selected = available[options.quality]
|
|
|
|
except KeyError:
|
|
|
|
log.error("Can't find that quality. (Try one of: %s)",
|
|
|
|
", ".join([str(elm) for elm in available]))
|
|
|
|
sys.exit(4)
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
selected = self.select_highest_quality(available)
|
|
|
|
except KeyError:
|
|
|
|
log.error("Can't find any streams.")
|
|
|
|
sys.exit(4)
|
|
|
|
|
|
|
|
options.other = "-v -a %s -y %s" % (jsondata["streaming_config"]["rtmp"]["application"], selected["rtmp"]["path"])
|
2014-03-21 20:59:58 +01:00
|
|
|
|
|
|
|
if options.subtitle and options.force_subtitle:
|
|
|
|
return
|
|
|
|
|
2013-03-03 10:58:37 +01:00
|
|
|
if options.hls:
|
2014-02-08 16:08:39 +01:00
|
|
|
download_hls(options, selected["hls"]["playlist"])
|
2013-03-10 13:35:08 +01:00
|
|
|
else:
|
2014-01-09 00:32:14 +01:00
|
|
|
download_rtmp(options, selected["rtmp"]["server"])
|
|
|
|
|
|
|
|
def select_highest_quality(self, available):
|
|
|
|
if 'hd' in available:
|
|
|
|
return available["hd"]
|
|
|
|
elif 'sd' in available:
|
|
|
|
return available["sd"]
|
|
|
|
else:
|
2014-01-06 23:14:06 +01:00
|
|
|
raise KeyError()
|
2014-01-11 23:02:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
def get_subtitle(self, options):
|
|
|
|
if self.subtitle:
|
|
|
|
data = get_http_data(self.subtitle)
|
|
|
|
subtitle_tt(options, data)
|