forked from streamlink/streamlink
/
wetter.py
64 lines (55 loc) · 2.02 KB
/
wetter.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
54
55
56
57
58
59
60
61
62
63
64
"""
$url wetter.com
$type live, vod
"""
import logging
import re
from streamlink.plugin import Plugin, pluginmatcher
from streamlink.plugin.api import validate
from streamlink.stream import HLSStream, HTTPStream, RTMPStream
log = logging.getLogger(__name__)
@pluginmatcher(re.compile(
r"https?://(?:www\.)?wetter\.com/"
))
class Wetter(Plugin):
_videourl_re = re.compile(r'data-video-url-(hls|rtmp|endpoint|mp4)\s*=\s*"(.+)"')
_stream_schema = validate.Schema(
validate.transform(_videourl_re.findall),
validate.transform(lambda vl: [{"stream-type": v[0], "url": v[1]} for v in vl]),
[
{
"stream-type": validate.text,
"url": validate.url(),
}
],
)
_endpoint_schema = validate.Schema(
[
{
validate.optional("label"): validate.text,
"type": "video/mp4",
"file": validate.url(scheme="http"),
}
],
)
def _get_streams(self):
streams = self.session.http.get(self.url, schema=self._stream_schema)
for stream in streams:
if stream["stream-type"] == "hls":
streams = HLSStream.parse_variant_playlist(self.session, stream["url"]).items()
if streams:
for s in streams:
yield s
else:
yield "live", HLSStream(self.session, stream["url"])
elif stream["stream-type"] == "rtmp":
yield "0_live", RTMPStream(self.session, {"rtmp": stream["url"]})
elif stream["stream-type"] == "endpoint":
res = self.session.http.get(stream["url"])
files = self.session.http.json(res, schema=self._endpoint_schema)
for f in files:
s = HTTPStream(self.session, f["file"])
yield "vod", s
elif stream["stream-type"] == "mp4":
yield "vod", HTTPStream(self.session, stream["url"])
__plugin__ = Wetter