1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-24 20:25:41 +01:00
svtplay-dl/lib/svtplay_dl/service/tv4play.py

92 lines
3.4 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 xml.etree.ElementTree as ET
2014-04-03 19:52:51 +02:00
import json
2014-04-03 19:52:51 +02:00
from svtplay_dl.utils.urllib import urlparse, parse_qs, quote_plus
from svtplay_dl.service import Service, OpenGraphThumbMixin
2013-12-30 01:35:08 +01:00
from svtplay_dl.utils import get_http_data, select_quality, subtitle_smi, is_py2_old
from svtplay_dl.log import log
from svtplay_dl.fetcher.rtmp import RTMP
from svtplay_dl.fetcher.hds import HDS
class Tv4play(Service, OpenGraphThumbMixin):
supported_domains = ['tv4play.se', 'tv4.se']
def __init__(self, url):
Service.__init__(self, url)
self.subtitle = None
2014-01-06 23:14:06 +01:00
def get(self, options):
parse = urlparse(self.url)
if "tv4play.se" in self.url:
try:
vid = parse_qs(parse[4])["video_id"][0]
except KeyError:
log.error("Can't find video file")
sys.exit(2)
else:
2014-01-06 23:14:06 +01:00
match = re.search(r"-(\d+)$", self.url)
if match:
vid = match.group(1)
else:
match = re.search(r"\"vid\":\"(\d+)\",", self.get_urldata())
if match:
vid = match.group(1)
else:
log.error("Can't find video file")
sys.exit(2)
url = "http://premium.tv4play.se/api/web/asset/%s/play" % vid
data = get_http_data(url)
xml = ET.XML(data)
ss = xml.find("items")
2013-12-30 01:35:08 +01:00
if is_py2_old:
sa = list(ss.getiterator("item"))
else:
sa = list(ss.iter("item"))
if xml.find("live").text:
if xml.find("live").text != "false":
options.live = True
for i in sa:
2013-11-17 13:32:33 +01:00
if i.find("mediaFormat").text == "mp4":
base = i.find("base").text
if base[0:4] == "rtmp":
swf = "http://www.tv4play.se/flash/tv4playflashlets.swf"
options.other = "-W %s -y %s" % (swf, test["path"])
yield RTMP(options, i.find("base").text, i.find("bitrate").text)
elif base[len(base)-3:len(base)] == "f4m":
manifest = "%s?hdcore=2.8.0&g=hejsan" % i.find("url").text
yield HDS(options, manifest, "0")
2013-03-10 13:55:34 +01:00
elif i.find("mediaFormat").text == "smi":
self.subtitle = i.find("url").text
if options.subtitle and options.force_subtitle:
return
def get_subtitle(self, options):
if self.subtitle:
data = get_http_data(self.subtitle)
subtitle_smi(options, data)
2014-04-03 19:52:51 +02:00
def find_all_episodes(self, options):
parse = urlparse(self.url)
show = quote_plus(parse.path[parse.path.find("/", 1)+1:])
data = get_http_data("http://webapi.tv4play.se/play/video_assets?type=episode&is_live=false&platform=web&node_nids=%s&per_page=99999" % show)
jsondata = json.loads(data)
episodes = []
for i in jsondata["results"]:
try:
days = int(i["availability"]["availability_group_free"])
except ValueError:
days = 999
if days > 0:
id = i["id"]
url = "http://www.tv4play.se/program/%s?video_id=%s" % (show, id)
episodes.append(url)
return sorted(episodes)