Esempio n. 1
0
    def _get_rtmp(self, data):
        self.logger.debug('_get_rtmp ...')

        app = filter_urlquery(data['application'],
                              new_dict={'media_token': data['media_token']})
        host = data['host']

        params = {
            'app': app,
            'flashVer': 'WIN 29,0,0,140',
            'swfUrl': 'https://live.fc2.com/swf/liveVideo.swf',
            'tcUrl': 'rtmp://{0}/{1}'.format(host, app),
            'live': 'yes',
            'pageUrl': self.url,
            'playpath': data['play_rtmp_stream'],
            'host': host,
        }
        yield 'live', RTMPStream(self.session, params)
Esempio n. 2
0
    def _get_hds_streams(self, channel):
        channel = self.hds_channel_remap.get(channel,
                                             "{0}live".format(channel))
        manifest_url = http.get(self.api_url.format(channel),
                                params={
                                    "getURL": 1
                                },
                                headers={
                                    "User-Agent": useragents.FIREFOX
                                }).text
        self.logger.debug("OLD HDS URL: {0}".format(manifest_url))
        manifest_url = filter_urlquery(manifest_url, ["hdnea"], True)
        self.logger.debug("NEW HDS URL: {0}".format(manifest_url))

        for s in HDSStream.parse_manifest(self.session,
                                          manifest_url,
                                          pvswf=self.swf_url,
                                          headers={
                                              "User-Agent": useragents.FIREFOX
                                          }).items():
            yield s
Esempio n. 3
0
    def _get_hls_streams(self, channel):
        channel = self.hls_channel_remap.get(channel, channel)
        embed_url = self.embed_url.format(channel)
        self.logger.debug("Found embed URL: {0}", embed_url)
        # page needs to have a mobile user agent
        embed_page = http.get(embed_url,
                              headers={"User-Agent": useragents.ANDROID})

        m = self.embed_re.search(embed_page.text)
        if m:
            hls_stream_url = m.group(1)
            self.logger.debug("OLD HLS URL: {0}".format(hls_stream_url))
            hls_stream_url = filter_urlquery(hls_stream_url, ["hdnea"], True)
            self.logger.debug("NEW HLS URL: {0}".format(hls_stream_url))

            try:
                for s in HLSStream.parse_variant_playlist(
                        self.session, hls_stream_url).items():
                    yield s
            except Exception:
                self.logger.error("Failed to load the HLS playlist for {0}",
                                  channel)
Esempio n. 4
0
    def _get_ws_url(self, user_id, version):
        self.logger.debug('_get_ws_url ...')
        data = {
            'channel_id': user_id,
            'channel_version': version,
            'client_type': 'pc',
            'client_app': 'browser'
        }

        res = http.post(self.url_server, data=data)
        w_data = http.json(res)
        if w_data['status'] == 11:
            raise PluginError('The broadcaster is currently not available')

        new_dict = {
            'control_token': w_data['control_token'],
            'mode': 'pay',
            'comment': '0',
        }
        ws_url = filter_urlquery(w_data['url'], new_dict=new_dict)
        self.logger.debug('WS URL: {0}'.format(ws_url))
        return ws_url
Esempio n. 5
0
 def test_filter_urlquery(self):
     test_data = [
         {
             "url":
             "http://example.com/z/manifest.f4m?hdnea=st=123~exp=123~acl=/*~hmac=123&n=20&b=496,896,1296,1896",
             "keys": ["hdnea"],
             "keys_status":
             False,
             "result":
             "http://example.com/z/manifest.f4m?n=20&b=496,896,1296,1896"
         },
         {
             "url":
             "http://example.com/i/master.m3u8?hdnea=st=123~exp=123~acl=/*~hmac=123&n=10&__b__=240&b=240,120,64,496,896,1296,1896",
             "keys": ["hdnea", "invalid"],
             "keys_status":
             False,
             "result":
             "http://example.com/i/master.m3u8?__b__=240&b=240,120,64,496,896,1296,1896&n=10"
         },
         {
             "url":
             "http://example.com/i/master.m3u8?hdnea=st=123~exp=123~acl=/*~hmac=123&n=10&__b__=240&b=240,120,64,496,896,1296,1896",
             "keys": ["invalid"],
             "keys_status":
             False,
             "result":
             "http://example.com/i/master.m3u8?hdnea=st=123~exp=123~acl=/*~hmac=123&n=10&__b__=240&b=240,120,64,496,896,1296,1896"
         },
         {
             "url":
             "http://example.com/z/manifest.f4m?hdnea=st=123~exp=123~acl=/*~hmac=123&n=20&b=496,896,1296,1896",
             "keys": ["n", "b"],
             "keys_status":
             False,
             "result":
             "http://example.com/z/manifest.f4m?hdnea=st=123~exp=123~acl=/*~hmac=123"
         },
         {
             "url":
             "http://example.com/z/manifest.f4m?hdnea=st=123~exp=123~acl=/*~hmac=123&n=20&b=496,896,1296,1896",
             "keys": ["hdnea"],
             "keys_status":
             True,
             "result":
             "http://example.com/z/manifest.f4m?hdnea=st=123~exp=123~acl=/*~hmac=123"
         },
         {
             "url":
             "http://example.com/i/master.m3u8?hdnea=st=123~exp=123~acl=/*~hmac=123&n=10&__b__=240&b=240,120,64,496,896,1296,1896",
             "keys": ["hdnea", "invalid"],
             "keys_status":
             True,
             "result":
             "http://example.com/i/master.m3u8?hdnea=st=123~exp=123~acl=/*~hmac=123"
         },
         {
             "url":
             "http://example.com/i/master.m3u8?hdnea=st=123~exp=123~acl=/*~hmac=123&n=10&__b__=240&b=240,120,64,496,896,1296,1896",
             "keys": ["invalid"],
             "keys_status": True,
             "result": "http://example.com/i/master.m3u8"
         },
         {
             "url":
             "http://example.com/z/manifest.f4m?hdnea=st=123~exp=123~acl=/*~hmac=123&n=20&b=496,896,1296,1896",
             "keys": ["hdnea"],
             "keys_status":
             False,
             "new_dict": {
                 "FOO": "BAR"
             },
             "result":
             "http://example.com/z/manifest.f4m?n=20&b=496,896,1296,1896&FOO=BAR"
         },
         {
             "url":
             "http://example.com/i/master.m3u8?hdnea=st=123~exp=123~acl=/*~hmac=123&n=10&__b__=240&b=240,120,64,496,896,1296,1896",
             "keys": ["invalid"],
             "keys_status": True,
             "new_dict": {
                 "FOO": "BAR"
             },
             "result": "http://example.com/i/master.m3u8?FOO=BAR"
         },
         {
             "url":
             "http://example.com/i/master.m3u8?hdnea=st=123~exp=123~acl=/*~hmac=123&n=10&__b__=240&b=240,120,64,496,896,1296,1896",
             "keys": ["invalid"],
             "keys_status": True,
             "new_dict": {
                 "FOO": "BAR",
                 "FOO2": "BAR2"
             },
             "result": "http://example.com/i/master.m3u8?FOO=BAR&FOO2=BAR2"
         },
     ]
     for test_dict in test_data:
         # new_url == result_url can't be tested because of different sorting sometimes
         # we will only test the parameters as a dict
         self.assertDictEqual(
             dict(parse_qsl(urlparse(test_dict["result"]).query)),
             dict(
                 parse_qsl(
                     urlparse(
                         filter_urlquery(test_dict["url"],
                                         test_dict["keys"],
                                         test_dict["keys_status"],
                                         test_dict.get("new_dict",
                                                       {}))).query)))
Esempio n. 6
0
 def test_filter_urlquery(self):
     test_data = [
         {
             "url":
             "http://example.com/z/manifest.f4m?hdnea=st=123~exp=123~acl=/*~hmac=123&n=20&b=496,896,1296,1896",
             "keys": ["hdnea"],
             "keys_status":
             False,
             "result":
             "http://example.com/z/manifest.f4m?n=20&b=496,896,1296,1896"
         },
         {
             "url":
             "http://example.com/i/master.m3u8?hdnea=st=123~exp=123~acl=/*~hmac=123&n=10&__b__=240&b=240,120,64,496,896,1296,1896",
             "keys": ["hdnea", "invalid"],
             "keys_status":
             False,
             "result":
             "http://example.com/i/master.m3u8?__b__=240&b=240,120,64,496,896,1296,1896&n=10"
         },
         {
             "url":
             "http://example.com/i/master.m3u8?hdnea=st=123~exp=123~acl=/*~hmac=123&n=10&__b__=240&b=240,120,64,496,896,1296,1896",
             "keys": ["invalid"],
             "keys_status":
             False,
             "result":
             "http://example.com/i/master.m3u8?hdnea=st=123~exp=123~acl=/*~hmac=123&n=10&__b__=240&b=240,120,64,496,896,1296,1896"
         },
         {
             "url":
             "http://example.com/z/manifest.f4m?hdnea=st=123~exp=123~acl=/*~hmac=123&n=20&b=496,896,1296,1896",
             "keys": ["n", "b"],
             "keys_status":
             False,
             "result":
             "http://example.com/z/manifest.f4m?hdnea=st=123~exp=123~acl=/*~hmac=123"
         },
         {
             "url":
             "http://example.com/z/manifest.f4m?hdnea=st=123~exp=123~acl=/*~hmac=123&n=20&b=496,896,1296,1896",
             "keys": ["hdnea"],
             "keys_status":
             True,
             "result":
             "http://example.com/z/manifest.f4m?hdnea=st=123~exp=123~acl=/*~hmac=123"
         },
         {
             "url":
             "http://example.com/i/master.m3u8?hdnea=st=123~exp=123~acl=/*~hmac=123&n=10&__b__=240&b=240,120,64,496,896,1296,1896",
             "keys": ["hdnea", "invalid"],
             "keys_status":
             True,
             "result":
             "http://example.com/i/master.m3u8?hdnea=st=123~exp=123~acl=/*~hmac=123"
         },
         {
             "url":
             "http://example.com/i/master.m3u8?hdnea=st=123~exp=123~acl=/*~hmac=123&n=10&__b__=240&b=240,120,64,496,896,1296,1896",
             "keys": ["invalid"],
             "keys_status": True,
             "result": "http://example.com/i/master.m3u8"
         },
     ]
     for test_dict in test_data:
         self.assertDictEqual(
             dict(parse_qsl(urlparse(test_dict["result"]).query)),
             dict(
                 parse_qsl(
                     urlparse(
                         filter_urlquery(test_dict["url"],
                                         test_dict["keys"],
                                         test_dict["keys_status"])).query)))