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/nhl.py

55 lines
2.3 KiB
Python
Raw Normal View History

2017-02-18 21:13:01 +01:00
from __future__ import absolute_import
import re
import json
2018-01-30 22:07:21 +01:00
from urllib.parse import urljoin
2017-02-18 21:13:01 +01:00
from svtplay_dl.service import Service, OpenGraphThumbMixin
from svtplay_dl.fetcher.hls import hlsparse
from svtplay_dl.error import ServiceError
class NHL(Service, OpenGraphThumbMixin):
supported_domains = ['nhl.com']
def get(self):
if self.exclude():
yield ServiceError("Excluding video")
return
match = re.search("var initialMedia\s+= ({[^;]+);", self.get_urldata())
if not match:
yield ServiceError("Cant find any media on that page")
return
janson = json.loads(match.group(1))
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"]:
streams = hlsparse(self.options, self.http.request("get", i["url"]), i["url"])
if streams:
for n in list(streams.keys()):
yield streams[n]
else:
match = re.search("var mediaConfig\s+= ({[^;]+);", self.get_urldata())
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
2018-01-30 23:10:22 +01:00
filename = "{0}?contentId={1}&playbackScenario=HTTP_CLOUD_WIRED_WEB&format=json&platform=WEB_MEDIAPLAYER" \
"&_=1487455224334".format(janson["vpm"]["mediaFramework"]["mediaFrameworkEndPoint"], vid)
url = urljoin(apiurl, filename)
res = self.http.get(url)
janson = res.json()
for i in janson["user_verified_event"][0]["user_verified_content"][0]["user_verified_media_item"]:
streams = hlsparse(self.options, self.http.request("get", i["url"]), i["url"])
if streams:
for n in list(streams.keys()):
yield streams[n]