1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-28 14:14:15 +01:00
svtplay-dl/lib/svtplay_dl/service/picsearch.py

54 lines
2.2 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
2014-12-08 23:07:02 +01:00
from svtplay_dl.utils import get_http_data
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.log import log
class Picsearch(Service, OpenGraphThumbMixin):
supported_domains = ['dn.se', 'mobil.dn.se']
def get(self, options):
2014-12-08 23:07:02 +01:00
error, data = self.get_urldata()
if error:
2014-11-26 15:59:57 +01:00
log.error("Can't get the page.")
return
2014-12-08 23:07:02 +01:00
ajax_auth = re.search(r"picsearch_ajax_auth = '(\w+)'", data)
if not ajax_auth:
2014-03-31 19:15:40 +02:00
log.error("Cant find token for video")
2014-10-06 23:21:43 +02:00
return
2014-12-08 23:07:02 +01:00
mediaid = re.search(r"mediaId = '([^']+)';", self.get_urldata()[1])
if not mediaid:
2014-12-08 23:07:02 +01:00
mediaid = re.search(r'media-id="([^"]+)"', self.get_urldata()[1])
if not mediaid:
log.error("Cant find media id")
2014-10-06 23:21:43 +02:00
return
2014-12-08 23:07:02 +01:00
error, jsondata = get_http_data("http://csp.picsearch.com/rest?jsonp=&eventParam=1&auth=%s&method=embed&mediaid=%s" % (ajax_auth.group(1), mediaid.group(1)))
if error:
log.error("Cant get stream info")
return
jsondata = json.loads(jsondata)
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:
options.other = "-y '%s'" % i["url"]
yield RTMP(copy.copy(options), server, i["height"])
if "provider" in playlist:
if playlist["provider"] != "rtmp":
if "live" in playlist:
options.live = playlist["live"]
if playlist["url"].endswith(".f4m"):
streams = hdsparse(copy.copy(options), playlist["url"])
if streams:
for n in list(streams.keys()):
yield streams[n]