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 -*-
|
2017-10-17 19:56:20 +02:00
|
|
|
from __future__ import absolute_import, unicode_literals
|
2013-02-12 19:43:37 +01:00
|
|
|
import re
|
2014-04-03 19:52:51 +02:00
|
|
|
import json
|
2018-01-15 00:37:18 +01:00
|
|
|
from datetime import datetime, timedelta
|
2018-06-24 16:15:55 +02:00
|
|
|
from urllib.parse import urlparse
|
2013-02-12 19:43:37 +01:00
|
|
|
|
2014-01-19 14:26:48 +01:00
|
|
|
from svtplay_dl.service import Service, OpenGraphThumbMixin
|
2015-10-04 14:37:16 +02:00
|
|
|
from svtplay_dl.fetcher.hls import hlsparse
|
2015-09-06 14:19:10 +02:00
|
|
|
from svtplay_dl.error import ServiceError
|
2013-02-12 19:43:37 +01:00
|
|
|
|
2015-09-15 20:10:32 +02:00
|
|
|
|
2014-01-19 14:26:48 +01:00
|
|
|
class Tv4play(Service, OpenGraphThumbMixin):
|
2018-06-24 16:15:55 +02:00
|
|
|
supported_domains = ['tv4play.se']
|
2013-01-17 00:21:47 +01:00
|
|
|
|
2015-12-26 11:46:14 +01:00
|
|
|
def get(self):
|
2018-01-15 00:37:18 +01:00
|
|
|
parse = urlparse(self.url)
|
|
|
|
if parse.path[:8] == "/kanaler":
|
2018-03-24 18:43:05 +01:00
|
|
|
end_time_stamp = (datetime.utcnow() - timedelta(minutes=1, seconds=20)).replace(microsecond=0)
|
2018-01-15 22:16:07 +01:00
|
|
|
start_time_stamp = end_time_stamp - timedelta(minutes=1)
|
2018-01-15 00:37:18 +01:00
|
|
|
|
2018-01-30 20:11:37 +01:00
|
|
|
url = "https://bbr-l2v.akamaized.net/live/{0}/master.m3u8?in={1}&out={2}?".format(parse.path[9:],
|
|
|
|
start_time_stamp.isoformat(),
|
|
|
|
end_time_stamp.isoformat())
|
2018-01-15 22:16:07 +01:00
|
|
|
|
2018-05-13 13:06:45 +02:00
|
|
|
self.config.set("live", True)
|
2018-05-22 00:03:14 +02:00
|
|
|
streams = hlsparse(self.config, self.http.request("get", url), url, output=self.output, hls_time_stamp=True)
|
2018-05-08 22:48:55 +02:00
|
|
|
for n in list(streams.keys()):
|
|
|
|
yield streams[n]
|
2018-01-15 00:37:18 +01:00
|
|
|
return
|
|
|
|
|
2018-06-24 16:15:55 +02:00
|
|
|
match = self._getjson()
|
|
|
|
if not match:
|
|
|
|
yield ServiceError("Can't find json data")
|
2015-01-20 13:10:35 +01:00
|
|
|
return
|
2013-01-17 00:21:47 +01:00
|
|
|
|
2018-06-24 16:15:55 +02:00
|
|
|
jansson = json.loads(match.group(1))
|
|
|
|
vid = None
|
|
|
|
for i in jansson:
|
|
|
|
janson2 = json.loads(i["data"])
|
|
|
|
json.dumps(janson2)
|
|
|
|
if "videoAsset" in janson2["data"]:
|
|
|
|
vid = janson2["data"]["videoAsset"]["id"]
|
|
|
|
if janson2["data"]["videoAsset"]["is_drm_protected"]:
|
|
|
|
yield ServiceError("We can't download DRM protected content from this site.")
|
|
|
|
return
|
|
|
|
if janson2["data"]["videoAsset"]["is_live"]:
|
|
|
|
self.config.set("live", True)
|
|
|
|
if janson2["data"]["videoAsset"]["season"] > 0:
|
|
|
|
self.output["season"] = janson2["data"]["videoAsset"]["season"]
|
|
|
|
if janson2["data"]["videoAsset"]["episode"] > 0:
|
|
|
|
self.output["episode"] = janson2["data"]["videoAsset"]["episode"]
|
|
|
|
self.output["title"] = janson2["data"]["videoAsset"]["program"]["name"]
|
|
|
|
self.output["episodename"] = janson2["data"]["videoAsset"]["title"]
|
|
|
|
vid = str(vid)
|
|
|
|
self.output["id"] = str(vid)
|
|
|
|
if "program" in janson2["data"] and vid is None:
|
|
|
|
if "contentfulPanels" in janson2["data"]["program"]:
|
|
|
|
match = re.search(r"[\/-](\d+)$", self.url)
|
|
|
|
if match and "panels" in janson2["data"]["program"]:
|
|
|
|
for n in janson2["data"]["program"]["panels"]:
|
|
|
|
for z in n["videoList"]["videoAssets"]:
|
|
|
|
if z["id"] == int(match.group(1)):
|
|
|
|
vid = z["id"]
|
|
|
|
self.output["id"] = str(vid)
|
|
|
|
self.output["episodename"] = z["title"]
|
|
|
|
self.output["title"] = z["program"]["name"]
|
|
|
|
|
|
|
|
if vid is None:
|
|
|
|
yield ServiceError("Cant find video id for the video")
|
2016-03-27 13:02:49 +02:00
|
|
|
return
|
2014-08-27 22:58:37 +02:00
|
|
|
|
2018-06-24 16:15:55 +02:00
|
|
|
url = "https://playback-api.b17g.net/media/{}?service=tv4&device=browser&protocol=hls%2Cdash&drm=widevine".format(vid)
|
|
|
|
res = self.http.request("get", url, cookies=self.cookies)
|
2018-09-23 21:32:02 +02:00
|
|
|
if res.status_code > 200:
|
2018-10-28 16:37:58 +01:00
|
|
|
yield ServiceError("Can't play this because the video is geoblocked or not available.")
|
2018-09-23 21:32:02 +02:00
|
|
|
return
|
2018-06-24 16:15:55 +02:00
|
|
|
if res.json()["playbackItem"]["type"] == "hls":
|
|
|
|
streams = hlsparse(self.config, self.http.request("get", res.json()["playbackItem"]["manifestUrl"]),
|
2018-07-05 01:26:33 +02:00
|
|
|
res.json()["playbackItem"]["manifestUrl"], output=self.output, httpobject=self.http)
|
2018-06-24 16:15:55 +02:00
|
|
|
for n in list(streams.keys()):
|
|
|
|
yield streams[n]
|
2014-08-27 22:58:37 +02:00
|
|
|
|
2018-06-24 16:15:55 +02:00
|
|
|
def _getjson(self):
|
2018-10-28 23:16:00 +01:00
|
|
|
match = re.search(r".prefetched = (\[.*\]);", self.get_urldata())
|
2018-06-24 16:15:55 +02:00
|
|
|
return match
|
2016-04-30 14:10:43 +02:00
|
|
|
|
2018-05-13 13:06:45 +02:00
|
|
|
def find_all_episodes(self, config):
|
2014-04-03 19:52:51 +02:00
|
|
|
episodes = []
|
2018-06-24 16:15:55 +02:00
|
|
|
items = []
|
|
|
|
show = None
|
|
|
|
match = self._getjson()
|
|
|
|
jansson = json.loads(match.group(1))
|
|
|
|
for i in jansson:
|
|
|
|
janson2 = json.loads(i["data"])
|
|
|
|
if "program" in janson2["data"]:
|
2018-09-23 20:05:36 +02:00
|
|
|
if "programPanels" in janson2["data"]["program"]:
|
|
|
|
for n in janson2["data"]["program"]["programPanels"]["panels"]:
|
2018-08-18 14:13:29 +02:00
|
|
|
if n.get("assetType", None) == "EPISODE":
|
2018-06-24 16:15:55 +02:00
|
|
|
for z in n["videoList"]["videoAssets"]:
|
|
|
|
show = z["program_nid"]
|
|
|
|
items.append(z["id"])
|
2018-08-18 14:13:29 +02:00
|
|
|
if n.get("assetType", None) == "CLIP" and config.get("include_clips"):
|
2018-06-24 16:15:55 +02:00
|
|
|
for z in n["videoList"]["videoAssets"]:
|
|
|
|
show = z["program_nid"]
|
|
|
|
items.append(z["id"])
|
|
|
|
|
|
|
|
items = sorted(items)
|
|
|
|
for item in items:
|
|
|
|
episodes.append("https://www.tv4play.se/program/{}/{}".format(show, item))
|
|
|
|
|
|
|
|
if config.get("all_last") > 0:
|
|
|
|
return episodes[-config.get("all_last"):]
|
2014-12-21 12:27:16 +01:00
|
|
|
return episodes
|
2015-01-20 13:10:35 +01:00
|
|
|
|
2015-09-15 20:10:32 +02:00
|
|
|
|
2018-06-24 16:15:55 +02:00
|
|
|
class Tv4(Service, OpenGraphThumbMixin):
|
|
|
|
supported_domains = ['tv4.se']
|
|
|
|
|
|
|
|
def get(self):
|
|
|
|
match = re.search(r"[\/-](\d+)$", self.url)
|
|
|
|
if not match:
|
|
|
|
yield ServiceError("Cant find video id")
|
|
|
|
return
|
|
|
|
self.output["id"] = match.group(1)
|
|
|
|
|
|
|
|
match = re.search("data-program-format='([^']+)'", self.get_urldata())
|
|
|
|
if not match:
|
|
|
|
yield ServiceError("Cant find program name")
|
|
|
|
return
|
|
|
|
self.output["title"] = match.group(1)
|
|
|
|
|
|
|
|
match = re.search('img alt="([^"]+)" class="video-image responsive"', self.get_urldata())
|
|
|
|
if not match:
|
|
|
|
yield ServiceError("Cant find title of the video")
|
|
|
|
return
|
|
|
|
self.output["episodename"] = match.group(1)
|
|
|
|
|
|
|
|
url = "https://playback-api.b17g.net/media/{}?service=tv4&device=browser&protocol=hls%2Cdash&drm=widevine".format(self.output["id"])
|
|
|
|
res = self.http.request("get", url, cookies=self.cookies)
|
2018-09-23 21:32:02 +02:00
|
|
|
if res.status_code > 200:
|
|
|
|
yield ServiceError("Can't play this because the video is geoblocked.")
|
|
|
|
return
|
2018-06-24 16:15:55 +02:00
|
|
|
if res.json()["playbackItem"]["type"] == "hls":
|
|
|
|
streams = hlsparse(self.config, self.http.request("get", res.json()["playbackItem"]["manifestUrl"]),
|
|
|
|
res.json()["playbackItem"]["manifestUrl"], output=self.output)
|
|
|
|
for n in list(streams.keys()):
|
|
|
|
yield streams[n]
|