1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-28 06:04:17 +01:00
svtplay-dl/lib/svtplay_dl/service/viaplay.py

111 lines
4.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 -*-
# pylint has issues with urlparse: "some types could not be inferred"
# pylint: disable=E1103
from __future__ import absolute_import
import sys
import re
import xml.etree.ElementTree as ET
import json
from svtplay_dl.utils.urllib import urlparse
2014-01-26 01:54:20 +01:00
from svtplay_dl.service import Service, OpenGraphThumbMixin
2014-04-21 20:04:06 +02:00
from svtplay_dl.utils import get_http_data
from svtplay_dl.log import log
from svtplay_dl.fetcher.rtmp import RTMP
2014-05-01 16:52:05 +02:00
from svtplay_dl.fetcher.hds import hdsparse
2014-04-21 20:04:06 +02:00
from svtplay_dl.subtitle import subtitle_sami
2014-01-26 01:54:20 +01:00
class Viaplay(Service, OpenGraphThumbMixin):
supported_domains = [
'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']
def __init__(self, url):
Service.__init__(self, url)
self.subtitle = None
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.
"""
html_data = self.get_urldata()
match = re.search(r'data-emediate-video_id="([0-9]+)"', html_data)
if match:
return match.group(1)
parse = urlparse(self.url)
match = re.search(r'\/(\d+)/\?', parse.path)
if match:
return match.group(1)
return None
def get(self, options):
vid = self._get_video_id()
if vid is None:
log.error("Cant find video file")
sys.exit(2)
url = "http://viastream.viasat.tv/PlayProduct/%s" % vid
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
if xml.find("Product").find("Syndicate").text == "true":
options.live = True
2014-05-01 16:52:05 +02:00
filename = xml.find("Product").find("Videos").find("Video").find("Url").text
bitrate = xml.find("Product").find("Videos").find("Video").find("BitRate").text
2014-04-21 20:04:06 +02:00
yield subtitle_sami(xml.find("Product").find("SamiFile").text)
if filename[len(filename)-3:] == "f4m":
#fulhack. RTMP need live to be set
if xml.find("Product").find("Syndicate").text == "true":
options.live = False
manifest = "%s?hdcore=2.8.0&g=hejsan" % filename
streams = hdsparse(options, manifest)
for n in list(streams.keys()):
yield streams[n]
else:
if filename[:4] == "http":
data = get_http_data(filename)
xml = ET.XML(data)
filename = xml.find("Url").text
if xml.find("Msg").text:
log.error("Can't download file:")
log.error(xml.find("Msg").text)
sys.exit(2)
parse = urlparse(filename)
match = re.search("^(/[a-z0-9]{0,20})/(.*)", parse.path)
if not match:
log.error("Somthing wrong with rtmpparse")
sys.exit(2)
filename = "%s://%s:%s%s" % (parse.scheme, parse.hostname, parse.port, match.group(1))
path = "-y %s" % match.group(2)
options.other = "-W http://flvplayer.viastream.viasat.tv/flvplayer/play/swf/player.swf %s" % path
yield RTMP(options, filename, bitrate)
def find_all_episodes(self, options):
format_id = re.search(r'data-format-id="(\d+)"', self.get_urldata())
if not format_id:
log.error("Can't find video info")
sys.exit(2)
data = get_http_data("http://playapi.mtgx.tv/v1/sections?sections=videos.one,seasons.videolist&format=%s" % format_id.group(1))
jsondata = json.loads(data)
videos = jsondata["_embedded"]["sections"][1]["_embedded"]["seasons"][0]["_embedded"]["episodelist"]["_embedded"]["videos"]
return sorted(x["sharing"]["url"] for x in videos)