2014-03-25 15:37:41 +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 re
|
|
|
|
import json
|
2014-06-07 20:43:40 +02:00
|
|
|
import copy
|
2014-03-25 15:37:41 +01:00
|
|
|
|
|
|
|
from svtplay_dl.service import Service, OpenGraphThumbMixin
|
2014-04-21 18:24:43 +02:00
|
|
|
from svtplay_dl.fetcher.rtmp import RTMP
|
2014-12-08 23:07:02 +01:00
|
|
|
from svtplay_dl.fetcher.hds import hdsparse
|
2016-04-19 21:08:17 +02:00
|
|
|
from svtplay_dl.fetcher.hls import hlsparse
|
2015-09-06 14:19:10 +02:00
|
|
|
from svtplay_dl.error import ServiceError
|
2016-03-16 22:50:43 +01:00
|
|
|
from svtplay_dl.utils.urllib import urlparse
|
2014-03-25 15:37:41 +01:00
|
|
|
|
2015-09-15 20:10:32 +02:00
|
|
|
|
2014-03-25 15:37:41 +01:00
|
|
|
class Picsearch(Service, OpenGraphThumbMixin):
|
2016-03-20 18:20:19 +01:00
|
|
|
supported_domains = ['dn.se', 'mobil.dn.se', 'di.se', 'csp.picsearch.com', 'csp.screen9.com']
|
2014-03-25 15:37:41 +01:00
|
|
|
|
2015-12-26 11:46:14 +01:00
|
|
|
def get(self):
|
2016-05-14 22:54:30 +02:00
|
|
|
if self.exclude():
|
2015-09-06 23:04:48 +02:00
|
|
|
yield ServiceError("Excluding video")
|
2014-12-22 17:41:40 +01:00
|
|
|
return
|
|
|
|
|
2016-03-16 22:50:43 +01:00
|
|
|
ajax_auth = self.get_auth()
|
2014-03-25 15:37:41 +01:00
|
|
|
if not ajax_auth:
|
2016-03-16 22:50:43 +01:00
|
|
|
yield ServiceError("Cant find token for video")
|
|
|
|
return
|
|
|
|
|
|
|
|
mediaid = self.get_mediaid()
|
2014-03-25 15:37:41 +01:00
|
|
|
if not mediaid:
|
2016-03-16 22:50:43 +01:00
|
|
|
yield ServiceError("Cant find media id")
|
|
|
|
return
|
|
|
|
if not isinstance(mediaid, str):
|
|
|
|
mediaid = mediaid.group(1)
|
|
|
|
|
|
|
|
jsondata = self.http.request("get", "http://csp.picsearch.com/rest?jsonp=&eventParam=1&auth=%s&method=embed&mediaid=%s" % (ajax_auth.group(1), mediaid)).text
|
2014-03-25 15:37:41 +01:00
|
|
|
jsondata = json.loads(jsondata)
|
2015-11-15 09:23:35 +01:00
|
|
|
if "playerconfig" not in jsondata["media"]:
|
|
|
|
yield ServiceError(jsondata["error"])
|
|
|
|
return
|
2015-11-26 19:16:14 +01:00
|
|
|
if "live" in jsondata["media"]["playerconfig"]["clip"]:
|
2015-12-26 11:46:14 +01:00
|
|
|
self.options.live = jsondata["media"]["playerconfig"]["clip"]
|
2014-12-03 17:48:30 +01:00
|
|
|
playlist = jsondata["media"]["playerconfig"]["playlist"][1]
|
|
|
|
if "bitrates" in playlist:
|
|
|
|
files = playlist["bitrates"]
|
|
|
|
server = jsondata["media"]["playerconfig"]["plugins"]["bwcheck"]["netConnectionUrl"]
|
2014-03-25 15:37:41 +01:00
|
|
|
|
2014-12-03 17:48:30 +01:00
|
|
|
for i in files:
|
2015-12-26 11:46:14 +01:00
|
|
|
self.options.other = "-y '%s'" % i["url"]
|
|
|
|
yield RTMP(copy.copy(self.options), server, i["height"])
|
2014-12-03 17:48:30 +01:00
|
|
|
if "provider" in playlist:
|
2014-12-17 21:06:08 +01:00
|
|
|
if playlist["provider"] != "rtmp":
|
|
|
|
if "live" in playlist:
|
2015-12-26 11:46:14 +01:00
|
|
|
self.options.live = playlist["live"]
|
2014-12-17 21:06:08 +01:00
|
|
|
if playlist["url"].endswith(".f4m"):
|
2015-12-26 11:46:14 +01:00
|
|
|
streams = hdsparse(self.options, self.http.request("get", playlist["url"], params={"hdcore": "3.7.0"}), playlist["url"])
|
2014-12-22 10:15:24 +01:00
|
|
|
if streams:
|
|
|
|
for n in list(streams.keys()):
|
|
|
|
yield streams[n]
|
2016-04-19 21:08:17 +02:00
|
|
|
if ".m3u8" in playlist["url"]:
|
|
|
|
streams = hlsparse(self.options, self.http.request("get", playlist["url"]), playlist["url"])
|
|
|
|
if streams:
|
|
|
|
for n in list(streams.keys()):
|
|
|
|
yield streams[n]
|
2016-03-16 22:50:43 +01:00
|
|
|
|
|
|
|
def get_auth(self):
|
|
|
|
match = re.search(r"picsearch_ajax_auth[ ]*=[ ]*['\"]([^'\"]+)['\"]", self.get_urldata())
|
|
|
|
if not match:
|
|
|
|
match = re.search(r'screen9-ajax-auth="([^"]+)"', self.get_urldata())
|
2016-04-19 21:08:17 +02:00
|
|
|
if not match:
|
|
|
|
match = re.search('screen9"[ ]*:[ ]*"([^"]+)"', self.get_urldata())
|
2016-03-16 22:50:43 +01:00
|
|
|
if not match:
|
|
|
|
match = re.search('s.src="(https://csp-ssl.picsearch.com[^"]+|http://csp.picsearch.com/rest[^"]+)', self.get_urldata())
|
|
|
|
if match:
|
|
|
|
data = self.http.request("get", match.group(1))
|
|
|
|
match = re.search(r'ajaxAuth": "([^"]+)"', data.text)
|
2016-03-20 18:20:19 +01:00
|
|
|
if not match:
|
|
|
|
match = re.search('iframe src="(//csp.screen9.com[^"]+)"', self.get_urldata())
|
|
|
|
if match:
|
|
|
|
url = "http:%s" % match.group(1)
|
|
|
|
data = self.http.request("get", url)
|
|
|
|
match = re.search(r"picsearch_ajax_auth = '([^']+)'", data.text)
|
|
|
|
|
2016-03-16 22:50:43 +01:00
|
|
|
return match
|
|
|
|
|
|
|
|
def get_mediaid(self):
|
|
|
|
match = re.search(r"mediaId = '([^']+)';", self.get_urldata())
|
|
|
|
if not match:
|
|
|
|
match = re.search(r'media-id="([^"]+)"', self.get_urldata())
|
|
|
|
if not match:
|
|
|
|
match = re.search(r'screen9-mid="([^"]+)"', self.get_urldata())
|
2016-04-19 21:08:17 +02:00
|
|
|
if not match:
|
|
|
|
match = re.search(r'data-id="([^"]+)"', self.get_urldata())
|
2016-03-16 22:50:43 +01:00
|
|
|
if not match:
|
|
|
|
match = re.search('s.src="(https://csp-ssl.picsearch.com[^"]+|http://csp.picsearch.com/rest[^"]+)', self.get_urldata())
|
|
|
|
if match:
|
|
|
|
data = self.http.request("get", match.group(1))
|
|
|
|
match = re.search(r'mediaid": "([^"]+)"', data.text)
|
2016-03-20 18:20:19 +01:00
|
|
|
if not match:
|
|
|
|
match = re.search('iframe src="(//csp.screen9.com[^"]+)"', self.get_urldata())
|
|
|
|
if match:
|
|
|
|
url = "http:%s" % match.group(1)
|
|
|
|
data = self.http.request("get", url)
|
|
|
|
match = re.search(r"mediaid: '([^']+)'", data.text)
|
2016-03-16 22:50:43 +01:00
|
|
|
if not match:
|
|
|
|
urlp = urlparse(self.url)
|
|
|
|
match = urlp.fragment
|
|
|
|
return match
|