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-04-27 13:17:00 +02:00
|
|
|
|
|
|
|
# pylint has issues with urlparse: "some types could not be inferred"
|
|
|
|
# pylint: disable=E1103
|
|
|
|
|
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 xml.etree.ElementTree as ET
|
|
|
|
|
2013-04-21 13:42:33 +02:00
|
|
|
from svtplay_dl.utils.urllib import urlparse
|
2014-01-26 01:54:20 +01:00
|
|
|
from svtplay_dl.service import Service, OpenGraphThumbMixin
|
2013-03-24 20:24:08 +01:00
|
|
|
from svtplay_dl.utils import get_http_data, subtitle_sami
|
2013-03-17 19:55:19 +01:00
|
|
|
from svtplay_dl.log import log
|
|
|
|
from svtplay_dl.fetcher.rtmp import download_rtmp
|
2013-02-12 19:43:37 +01:00
|
|
|
|
2014-01-26 01:54:20 +01:00
|
|
|
class Viaplay(Service, OpenGraphThumbMixin):
|
2014-01-01 14:57:17 +01:00
|
|
|
supported_domains = [
|
2014-01-16 21:41:48 +01:00
|
|
|
'tv3play.se', 'tv6play.se', 'tv8play.se', 'tv10play.se',
|
|
|
|
'tv3play.no', 'tv3play.dk', 'tv6play.no', 'viasat4play.no',
|
2014-02-05 21:50:31 +01:00
|
|
|
'tv3play.ee', 'tv3play.lv', 'tv3play.lt', 'tvplay.lv']
|
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-03-09 15:56:00 +01:00
|
|
|
|
|
|
|
def _get_video_id(self):
|
|
|
|
"""
|
|
|
|
Extract video id. It will try to avoid making an HTTP request
|
|
|
|
if it can find the ID in the URL, but otherwise it will try
|
|
|
|
to scrape it from the HTML document. Returns None in case it's
|
|
|
|
unable to extract the ID at all.
|
|
|
|
"""
|
2014-01-06 23:14:06 +01:00
|
|
|
parse = urlparse(self.url)
|
2014-02-05 12:28:10 +01:00
|
|
|
match = re.search(r'\/(\d+)/?', parse.path)
|
2014-03-09 15:56:00 +01:00
|
|
|
if match:
|
|
|
|
return match.group(1)
|
|
|
|
|
|
|
|
html_data = self.get_urldata()
|
|
|
|
match = re.search(r'data-link="[^"]+/([0-9]+)"', html_data)
|
|
|
|
if match:
|
|
|
|
return match.group(1)
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def get(self, options):
|
|
|
|
vid = self._get_video_id()
|
|
|
|
if vid is None:
|
2013-01-17 00:21:47 +01:00
|
|
|
log.error("Cant find video file")
|
|
|
|
sys.exit(2)
|
2014-03-09 15:56:00 +01:00
|
|
|
|
|
|
|
url = "http://viastream.viasat.tv/PlayProduct/%s" % vid
|
2013-01-17 00:21:47 +01:00
|
|
|
options.other = ""
|
|
|
|
data = get_http_data(url)
|
|
|
|
xml = ET.XML(data)
|
2013-08-10 20:38:42 +02:00
|
|
|
live = xml.find("Product").find("LiveInfo")
|
|
|
|
if live is not None:
|
|
|
|
live = live.find("Live").text
|
|
|
|
if live == "true":
|
|
|
|
options.live = True
|
2014-02-05 22:03:16 +01:00
|
|
|
if xml.find("Product").find("Syndicate").text == "true":
|
|
|
|
options.live = True
|
2013-01-17 00:21:47 +01:00
|
|
|
filename = xml.find("Product").find("Videos").find("Video").find("Url").text
|
2014-01-11 23:02:47 +01:00
|
|
|
self.subtitle = xml.find("Product").find("SamiFile").text
|
2013-01-17 00:21:47 +01:00
|
|
|
|
|
|
|
if filename[:4] == "http":
|
|
|
|
data = get_http_data(filename)
|
|
|
|
xml = ET.XML(data)
|
|
|
|
filename = xml.find("Url").text
|
2014-02-05 21:46:19 +01:00
|
|
|
if xml.find("Msg").text:
|
|
|
|
log.error("Can't download file:")
|
|
|
|
log.error(xml.find("Msg").text)
|
|
|
|
sys.exit(2)
|
2013-01-17 00:21:47 +01:00
|
|
|
|
2013-08-15 14:20:02 +02:00
|
|
|
parse = urlparse(filename)
|
2013-12-23 23:14:24 +01:00
|
|
|
match = re.search("^(/[a-z0-9]{0,20})/(.*)", parse.path)
|
2013-08-15 14:20:02 +02:00
|
|
|
if not match:
|
|
|
|
log.error("Somthing wrong with rtmpparse")
|
|
|
|
sys.exit(2)
|
2014-03-09 17:26:27 +01:00
|
|
|
filename = "%s://%s:%s%s" % (parse.scheme, parse.hostname, parse.port, match.group(1))
|
2013-08-15 14:20:02 +02:00
|
|
|
path = "-y %s" % match.group(2)
|
|
|
|
options.other = "-W http://flvplayer.viastream.viasat.tv/flvplayer/play/swf/player.swf %s" % path
|
2013-01-17 00:21:47 +01:00
|
|
|
download_rtmp(options, filename)
|
2014-01-11 23:02:47 +01:00
|
|
|
|
|
|
|
def get_subtitle(self, options):
|
|
|
|
if self.subtitle:
|
|
|
|
data = get_http_data(self.subtitle)
|
|
|
|
subtitle_sami(options, data)
|