forked from streamlink/streamlink
/
olympicchannel.py
71 lines (62 loc) · 2.17 KB
/
olympicchannel.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
65
66
67
68
69
70
71
"""
$description Live TV channel and video on-demand service run by the International Olympic Committee.
$url olympicchannel.com
$url olympics.com
$type live, vod
$notes Only non-premium content is available
"""
import logging
import re
from time import time
from streamlink.compat import urljoin, urlparse
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?://(\w+\.)?(?:olympics|olympicchannel)\.com/(?:[\w-]+/)?../.+"
))
class OlympicChannel(Plugin):
def _get_streams(self):
data = self.session.http.get(self.url, schema=validate.Schema(
validate.parse_html(),
validate.union((
validate.xml_xpath_string(".//*[@data-content-url][1]/@data-content-url"),
validate.xml_xpath_string(".//*[@data-d3vp-plugin='THEOplayer'][@data-content][1]/@data-content"),
)),
))
if not data:
return
api_url, api_data = data
api_schema = validate.Schema(
validate.parse_json(),
[{
validate.optional("src"): validate.url(),
validate.optional("srcType"): "HLS",
}],
validate.get((0, "src")),
)
if api_data:
stream_url = api_schema.validate(api_data)
else:
stream_url = self.session.http.get(
urljoin(self.url, api_url),
headers={"Referer": self.url},
schema=api_schema,
)
parsed = urlparse(stream_url)
stream_url = self.session.http.get(
urljoin(self.url, "/tokenGenerator"),
params={
"url": stream_url,
"domain": "{0}://{1}".format(parsed.scheme, parsed.netloc),
"_ts": int(time()),
},
headers={"Referer": self.url},
schema=validate.Schema(
validate.parse_json(),
validate.url(),
),
)
return HLSStream.parse_variant_playlist(self.session, stream_url)
__plugin__ = OlympicChannel