Esempio n. 1
0
    def test_can_handle_url(self):
        should_match = [
            "https://www.youtube.com/EXAMPLE/live",
            "https://www.youtube.com/c/EXAMPLE",
            "https://www.youtube.com/c/EXAMPLE/",
            "https://www.youtube.com/c/EXAMPLE/live",
            "https://www.youtube.com/c/EXAMPLE/live/",
            "https://www.youtube.com/channel/EXAMPLE",
            "https://www.youtube.com/channel/EXAMPLE/",
            "https://www.youtube.com/embed/aqz-KE-bpKQ",
            "https://www.youtube.com/embed/live_stream?channel=UCNye-wNBqNL5ZzHSJj3l8Bg",
            "https://www.youtube.com/user/EXAMPLE",
            "https://www.youtube.com/user/EXAMPLE/",
            "https://www.youtube.com/user/EXAMPLE/live",
            "https://www.youtube.com/v/aqz-KE-bpKQ",
            "https://www.youtube.com/watch?v=aqz-KE-bpKQ",
        ]
        for url in should_match:
            self.assertTrue(YouTube.can_handle_url(url), url)

        should_not_match = [
            "https://accounts.google.com/",
            "https://www.youtube.com",
            "https://www.youtube.com/account",
            "https://www.youtube.com/feed/guide_builder",
            "https://www.youtube.com/t/terms",
        ]
        for url in should_not_match:
            self.assertFalse(YouTube.can_handle_url(url), url)
Esempio n. 2
0
    def _get_streams(self):
        res = self.session.http.get(self.url)

        # Look for Youtube embedded video first
        for iframe in itertags(res.text, 'iframe'):
            if YouTube.can_handle_url(iframe.attributes.get("src")):
                log.debug("Handing off to YouTube plugin")
                return self.session.streams(iframe.attributes.get("src"))

        # Next check for HLS URL with token
        mobile_url_m = self.mobile_url_re.search(res.text)
        mobile_url = mobile_url_m and update_scheme(self.url,
                                                    mobile_url_m.group("url"))
        if mobile_url:
            log.debug("Found mobile stream: {0}".format(mobile_url_m.group(0)))

            token = mobile_url_m and mobile_url_m.group("token")
            if not token and "kralmuzik" in self.url:
                log.debug("Getting Kral Muzik HLS stream token from API")
                token = self.session.http.get(self.kral_token_url).text
            elif not token:
                # if no token is in the url, try to find it else where in the page
                log.debug("Searching for HLS stream token in URL")
                token_m = self.token_re.search(res.text)
                token = token_m and token_m.group("token")

            return HLSStream.parse_variant_playlist(
                self.session,
                mobile_url + token,
                headers={"Referer": self.url})
Esempio n. 3
0
    def test_can_handle_url(self):
        should_match = [
            "https://www.youtube.com/c/EXAMPLE/live",
            "https://www.youtube.com/channel/EXAMPLE",
            "https://www.youtube.com/v/aqz-KE-bpKQ",
            "https://www.youtube.com/embed/aqz-KE-bpKQ",
            "https://www.youtube.com/user/EXAMPLE/",
            "https://www.youtube.com/watch?v=aqz-KE-bpKQ",
        ]
        for url in should_match:
            self.assertTrue(YouTube.can_handle_url(url))

        should_not_match = [
            "https://www.youtube.com",
        ]
        for url in should_not_match:
            self.assertFalse(YouTube.can_handle_url(url))
Esempio n. 4
0
def test_translate_url(url, expected):
    Plugin.bind(Mock(), "tests.plugins.test_youtube")
    assert YouTube(url).url == expected
Esempio n. 5
0
def test_match_url(url, group, expected):
    YouTube.bind(Mock(), "tests.plugins.test_youtube")
    plugin = YouTube(url)
    assert plugin.match is not None
    assert plugin.match.group(group) == expected