1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-27 21:54:17 +01:00
svtplay-dl/lib/svtplay_dl/service/disney.py

88 lines
3.9 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 -*-
2019-08-25 00:40:39 +02:00
import copy
import json
import re
2018-01-30 22:07:21 +01:00
from urllib.parse import urlparse
2019-08-25 00:40:39 +02:00
from svtplay_dl.error import ServiceError
from svtplay_dl.fetcher.hls import hlsparse
from svtplay_dl.fetcher.http import HTTP
2019-08-25 00:40:39 +02:00
from svtplay_dl.service import OpenGraphThumbMixin
from svtplay_dl.service import Service
2015-09-15 20:10:32 +02:00
class Disney(Service, OpenGraphThumbMixin):
2019-08-25 00:27:31 +02:00
supported_domains = ["disney.se", "video.disney.se", "disneyjunior.disney.se"]
def get(self):
parse = urlparse(self.url)
2021-12-18 21:37:09 +01:00
if parse.hostname in ("video.disney.se", "disneyjunior.disney.se"):
data = self.get_urldata()
2014-12-08 23:07:02 +01:00
match = re.search(r"Grill.burger=({.*}):", data)
if not match:
yield ServiceError("Can't find video info")
return
jsondata = json.loads(match.group(1))
for n in jsondata["stack"]:
if len(n["data"]) > 0:
for x in n["data"]:
if "flavors" in x:
for i in x["flavors"]:
if i["format"] == "mp4":
res = self.http.get(i["url"])
match = re.search('button primary" href="([^"]+)"', res.text)
if match:
yield HTTP(copy.copy(self.config), match.group(1), i["bitrate"], output=self.output)
else:
data = self.get_urldata()
2014-12-08 23:07:02 +01:00
match = re.search(r"uniqueId : '([^']+)'", data)
if not match:
yield ServiceError("Can't find video info")
return
uniq = match.group(1)
match = re.search("entryId : '([^']+)'", self.get_urldata())
entryid = match.group(1)
match = re.search("partnerId : '([^']+)'", self.get_urldata())
partnerid = match.group(1)
match = re.search("uiConfId : '([^']+)'", self.get_urldata())
uiconfid = match.group(1)
match = re.search("json : ({.*}}),", self.get_urldata())
jsondata = json.loads(match.group(1))
parse = urlparse(self.url)
if len(parse.fragment) > 0:
2019-08-25 00:27:31 +02:00
entry = parse.fragment[parse.fragment.rindex("/") + 1 :]
if entry in jsondata["idlist"]:
entryid = jsondata["idlist"][entry]
else:
yield ServiceError("Cant find video info")
return
2018-05-13 13:06:45 +02:00
for i in jsondata["playlists"][0]["playlist"]:
if entryid in i["id"]:
title = i["longId"]
break
self.output["title"] = title
2019-08-25 00:27:31 +02:00
url = (
2021-12-18 19:52:08 +01:00
f"http://cdnapi.kaltura.com/html5/html5lib/v1.9.7.6/mwEmbedFrame.php?&wid={partnerid}&"
f"uiconf_id={uiconfid}&entry_id={entryid}&playerId={uniq}&forceMobileHTML5=true&urid=1.9.7.6&callback=mwi"
2019-08-25 00:27:31 +02:00
)
data = self.http.request("get", url).text
2014-11-09 02:15:43 +01:00
match = re.search(r"mwi\(({.*})\);", data)
jsondata = json.loads(match.group(1))
data = jsondata["content"]
2014-11-09 02:15:43 +01:00
match = re.search(r"window.kalturaIframePackageData = ({.*});", data)
jsondata = json.loads(match.group(1))
ks = jsondata["enviornmentConfig"]["ks"]
2018-05-13 13:06:45 +02:00
name = jsondata["entryResult"]["meta"]["name"]
self.output["title"] = name
2019-08-25 00:27:31 +02:00
url = (
2021-12-18 19:52:08 +01:00
f"http://cdnapi.kaltura.com/p/{partnerid[1:]}/sp/{partnerid[1:]}00/playManifest/entryId/{entryid}"
f"/format/applehttp/protocol/http/a.m3u8?ks={ks}&referrer=aHR0cDovL3d3dy5kaXNuZXkuc2U=&"
2019-08-25 00:27:31 +02:00
)
2021-12-18 19:52:08 +01:00
redirect = self.http.check_redirect(url)
yield from hlsparse(self.config, self.http.request("get", redirect), redirect, output=self.output)