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 re
|
2014-03-25 20:21:52 +01:00
|
|
|
import json
|
2014-06-07 20:43:40 +02:00
|
|
|
import copy
|
2015-10-24 21:55:33 +02:00
|
|
|
import os
|
2013-02-12 19:43:37 +01:00
|
|
|
|
2015-10-24 21:55:33 +02:00
|
|
|
from svtplay_dl.utils import filenamify
|
2014-12-08 23:07:02 +01: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-17 19:55:19 +01:00
|
|
|
from svtplay_dl.log import log
|
2014-04-21 17:13:38 +02:00
|
|
|
from svtplay_dl.fetcher.rtmp import RTMP
|
2014-05-01 16:52:05 +02:00
|
|
|
from svtplay_dl.fetcher.hds import hdsparse
|
2015-10-24 21:55:33 +02:00
|
|
|
from svtplay_dl.fetcher.hls import hlsparse
|
2014-08-31 01:20:36 +02:00
|
|
|
from svtplay_dl.subtitle import subtitle
|
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-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',
|
2015-09-10 21:57:55 +02:00
|
|
|
'tv3play.ee', 'tv3play.lv', 'tv3play.lt', 'tvplay.lv', 'viagame.com',
|
|
|
|
'juicyplay.se']
|
2013-01-17 00:21:47 +01:00
|
|
|
|
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.
|
|
|
|
"""
|
2015-08-31 17:14:08 +02:00
|
|
|
html_data = self.get_urldata()
|
2014-06-22 22:46:00 +02:00
|
|
|
match = re.search(r'data-video-id="([0-9]+)"', html_data)
|
2014-06-26 22:04:16 +02:00
|
|
|
if match:
|
|
|
|
return match.group(1)
|
|
|
|
match = re.search(r'data-videoid="([0-9]+)', html_data)
|
2014-03-09 15:56:00 +01:00
|
|
|
if match:
|
|
|
|
return match.group(1)
|
|
|
|
|
2014-06-02 22:13:11 +02:00
|
|
|
parse = urlparse(self.url)
|
2014-09-11 23:45:08 +02:00
|
|
|
match = re.search(r'/\w+/(\d+)', parse.path)
|
2015-09-10 21:57:55 +02:00
|
|
|
if match:
|
|
|
|
return match.group(1)
|
|
|
|
match = re.search('iframe src="http://play.juicyplay.se[^\"]+id=(\d+)', html_data)
|
2014-03-09 15:56:00 +01:00
|
|
|
if match:
|
|
|
|
return match.group(1)
|
|
|
|
return None
|
|
|
|
|
2015-12-26 11:46:14 +01:00
|
|
|
def get(self):
|
2014-12-08 23:07:02 +01:00
|
|
|
vid = self._get_video_id()
|
2014-03-09 15:56:00 +01:00
|
|
|
if vid is None:
|
2015-09-06 14:19:10 +02:00
|
|
|
yield ServiceError("Can't find video file for: %s" % self.url)
|
2014-10-06 23:21:43 +02:00
|
|
|
return
|
2014-03-09 15:56:00 +01:00
|
|
|
|
2014-10-23 00:03:14 +02:00
|
|
|
url = "http://playapi.mtgx.tv/v3/videos/%s" % vid
|
2015-12-26 11:46:14 +01:00
|
|
|
self.options.other = ""
|
2015-08-31 19:45:15 +02:00
|
|
|
data = self.http.request("get", url)
|
2015-08-30 00:06:20 +02:00
|
|
|
if data.status_code == 403:
|
2015-09-06 14:19:10 +02:00
|
|
|
yield ServiceError("Can't play this because the video is geoblocked.")
|
2014-11-01 21:10:06 +01:00
|
|
|
return
|
2015-08-31 23:18:37 +02:00
|
|
|
dataj = json.loads(data.text)
|
2014-10-23 00:03:14 +02:00
|
|
|
if "msg" in dataj:
|
2015-09-06 14:19:10 +02:00
|
|
|
yield ServiceError(dataj["msg"])
|
2014-09-11 23:51:32 +02:00
|
|
|
return
|
2014-08-11 19:44:20 +02:00
|
|
|
|
2014-10-23 00:03:14 +02:00
|
|
|
if dataj["type"] == "live":
|
2015-12-26 11:46:14 +01:00
|
|
|
self.options.live = True
|
2014-10-23 00:03:14 +02:00
|
|
|
|
2015-12-26 11:46:14 +01:00
|
|
|
if self.exclude(self.options):
|
2015-09-06 23:04:48 +02:00
|
|
|
yield ServiceError("Excluding video")
|
2014-12-22 17:41:40 +01:00
|
|
|
return
|
|
|
|
|
2014-10-23 00:03:14 +02:00
|
|
|
if dataj["sami_path"]:
|
2015-12-26 11:46:14 +01:00
|
|
|
yield subtitle(copy.copy(self.options), "sami", dataj["sami_path"])
|
2014-12-22 15:30:23 +01:00
|
|
|
if dataj["subtitles_for_hearing_impaired"]:
|
2015-12-26 11:46:14 +01:00
|
|
|
yield subtitle(copy.copy(self.options), "sami", dataj["subtitles_for_hearing_impaired"])
|
2014-12-08 23:07:02 +01:00
|
|
|
|
2015-08-31 19:45:15 +02:00
|
|
|
streams = self.http.request("get", "http://playapi.mtgx.tv/v3/videos/stream/%s" % vid)
|
2015-08-30 00:06:20 +02:00
|
|
|
if streams.status_code == 403:
|
2015-09-06 14:19:10 +02:00
|
|
|
yield ServiceError("Can't play this because the video is geoblocked.")
|
2014-11-01 21:10:06 +01:00
|
|
|
return
|
2015-08-31 23:18:37 +02:00
|
|
|
streamj = json.loads(streams.text)
|
2014-06-26 21:52:32 +02:00
|
|
|
|
2014-10-23 00:03:14 +02:00
|
|
|
if "msg" in streamj:
|
2015-09-06 14:19:10 +02:00
|
|
|
yield ServiceError("Can't play this because the video is either not found or geoblocked.")
|
2014-10-23 00:03:14 +02:00
|
|
|
return
|
|
|
|
|
2015-12-26 11:46:14 +01:00
|
|
|
if self.options.output_auto:
|
|
|
|
directory = os.path.dirname(self.options.output)
|
|
|
|
self.options.service = "tv3play"
|
2015-10-24 21:55:33 +02:00
|
|
|
basename = self._autoname(dataj)
|
2015-12-26 11:46:14 +01:00
|
|
|
title = "%s-%s-%s" % (basename, vid, self.options.service)
|
2015-10-24 21:55:33 +02:00
|
|
|
if len(directory):
|
2015-12-26 11:46:14 +01:00
|
|
|
self.options.output = os.path.join(directory, title)
|
2015-10-24 21:55:33 +02:00
|
|
|
else:
|
2015-12-26 11:46:14 +01:00
|
|
|
self.options.output = title
|
2015-10-24 21:55:33 +02:00
|
|
|
|
2014-06-26 21:52:32 +02:00
|
|
|
if streamj["streams"]["medium"]:
|
|
|
|
filename = streamj["streams"]["medium"]
|
2015-09-10 21:38:29 +02:00
|
|
|
if ".f4m" in filename:
|
2015-12-26 11:46:14 +01:00
|
|
|
streams = hdsparse(self.options, self.http.request("get", filename, params={"hdcore": "3.7.0"}), filename)
|
2014-10-12 23:31:02 +02:00
|
|
|
if streams:
|
|
|
|
for n in list(streams.keys()):
|
|
|
|
yield streams[n]
|
2014-06-26 21:52:32 +02:00
|
|
|
else:
|
|
|
|
parse = urlparse(filename)
|
2014-08-27 15:13:57 +02:00
|
|
|
match = re.search("^(/[^/]+)/(.*)", parse.path)
|
2014-06-26 21:52:32 +02:00
|
|
|
if not match:
|
2015-09-06 14:19:10 +02:00
|
|
|
yield ServiceError("Can't get rtmpparse info")
|
2014-11-25 21:46:33 +01:00
|
|
|
return
|
2014-06-26 21:52:32 +02:00
|
|
|
filename = "%s://%s:%s%s" % (parse.scheme, parse.hostname, parse.port, match.group(1))
|
|
|
|
path = "-y %s" % match.group(2)
|
2015-12-26 11:46:14 +01:00
|
|
|
self.options.other = "-W http://flvplayer.viastream.viasat.tv/flvplayer/play/swf/player.swf %s" % path
|
|
|
|
yield RTMP(copy.copy(self.options), filename, 800)
|
2014-05-01 17:04:08 +02:00
|
|
|
|
2014-06-26 21:52:32 +02:00
|
|
|
if streamj["streams"]["hls"]:
|
2015-12-26 11:46:14 +01:00
|
|
|
streams = hlsparse(self.options, self.http.request("get", streamj["streams"]["hls"]), streamj["streams"]["hls"])
|
2015-01-16 21:18:54 +01:00
|
|
|
if streams:
|
|
|
|
for n in list(streams.keys()):
|
2015-10-04 14:37:16 +02:00
|
|
|
yield streams[n]
|
2014-01-11 23:02:47 +01:00
|
|
|
|
2014-03-25 20:21:52 +01:00
|
|
|
def find_all_episodes(self, options):
|
2015-08-31 17:14:08 +02:00
|
|
|
format_id = re.search(r'data-format-id="(\d+)"', self.get_urldata())
|
2014-03-25 20:21:52 +01:00
|
|
|
if not format_id:
|
2014-11-25 21:46:33 +01:00
|
|
|
log.error("Can't find video info for all episodes")
|
|
|
|
return
|
2015-09-01 23:52:00 +02:00
|
|
|
data = self.http.request("get", "http://playapi.mtgx.tv/v1/sections?sections=videos.one,seasons.videolist&format=%s" % format_id.group(1)).text
|
2014-03-25 20:21:52 +01:00
|
|
|
jsondata = json.loads(data)
|
|
|
|
videos = jsondata["_embedded"]["sections"][1]["_embedded"]["seasons"][0]["_embedded"]["episodelist"]["_embedded"]["videos"]
|
|
|
|
|
2014-12-26 02:04:29 +01:00
|
|
|
n = 0
|
2014-12-21 13:28:46 +01:00
|
|
|
episodes = []
|
|
|
|
for i in videos:
|
|
|
|
if n == options.all_last:
|
|
|
|
break
|
|
|
|
episodes.append(i["sharing"]["url"])
|
|
|
|
n += 1
|
|
|
|
return episodes
|
2015-10-24 21:55:33 +02:00
|
|
|
|
|
|
|
def _autoname(self, dataj):
|
|
|
|
program = dataj["format_slug"]
|
|
|
|
season = dataj["format_position"]["season"]
|
|
|
|
episode = None
|
|
|
|
if season:
|
|
|
|
if len(dataj["format_position"]["episode"]) > 0:
|
|
|
|
episode = dataj["format_position"]["episode"]
|
|
|
|
name = filenamify(program)
|
|
|
|
if season:
|
|
|
|
name = "%s.s%s" % (name, season)
|
|
|
|
if episode:
|
|
|
|
name = "%se%s" % (name, episode)
|
|
|
|
return name
|