1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-24 20:25:41 +01:00
svtplay-dl/lib/svtplay_dl/service/urplay.py

81 lines
3.2 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
2014-04-03 21:09:42 +02:00
import xml.etree.ElementTree as ET
from svtplay_dl.service import Service, OpenGraphThumbMixin
2014-12-08 23:07:02 +01:00
from svtplay_dl.utils import get_http_data
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
2014-01-08 23:36:57 +01:00
from svtplay_dl.log import log
from svtplay_dl.subtitle import subtitle
class Urplay(Service, OpenGraphThumbMixin):
supported_domains = ['urplay.se', 'ur.se']
def __init__(self, url):
Service.__init__(self, url)
self.subtitle = None
2014-01-06 23:14:06 +01:00
def get(self, options):
2014-12-08 23:07:02 +01:00
error, data = self.get_urldata()
if error:
2014-11-26 16:01:30 +01:00
log.error("Can't get the page")
return
2014-12-08 23:07:02 +01:00
match = re.search(r"urPlayer.init\((.*)\);", data)
if not match:
log.error("Can't find json info")
2014-10-06 23:21:43 +02:00
return
if self.exclude(options):
return
data = match.group(1)
jsondata = json.loads(data)
yield subtitle(copy.copy(options), "tt", jsondata["subtitles"].split(",")[0])
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
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-04-21 21:55:39 +02:00
streams = hlsparse(hls)
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:
2014-04-21 21:55:39 +02:00
streams = hlsparse(hls_hd)
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-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="([^"]+)"',
2014-12-08 23:07:02 +01:00
self.get_urldata()[1])
2014-04-03 21:09:42 +02:00
if match is None:
log.error("Couldn't retrieve episode list")
2014-11-25 21:46:33 +01:00
return
2014-04-03 21:09:42 +02:00
url = "http://urplay.se%s" % match.group(1).replace("&amp;", "&")
2014-12-08 23:07:02 +01:00
xml = ET.XML(get_http_data(url)[1])
2014-04-03 21:09:42 +02: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
episodes_new.append(i)
n += 1
return episodes_new