forked from streamlink/streamlink
/
mrtmk.py
53 lines (43 loc) · 1.53 KB
/
mrtmk.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
$description Live TV channels and video on-demand service from MRT, a North Macedonian public, state-owned broadcaster.
$url play.mrt.com.mk
$type live, vod
$region North Macedonia
"""
import logging
import re
from streamlink.plugin import Plugin, pluginmatcher
from streamlink.plugin.api import validate
from streamlink.stream.hls import HLSStream
log = logging.getLogger(__name__)
@pluginmatcher(re.compile(
r"https?://play\.mrt\.com\.mk/(live|play)/"
))
class MRTmk(Plugin):
file_re = re.compile(r"""(?P<url>https?://vod-[\d\w]+\.interspace\.com[^"',]+\.m3u8[^"',]*)""")
stream_schema = validate.Schema(
validate.all(
validate.transform(file_re.finditer),
validate.transform(list),
[validate.get("url")],
# remove duplicates
validate.transform(set),
validate.transform(list),
),
)
def _get_streams(self):
res = self.session.http.get(self.url)
stream_urls = self.stream_schema.validate(res.text)
log.debug("Found streams: {0}".format(len(stream_urls)))
if not stream_urls:
return
for stream_url in stream_urls:
try:
for s in HLSStream.parse_variant_playlist(self.session, stream_url).items():
yield s
except IOError as err:
if "403 Client Error" in str(err):
log.error("Failed to access stream, may be due to geo-restriction")
else:
raise err
__plugin__ = MRTmk