1import re
2
3from streamlink.plugin import Plugin
4from streamlink.plugins.theplatform import ThePlatform
5from streamlink.utils import update_scheme
6
7
8class NBC(Plugin):
9    url_re = re.compile(r"https?://(?:www\.)?nbc\.com")
10    embed_url_re = re.compile(r'''(?P<q>["'])embedURL(?P=q)\s*:\s*(?P<q2>["'])(?P<url>.*?)(?P=q2)''')
11
12    @classmethod
13    def can_handle_url(cls, url):
14        return cls.url_re.match(url) is not None
15
16    def _get_streams(self):
17        res = self.session.http.get(self.url)
18        m = self.embed_url_re.search(res.text)
19        platform_url = m and m.group("url")
20
21        if platform_url:
22            url = update_scheme(self.url, platform_url)
23            # hand off to ThePlatform plugin
24            p = ThePlatform(url)
25            p.bind(self.session, "plugin.nbc")
26            return p.streams()
27
28
29__plugin__ = NBC
30