1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-25 04:35:45 +01:00
svtplay-dl/lib/svtplay/service/kanal5.py

82 lines
3.3 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 sys
import re
import json
from svtplay.utils import get_http_data, select_quality
from svtplay.log import log
from svtplay.fetcher.rtmp import download_rtmp
class Kanal5():
def handle(self, url):
2013-03-10 14:00:22 +01:00
return ("kanal5play.se" in url) or ('kanal9play.se' in url)
def get(self, options, url):
match = re.search(".*video/([0-9]+)", url)
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)
cj.set_cookie(cc)
#get session cookie
data = get_http_data("http://www.kanal5play.se/", cookiejar=cj)
authurl = "https://kanal5swe.appspot.com/api/user/login?callback=jQuery171029989&email=%s&password=%s&_=136250" % (options.username, options.password)
data = get_http_data(authurl)
match = re.search("({.*})\);", data)
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})
cj.set_cookie(cc)
2013-03-10 14:09:35 +01:00
format = "FLASH"
if options.hls:
format = "IPHONE"
2013-03-14 22:20:27 +01:00
url = "http://www.kanal5play.se/api/getVideo?format=%s&videoId=%s" % (format, video_id)
data = json.loads(get_http_data(url, cookiejar=cj))
options.live = data["isLive"]
2013-03-10 13:58:25 +01:00
if data["hasSubtitle"]:
2013-03-14 22:20:27 +01:00
subtitle = "http://www.kanal5play.se/api/subtitles/%s" % video_id)
2013-03-10 14:09:35 +01:00
if options.hls:
url = data["streams"][0]["source"]
baseurl = url[0:url.rfind("/")]
if data["streams"][0]["drmProtected"]:
log.error("We cant download drm files for this site.")
sys.exit(2)
2013-03-10 14:09:35 +01:00
download_hls(options, url, baseurl)
else:
steambaseurl = data["streamBaseUrl"]
streams = {}
2013-03-10 14:09:35 +01:00
for i in data["streams"]:
stream = {}
stream["source"] = i["source"]
streams[int(i["bitrate"])] = stream
2013-03-10 14:09:35 +01:00
test = select_quality(options, streams)
2013-03-10 14:09:35 +01:00
filename = test["source"]
match = re.search("^(.*):", 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)
2013-03-10 13:58:25 +01:00
if options.subtitle:
if options.output != "-":
2013-03-14 22:20:27 +01:00
data = get_http_data(subtitle, cookiejar=cj)
2013-03-10 13:58:25 +01:00
subtitle_json(options, data)