def test_file_stream_path(session):
    stream = FileStream(session, "/path/to/file")
    assert stream.to_url() == "/path/to/file"
    with pytest.raises(TypeError) as cm:
        stream.to_manifest_url()
    assert str(
        cm.value
    ) == "<FileStream [file]> cannot be translated to a manifest URL"
def test_file_stream_handle(session):
    stream = FileStream(session, None, Mock())
    with pytest.raises(TypeError) as cm:
        stream.to_url()
    assert str(cm.value) == "<FileStream [file]> cannot be translated to a URL"
    with pytest.raises(TypeError) as cm:
        stream.to_manifest_url()
    assert str(
        cm.value
    ) == "<FileStream [file]> cannot be translated to a manifest URL"
Example #3
0
    def _get_streams(self):
        page = http.get(self.url, schema=_schema)
        if not page:
            return

        pubkey_pem = get_public_key(self.cache, urljoin(self.url, page["clientlibs"]))
        if not pubkey_pem:
            raise PluginError("Unable to get public key")

        flashvars = page["flashvars"]

        params = {
            "cashPath": int(time.time() * 1000)
        }
        res = http.get(urljoin(self.url, flashvars["country"]), params=params)
        if not res:
            return
        language = http.xml(res, schema=_language_schema)

        api_params = {}
        for key in ("ss_id", "mv_id", "device_cd", "ss1_prm", "ss2_prm", "ss3_prm"):
            if flashvars.get(key, ""):
                api_params[key] = flashvars[key]

        aeskey = number.long_to_bytes(random.getrandbits(8 * 32), 32)

        params = {
            "s": flashvars["s"],
            "c": language,
            "e": self.url,
            "d": aes_encrypt(aeskey, json.dumps(api_params)),
            "a": rsa_encrypt(pubkey_pem, aeskey)
        }
        res = http.get(urljoin(self.url, flashvars["init"]), params=params)
        if not res:
            return
        rtn = http.json(res, schema=_init_schema)
        if not rtn:
            return

        init_data = parse_json(aes_decrypt(aeskey, rtn))

        parsed = urlparse(init_data["play_url"])
        if parsed.scheme != "https" or not parsed.path.startswith("/i/") or not parsed.path.endswith("/master.m3u8"):
            return
        hlsstream_url = init_data["play_url"]

        streams = HLSStream.parse_variant_playlist(self.session, hlsstream_url)

        if "caption_url" in init_data:
            if self.get_option("mux_subtitles") and FFMPEGMuxer.is_usable(self.session):
                res = http.get(init_data["caption_url"])
                srt = http.xml(res, ignore_ns=True, schema=_xml_to_srt_schema)
                subfiles = []
                metadata = {}
                for i, lang, srt in ((i, s[0], s[1]) for i, s in enumerate(srt)):
                    subfile = tempfile.TemporaryFile()
                    subfile.write(srt.encode("utf8"))
                    subfile.seek(0)
                    subfiles.append(FileStream(self.session, fileobj=subfile))
                    metadata["s:s:{0}".format(i)] = ["language={0}".format(lang)]

                for n, s in streams.items():
                    yield n, MuxedStream(self.session, s, *subfiles,
                                         maps=list(range(0, len(metadata) + 1)),
                                         metadata=metadata)
                return
            else:
                self.logger.info("Subtitles: {0}".format(init_data["caption_url"]))

        for s in streams.items():
            yield s
Example #4
0
 def test_open_fileobj(self):
     fileobj = Mock()
     s = FileStream(self.session, fileobj=fileobj)
     self.assertEqual(fileobj, s.open())
Example #5
0
 def test_open_file_path(self):
     m = mock_open()
     s = FileStream(self.session, path="/test/path")
     with patch('streamlink.stream.file.open', m, create=True):
         s.open()
         m.assert_called_with("/test/path")
Example #6
0
def test_file_stream_handle(session):
    stream = FileStream(session, None, Mock())
    assert stream.__json__() == {
        "type": "file",
    }
Example #7
0
def test_file_stream_path(session):
    stream = FileStream(session, "/path/to/file")
    assert stream.__json__() == {
        "type": "file",
        "path": "/path/to/file",
    }
 def test_open_fileobj(self):
     fileobj = Mock()
     s = FileStream(self.session, fileobj=fileobj)
     self.assertEqual(fileobj, s.open())
 def test_open_file_path(self):
     m = mock_open()
     s = FileStream(self.session, path="/test/path")
     with patch('streamlink.stream.file.open', m, create=True):
         s.open()
         m.assert_called_with("/test/path")