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 sys
|
|
|
|
import re
|
|
|
|
import json
|
|
|
|
|
2013-04-21 13:42:33 +02:00
|
|
|
from svtplay_dl.utils.urllib import CookieJar, Cookie
|
2013-04-21 12:44:31 +02:00
|
|
|
from svtplay_dl.service import Service
|
2013-03-24 20:24:08 +01:00
|
|
|
from svtplay_dl.utils import get_http_data, select_quality, subtitle_json
|
2013-03-17 19:55:19 +01:00
|
|
|
from svtplay_dl.log import log
|
|
|
|
from svtplay_dl.fetcher.rtmp import download_rtmp
|
2013-03-24 20:33:39 +01:00
|
|
|
from svtplay_dl.fetcher.hls import download_hls
|
2013-02-12 19:43:37 +01:00
|
|
|
|
2013-04-21 12:44:31 +02:00
|
|
|
class Kanal5(Service):
|
2014-01-01 14:57:17 +01:00
|
|
|
supported_domains = ['kanal5play.se', 'kanal9play.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.cj = CookieJar()
|
|
|
|
self.subtitle = None
|
|
|
|
|
2014-01-06 23:14:06 +01:00
|
|
|
def get(self, options):
|
|
|
|
match = re.search(r".*video/([0-9]+)", self.url)
|
2013-01-17 00:21:47 +01:00
|
|
|
if not match:
|
|
|
|
log.error("Can't find video file")
|
|
|
|
sys.exit(2)
|
2013-03-14 22:20:27 +01:00
|
|
|
|
|
|
|
video_id = match.group(1)
|
|
|
|
if options.username and options.password:
|
|
|
|
#bogus
|
|
|
|
cc = Cookie(None, 'asdf', None, '80', '80', 'www.kanal5play.se', None, None, '/', None, False, False, 'TestCookie', None, None, None)
|
2014-01-11 23:02:47 +01:00
|
|
|
self.cj.set_cookie(cc)
|
2013-03-14 22:20:27 +01:00
|
|
|
#get session cookie
|
2014-01-11 23:02:47 +01:00
|
|
|
data = get_http_data("http://www.kanal5play.se/", cookiejar=self.cj)
|
2013-03-14 22:20:27 +01:00
|
|
|
authurl = "https://kanal5swe.appspot.com/api/user/login?callback=jQuery171029989&email=%s&password=%s&_=136250" % (options.username, options.password)
|
|
|
|
data = get_http_data(authurl)
|
2013-05-05 12:57:42 +02:00
|
|
|
match = re.search(r"({.*})\);", data)
|
2013-03-14 22:20:27 +01:00
|
|
|
jsondata = json.loads(match.group(1))
|
|
|
|
if jsondata["success"] == False:
|
|
|
|
log.error(jsondata["message"])
|
|
|
|
sys.exit(2)
|
|
|
|
authToken = jsondata["userData"]["auth"]
|
|
|
|
cc = Cookie(version=0, name='authToken',
|
|
|
|
value=authToken,
|
|
|
|
port=None, port_specified=False,
|
|
|
|
domain='www.kanal5play.se',
|
|
|
|
domain_specified=True,
|
|
|
|
domain_initial_dot=True, path='/',
|
|
|
|
path_specified=True, secure=False,
|
|
|
|
expires=None, discard=True, comment=None,
|
|
|
|
comment_url=None, rest={'HttpOnly': None})
|
2014-01-11 23:02:47 +01:00
|
|
|
self.cj.set_cookie(cc)
|
2013-03-14 22:20:27 +01:00
|
|
|
|
2013-04-27 13:27:30 +02:00
|
|
|
format_ = "FLASH"
|
2013-03-10 14:09:35 +01:00
|
|
|
if options.hls:
|
2013-04-27 13:27:30 +02:00
|
|
|
format_ = "IPHONE"
|
|
|
|
url = "http://www.kanal5play.se/api/getVideo?format=%s&videoId=%s" % (format_, video_id)
|
2014-01-11 23:02:47 +01:00
|
|
|
data = json.loads(get_http_data(url, cookiejar=self.cj))
|
2014-03-26 22:47:30 +01:00
|
|
|
if not options.live:
|
|
|
|
options.live = data["isLive"]
|
2013-03-10 13:58:25 +01:00
|
|
|
if data["hasSubtitle"]:
|
2014-01-11 23:02:47 +01:00
|
|
|
self.subtitle = "http://www.kanal5play.se/api/subtitles/%s" % video_id
|
2014-03-21 20:59:58 +01:00
|
|
|
|
|
|
|
if options.subtitle and options.force_subtitle:
|
|
|
|
return
|
|
|
|
|
2013-03-10 14:09:35 +01:00
|
|
|
if options.hls:
|
|
|
|
url = data["streams"][0]["source"]
|
2013-03-10 14:10:54 +01:00
|
|
|
if data["streams"][0]["drmProtected"]:
|
|
|
|
log.error("We cant download drm files for this site.")
|
|
|
|
sys.exit(2)
|
2014-02-08 16:08:39 +01:00
|
|
|
download_hls(options, url)
|
2013-03-10 14:09:35 +01:00
|
|
|
else:
|
|
|
|
streams = {}
|
2013-01-17 00:21:47 +01:00
|
|
|
|
2013-03-10 14:09:35 +01:00
|
|
|
for i in data["streams"]:
|
|
|
|
stream = {}
|
2014-02-05 22:13:26 +01:00
|
|
|
if i["drmProtected"]:
|
|
|
|
log.error("We cant download drm files for this site.")
|
|
|
|
sys.exit(2)
|
2013-03-10 14:09:35 +01:00
|
|
|
stream["source"] = i["source"]
|
|
|
|
streams[int(i["bitrate"])] = stream
|
2013-01-17 00:21:47 +01:00
|
|
|
|
2014-02-05 22:13:26 +01:00
|
|
|
steambaseurl = data["streamBaseUrl"]
|
|
|
|
|
2013-03-10 14:09:35 +01:00
|
|
|
test = select_quality(options, streams)
|
2013-01-17 00:21:47 +01:00
|
|
|
|
2013-03-10 14:09:35 +01:00
|
|
|
filename = test["source"]
|
2013-05-05 12:57:42 +02:00
|
|
|
match = re.search(r"^(.*):", filename)
|
2013-03-10 14:11:48 +01:00
|
|
|
options.other = "-W %s -y %s " % ("http://www.kanal5play.se/flash/K5StandardPlayer.swf", filename)
|
2013-03-10 14:09:35 +01:00
|
|
|
download_rtmp(options, steambaseurl)
|
2014-01-11 23:02:47 +01:00
|
|
|
|
|
|
|
def get_subtitle(self, options):
|
|
|
|
if self.subtitle:
|
|
|
|
data = get_http_data(self.subtitle, cookiejar=self.cj)
|
|
|
|
subtitle_json(options, data)
|