1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-12-03 00:24:21 +01:00
svtplay-dl/lib/svtplay_dl/service/picsearch.py

62 lines
2.6 KiB
Python
Raw Normal View History

# 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
from svtplay_dl.service import Service, OpenGraphThumbMixin
from svtplay_dl.fetcher.rtmp import RTMP
2014-12-08 23:07:02 +01:00
from svtplay_dl.fetcher.hds import hdsparse
from svtplay_dl.error import ServiceError
2015-09-15 20:10:32 +02:00
class Picsearch(Service, OpenGraphThumbMixin):
2015-08-31 23:46:17 +02:00
supported_domains = ['dn.se', 'mobil.dn.se', 'di.se']
def get(self):
data = self.get_urldata()
if self.exclude(self.options):
2015-09-06 23:04:48 +02:00
yield ServiceError("Excluding video")
return
2014-12-08 23:07:02 +01:00
ajax_auth = re.search(r"picsearch_ajax_auth = '(\w+)'", data)
if not ajax_auth:
2015-08-31 23:45:54 +02:00
ajax_auth = re.search(r'screen9-ajax-auth="([^"]+)"', data)
if not ajax_auth:
yield ServiceError("Cant find token for video")
2015-08-31 23:45:54 +02:00
return
mediaid = re.search(r"mediaId = '([^']+)';", self.get_urldata())
if not mediaid:
mediaid = re.search(r'media-id="([^"]+)"', self.get_urldata())
if not mediaid:
2015-08-31 23:45:54 +02:00
mediaid = re.search(r'screen9-mid="([^"]+)"', self.get_urldata())
if not mediaid:
yield ServiceError("Cant find media id")
2015-08-31 23:45:54 +02:00
return
jsondata = self.http.request("get", "http://csp.picsearch.com/rest?jsonp=&eventParam=1&auth=%s&method=embed&mediaid=%s" % (ajax_auth.group(1), mediaid.group(1))).text
jsondata = json.loads(jsondata)
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"]:
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-12-03 17:48:30 +01:00
for i in files:
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:
if playlist["provider"] != "rtmp":
if "live" in playlist:
self.options.live = playlist["live"]
if playlist["url"].endswith(".f4m"):
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]