1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-24 12:15:40 +01:00
svtplay-dl/lib/svtplay_dl/service/lemonwhale.py

52 lines
1.8 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
2014-06-07 20:43:40 +02:00
import copy
import json
from svtplay_dl.utils.urllib import unquote_plus
from svtplay_dl.service import Service
from svtplay_dl.error import ServiceError
from svtplay_dl.fetcher.hls import hlsparse
from svtplay_dl.utils import decode_html_entities
2015-09-15 20:10:32 +02:00
class Lemonwhale(Service):
supported_domains = ['svd.se']
def get(self):
vid = None
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
match = re.search(r'video url-([^"]+)', data)
if not match:
match = re.search(r'embed.jsp\?([^"]+)"', self.get_urldata())
if not match:
yield ServiceError("Can't find video id")
2014-10-06 23:21:43 +02:00
return
vid = match.group(1)
if not vid:
path = unquote_plus(match.group(1))
data = self.http.request("get", "http://www.svd.se%s" % path).content
match = re.search(r'embed.jsp\?([^"]+)', data)
if not match:
yield ServiceError("Can't find video id")
2014-10-06 23:21:43 +02:00
return
vid = match.group(1)
url = "http://ljsp.lwcdn.com/web/public/item.json?type=video&%s" % decode_html_entities(vid)
data = self.http.request("get", url).text
jdata = json.loads(data)
videos = jdata["videos"][0]["media"]["streams"]
for i in videos:
if i["name"] == "auto":
hls = "%s%s" % (jdata["videos"][0]["media"]["base"], i["url"])
streams = hlsparse(self.options, self.http.request("get", hls), hls)
if streams:
for n in list(streams.keys()):
yield streams[n]