2017-02-18 21:13:01 +01:00
|
|
|
import json
|
2019-08-25 00:40:39 +02:00
|
|
|
import re
|
2018-01-30 22:07:21 +01:00
|
|
|
from urllib.parse import urljoin
|
2017-02-18 21:13:01 +01:00
|
|
|
|
|
|
|
from svtplay_dl.error import ServiceError
|
2019-08-25 00:40:39 +02:00
|
|
|
from svtplay_dl.fetcher.hls import hlsparse
|
|
|
|
from svtplay_dl.service import OpenGraphThumbMixin
|
|
|
|
from svtplay_dl.service import Service
|
2017-02-18 21:13:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
class NHL(Service, OpenGraphThumbMixin):
|
2019-08-25 00:27:31 +02:00
|
|
|
supported_domains = ["nhl.com"]
|
2017-02-18 21:13:01 +01:00
|
|
|
|
|
|
|
def get(self):
|
2018-10-28 23:16:00 +01:00
|
|
|
match = re.search(r"var initialMedia\s+= ({[^;]+);", self.get_urldata())
|
2017-02-18 21:13:01 +01:00
|
|
|
if not match:
|
|
|
|
yield ServiceError("Cant find any media on that page")
|
|
|
|
return
|
|
|
|
janson = json.loads(match.group(1))
|
2017-02-18 23:51:58 +01:00
|
|
|
vid = janson["content_id"]
|
|
|
|
if not janson["metaData"]:
|
|
|
|
yield ServiceError("Can't find video on that page")
|
|
|
|
return
|
2017-02-18 21:13:01 +01:00
|
|
|
if "playbacks" in janson["metaData"]:
|
|
|
|
for i in janson["metaData"]["playbacks"]:
|
|
|
|
if "CLOUD" in i["name"]:
|
2019-09-06 22:49:49 +02:00
|
|
|
streams = hlsparse(self.config, self.http.request("get", i["url"]), i["url"])
|
2017-02-18 21:13:01 +01:00
|
|
|
if streams:
|
|
|
|
for n in list(streams.keys()):
|
|
|
|
yield streams[n]
|
|
|
|
else:
|
2018-10-28 23:16:00 +01:00
|
|
|
match = re.search(r"var mediaConfig\s+= ({[^;]+);", self.get_urldata())
|
2017-02-18 23:51:58 +01:00
|
|
|
if not match:
|
|
|
|
yield ServiceError("Cant find any media on that page")
|
|
|
|
return
|
|
|
|
janson = json.loads(match.group(1))
|
|
|
|
try:
|
|
|
|
apiurl = janson["vpm"]["mediaFramework"]["mediaFrameworkDomain"]
|
|
|
|
except KeyError:
|
|
|
|
yield ServiceError("Can't find api url")
|
|
|
|
return
|
2019-09-06 22:49:49 +02:00
|
|
|
filename = "{}?contentId={}&playbackScenario=HTTP_CLOUD_WIRED_WEB&format=json&platform=WEB_MEDIAPLAYER" "&_=1487455224334".format(
|
|
|
|
janson["vpm"]["mediaFramework"]["mediaFrameworkEndPoint"], vid
|
2019-08-25 00:27:31 +02:00
|
|
|
)
|
2017-02-18 23:51:58 +01:00
|
|
|
url = urljoin(apiurl, filename)
|
|
|
|
res = self.http.get(url)
|
|
|
|
janson = res.json()
|
2019-09-06 22:49:49 +02:00
|
|
|
for i in janson["user_verified_event"][0]["user_verified_content"][0]["user_verified_media_item"]:
|
|
|
|
streams = hlsparse(self.config, self.http.request("get", i["url"]), i["url"], output=self.output)
|
2018-05-08 22:48:55 +02:00
|
|
|
for n in list(streams.keys()):
|
|
|
|
yield streams[n]
|