1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-12-01 07:34:16 +01:00
svtplay-dl/lib/svtplay_dl/service/kanal5.py

94 lines
3.9 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
2014-06-07 20:43:40 +02:00
import copy
2014-08-12 19:57:03 +02:00
import os
from svtplay_dl.utils.urllib import CookieJar, Cookie
from svtplay_dl.service import Service
2014-08-12 19:57:03 +02:00
from svtplay_dl.utils import get_http_data, filenamify
from svtplay_dl.log import log
2014-04-21 18:26:03 +02:00
from svtplay_dl.fetcher.rtmp import RTMP
2014-07-10 18:23:30 +02:00
from svtplay_dl.fetcher.hls import HLS, hlsparse
2014-04-21 19:52:44 +02:00
from svtplay_dl.subtitle import subtitle_json
class Kanal5(Service):
2014-08-12 19:57:53 +02:00
supported_domains = ['kanal5play.se', 'kanal9play.se', 'kanal11play.se']
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)
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:
2014-07-28 16:01:27 +02:00
# bogus
2013-03-14 22:20:27 +01:00
cc = Cookie(None, 'asdf', None, '80', '80', 'www.kanal5play.se', None, None, '/', None, False, False, 'TestCookie', None, None, None)
self.cj.set_cookie(cc)
2014-07-28 16:01:27 +02:00
# get session cookie
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)
match = re.search(r"({.*})\);", data)
2013-03-14 22:20:27 +01:00
jsondata = json.loads(match.group(1))
2014-08-12 00:08:51 +02:00
if jsondata["success"] is False:
2013-03-14 22:20:27 +01:00
log.error(jsondata["message"])
sys.exit(2)
authToken = jsondata["userData"]["auth"]
cc = Cookie(version=0, name='authToken',
2014-07-28 15:57:25 +02:00
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})
self.cj.set_cookie(cc)
2013-03-14 22:20:27 +01:00
2014-04-21 18:26:03 +02:00
url = "http://www.kanal5play.se/api/getVideo?format=FLASH&videoId=%s" % video_id
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-04-21 19:52:44 +02:00
yield subtitle_json("http://www.kanal5play.se/api/subtitles/%s" % video_id)
2014-08-12 19:57:03 +02:00
if options.output_auto:
directory = os.path.dirname(options.output)
title = "%s-%s-s%s-%s" % (data["comscoreStation"], data["program"]["name"], data["seasonNumber"], data["episodeText"])
title = filenamify(title)
if len(directory):
options.output = "%s/%s" % (directory, title)
else:
options.output = title
2014-04-21 18:26:03 +02:00
for i in data["streams"]:
if i["drmProtected"]:
log.error("We cant download drm files for this site.")
sys.exit(2)
steambaseurl = data["streamBaseUrl"]
2014-07-13 14:27:34 +02:00
bitrate = i["bitrate"]
if bitrate > 1000:
bitrate = bitrate / 1000
2014-07-13 16:04:33 +02:00
options2 = copy.copy(options)
options2.other = "-W %s -y %s " % ("http://www.kanal5play.se/flash/K5StandardPlayer.swf", i["source"])
options2.live = True
yield RTMP(options2, steambaseurl, bitrate)
2014-07-10 18:23:30 +02:00
url = "http://www.kanal5play.se/api/getVideo?format=IPAD&videoId=%s" % video_id
data = json.loads(get_http_data(url, cookiejar=self.cj))
if "streams" in data.keys():
for i in data["streams"]:
streams = hlsparse(i["source"])
for n in list(streams.keys()):
yield HLS(copy.copy(options), streams[n], n)