Example #1
0
    def test_post_api_info(self, mock_http):
        API_INFO = Garena.API_INFO
        schema = Garena._info_schema

        api_data = {
            "reply": {
                "channel_id": 358220,
            },
            "result": "success"
        }

        api_resp = Mock()
        api_resp.text = json.dumps(api_data)
        mock_http.post.return_value = api_resp
        mock_http.json.return_value = api_data

        payload = {"alias": "LOLTW"}

        plugin = Garena("https://garena.live/LOLTW")

        info_data = plugin._post_api(API_INFO, payload, schema)

        self.assertEqual(info_data["channel_id"], 358220)

        mock_http.post.assert_called_with(API_INFO, json=dict(alias="LOLTW"))
Example #2
0
    def test_post_api_stream(self, mock_http):
        API_STREAM = Garena.API_STREAM
        schema = Garena._stream_schema

        api_data = {
            "reply": {
                "streams": [
                    {
                        "url": "https://test.se/stream1",
                        "bitrate": 0,
                        "resolution": 1080,
                        "format": 3
                    },
                ]
            },
            "result": "success"
        }

        api_resp = Mock()
        api_resp.text = json.dumps(api_data)
        mock_http.post.return_value = api_resp
        mock_http.json.return_value = api_data

        payload = {"channel_id": 358220}

        plugin = Garena("https://garena.live/358220")

        stream_data = plugin._post_api(API_STREAM, payload, schema)

        self.assertEqual(stream_data["streams"], api_data["reply"]["streams"])

        mock_http.post.assert_called_with(API_STREAM,
                                          json=dict(channel_id=358220))
Example #3
0
    def test_get_streams(self, hlsstream, mock_get_stream_data):
        mock_get_stream_data.return_value = {
            "stream": "http://test.se/stream1"
        }

        page_resp = Mock()
        page_resp.text = u"""
                    <div class="video-js theoplayer-skin theo-seekbar-above-controls content-box vjs-fluid"
                 data-resource= "bbcone"
                 data-token = "1324567894561268987948596154656418448489159"
                                    data-content-type="live"
                    data-environment="live"
                    data-subscription="free"
                    data-channel-id="89">
                <div id="channel-info" class="channel-info">
                    <div class="row visible-xs visible-sm">
        """

        self.session.http.get.return_value = page_resp
        hlsstream.parse_variant_playlist.return_value = {"test": HLSStream(self.session, "http://test.se/stream1")}

        TVPlayer.bind(self.session, "test.tvplayer")
        plugin = TVPlayer("http://tvplayer.com/watch/dave")

        streams = plugin.streams()

        self.assertTrue("test" in streams)

        # test the url is used correctly
        self.session.http.get.assert_called_with("http://tvplayer.com/watch/dave")
        # test that the correct API call is made
        mock_get_stream_data.assert_called_with(resource="bbcone", channel_id="89", token="1324567894561268987948596154656418448489159")
        # test that the correct URL is used for the HLSStream
        hlsstream.parse_variant_playlist.assert_called_with(ANY, "http://test.se/stream1")
Example #4
0
    def test_post_api_stream(self):
        API_STREAM = Garena.API_STREAM
        schema = Garena._stream_schema

        api_data = {
            "reply": {
                "streams": [
                    {
                        "url": "https://test.se/stream1",
                        "bitrate": 0,
                        "resolution": 1080,
                        "format": 3
                    },
                ]
            },
            "result": "success"
        }

        api_resp = Mock()
        api_resp.text = json.dumps(api_data)
        self.session.http.post.return_value = api_resp
        self.session.http.json.return_value = api_data

        payload = {"channel_id": 358220}

        Garena.bind(self.session, "test.garena")
        plugin = Garena("https://garena.live/358220")

        stream_data = plugin._post_api(API_STREAM, payload, schema)

        self.assertEqual(stream_data["streams"], api_data["reply"]["streams"])

        self.session.http.post.assert_called_with(API_STREAM, json=dict(channel_id=358220))
Example #5
0
    def test_post_api_info(self):
        API_INFO = Garena.API_INFO
        schema = Garena._info_schema

        api_data = {
            "reply": {
                "channel_id": 358220,
            },
            "result": "success"
        }

        api_resp = Mock()
        api_resp.text = json.dumps(api_data)
        self.session.http.post.return_value = api_resp
        self.session.http.json.return_value = api_data

        payload = {"alias": "LOLTW"}

        Garena.bind(self.session, "test.garena")
        plugin = Garena("https://garena.live/LOLTW")

        info_data = plugin._post_api(API_INFO, payload, schema)

        self.assertEqual(info_data["channel_id"], 358220)

        self.session.http.post.assert_called_with(API_INFO, json=dict(alias="LOLTW"))
Example #6
0
    def test_get_streams(self, hlsstream, mock_get_stream_data):
        mock_get_stream_data.return_value = {
            "response": {
                "stream": "http://test.se/stream1",
                "drm": None
            }
        }

        page_resp = Mock()
        page_resp.text = u"""
            <div class="col-xs-12">
                <div id="live-player-root"
                    data-player-library="videojs"
                    data-player-id="ILWxqLKV91Ql8kF"
                    data-player-key="2Pw1Eg0Px3Gy9Jm3Ry8Ar5Bi5Vc5Nk"
                    data-player-uvid="139"
                    data-player-token="275c808a685a09d6e36d0253ab3765af"
                    data-player-expiry="1531958189"
                    data-player-poster=""
                    data-requested-channel-id="139"
                    data-play-button="/assets/tvplayer/images/dist/play-button-epg.svg"
                    data-update-url="/now-ajax"
                    data-timezone-name="Europe/London"
                    data-thumb-link-classes=""
                    data-theme-name="tvplayer"
                    data-base-entitlements="%5B%22free%22%5D"
                    data-has-identity="0"
                    data-require-identity-to-watch-free="1"
                    data-stream-type="live"
                    data-live-route="/watch/%25live_channel_id%25"
                >
                </div>
            </div>
        """

        self.session.http.get.return_value = page_resp
        hlsstream.parse_variant_playlist.return_value = {
            "test": HLSStream(self.session, "http://test.se/stream1")
        }

        TVPlayer.bind(self.session, "test.tvplayer")
        plugin = TVPlayer("http://tvplayer.com/watch/dave")

        streams = plugin.streams()

        self.assertTrue("test" in streams)

        # test the url is used correctly
        self.session.http.get.assert_called_with(
            "http://tvplayer.com/watch/dave")
        # test that the correct API call is made
        mock_get_stream_data.assert_called_with(
            expiry="1531958189",
            key="2Pw1Eg0Px3Gy9Jm3Ry8Ar5Bi5Vc5Nk",
            token="275c808a685a09d6e36d0253ab3765af",
            uvid="139")
        # test that the correct URL is used for the HLSStream
        hlsstream.parse_variant_playlist.assert_called_with(
            ANY, "http://test.se/stream1")
Example #7
0
    def test_get_invalid_page(self):
        page_resp = Mock()
        page_resp.text = u"""
        var validate = "foo";
        var resourceId = "1234";
        """
        self.session.http.get.return_value = page_resp

        TVPlayer.bind(self.session, "test.tvplayer")
        plugin = TVPlayer("http://tvplayer.com/watch/dave")

        streams = plugin.streams()

        self.assertEqual({}, streams)

        # test the url is used correctly

        self.session.http.get.assert_called_with("http://tvplayer.com/watch/dave")
Example #8
0
    def test_get_invalid_page(self):
        page_resp = Mock()
        page_resp.text = u"""
            var validate = "foo";
            var resourceId = "1234";
        """
        self.session.http.get.return_value = page_resp

        TVPlayer.bind(self.session, "test.tvplayer")
        plugin = TVPlayer("http://tvplayer.com/watch/dave")

        streams = plugin.streams()

        self.assertEqual({}, streams)

        # test the url is used correctly

        self.session.http.get.assert_called_with(
            "http://tvplayer.com/watch/dave")
Example #9
0
    def test_get_streams(self, hlsstream, mock_get_stream_data):
        mock_get_stream_data.return_value = {
            "stream": "http://test.se/stream1"
        }

        page_resp = Mock()
        page_resp.text = u"""
                    <div class="video-js theoplayer-skin theo-seekbar-above-controls content-box vjs-fluid"
                 data-resource= "bbcone"
                 data-token = "1324567894561268987948596154656418448489159"
                                    data-content-type="live"
                    data-environment="live"
                    data-subscription="free"
                    data-channel-id="89">
                <div id="channel-info" class="channel-info">
                    <div class="row visible-xs visible-sm">
        """

        self.session.http.get.return_value = page_resp
        hlsstream.parse_variant_playlist.return_value = {
            "test": HLSStream(self.session, "http://test.se/stream1")
        }

        TVPlayer.bind(self.session, "test.tvplayer")
        plugin = TVPlayer("http://tvplayer.com/watch/dave")

        streams = plugin.get_streams()

        self.assertTrue("test" in streams)

        # test the url is used correctly
        self.session.http.get.assert_called_with(
            "http://tvplayer.com/watch/dave")
        # test that the correct API call is made
        mock_get_stream_data.assert_called_with(
            resource="bbcone",
            channel_id="89",
            token="1324567894561268987948596154656418448489159")
        # test that the correct URL is used for the HLSStream
        hlsstream.parse_variant_playlist.assert_called_with(
            ANY, "http://test.se/stream1")