Skip to content

Instantly share code, notes, and snippets.

@urnenfeld
Created January 5, 2018 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save urnenfeld/b1d9787893f285a9eee93b89385156ad to your computer and use it in GitHub Desktop.
Save urnenfeld/b1d9787893f285a9eee93b89385156ad to your computer and use it in GitHub Desktop.
mitele.py.patch
--- mitele_original.py 2018-01-05 23:21:58.722024388 +0100
+++ mitele.py 2018-01-05 23:40:09.456352460 +0100
@@ -16,6 +16,8 @@
_url_re = re.compile(r"https?://(?:www\.)?mitele\.es/directo/(?P<channel>\w+)")
_suffix_re = re.compile(r"""acl=(?P<path>[^"'*]+)""")
+ _channel_domains = {"energy": "https://mdslivehls-i.akamaihd.net", "cuatro": "https://livehlsdai-i.akamaihd.net"}
+
pdata_url = "http://indalo.mediaset.es/mmc-player/api/mmc/v1/{channel}/live/flash.json"
gate_url = "http://gatekeeper.mediaset.es"
@@ -41,7 +43,9 @@
@classmethod
def can_handle_url(cls, url):
- return cls._url_re.match(url) is not None
+ channel_wanted = cls._url_re.match(url).group("channel")
+ return cls._url_re.match(url) is not None and channel_wanted in cls._channel_domains.keys()
+
def get_pdata(self, channel):
"""
@@ -52,7 +56,7 @@
res = http.get(self.pdata_url.format(channel=channel))
return parse_json(res.text, schema=self.pdata_schema)
- def get_stream_url(self, data):
+ def get_stream_url(self, data, domain):
"""
Get the hls_url from the post request
:param data: dict with "gcp" and "ogn"
@@ -72,7 +76,7 @@
m = self._suffix_re.search(suffix)
if m:
self.logger.info("Might not work, only suffix - try to create a url.")
- domain = "https://mdslivehls-i.akamaihd.net"
+
path = m.group("path")
path_suffix = "master.m3u8?{suffix}".format(suffix=suffix)
hls_url = urljoin(domain, path)
@@ -85,7 +89,7 @@
channel = self._url_re.match(self.url).group("channel")
pdata = self.get_pdata(channel)
- hls_url = self.get_stream_url(pdata)
+ hls_url = self.get_stream_url(pdata, self._channel_domains[channel])
if hls_url:
for s in HLSStream.parse_variant_playlist(self.session, hls_url, headers=self.headers).items():
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment