Esempio n. 1
0
    def _supports_param(self, param, timeout=5.0):
        try:
            rtmpdump = self.spawn(dict(help=True),
                                  timeout=timeout,
                                  stderr=subprocess.PIPE)
        except StreamError as err:
            raise StreamError(
                "Error while checking rtmpdump compatibility: {0}".format(
                    err.message))

        for line in rtmpdump.stderr.readlines():
            m = re.match(r"^--(\w+)", str(line, "ascii"))

            if not m:
                continue

            if m.group(1) == param:
                return True

        return False
Esempio n. 2
0
    def _update_redirect(self, stderr):
        tcurl, redirect = None, None
        stderr = str(stderr, "utf8")

        m = re.search(
            r"DEBUG: Property: <Name:\s+redirect,\s+STRING:\s+(\w+://.+?)>",
            stderr)
        if m:
            redirect = m.group(1)

        if redirect:
            self.logger.debug("Found redirect tcUrl: {0}", redirect)

            if "rtmp" in self.parameters:
                tcurl, playpath = rtmpparse(self.parameters["rtmp"])
                if playpath:
                    rtmp = "{redirect}/{playpath}".format(redirect=redirect,
                                                          playpath=playpath)
                else:
                    rtmp = redirect
                self.parameters["rtmp"] = rtmp

            if "tcUrl" in self.parameters:
                self.parameters["tcUrl"] = redirect
Esempio n. 3
0
def create_output(plugin, output_shortname):
    """Decides where to write the stream.

    Depending on arguments it can be one of these:
     - The stdout pipe
     - A subprocess' stdin pipe
     - A named pipe that the subprocess reads from
     - A regular file

    """
    if args.auto_output:
        filename_id = ""
        filename_time = ""

        download_path = args.download_dir or DOWNLOAD_DIR
        output_format = get_output_format(output_shortname)

        if args.auto_output_id or args.auto_output_only_id:
            _found_url_re = get_url_re_from_module(plugin)
            m = _found_url_re.match(args.url)
            if m:
                filename_id = get_id_for_filename(m, args.url)

        if args.auto_output_time:
            filename_time = datetime.utcnow().strftime("_%Y_%m_%d_%Hh%Mm%Ss")

        file_endname = filename_id + filename_time + output_format

        if args.auto_output_only_id and filename_id:
            full_download_path = os.path.join(download_path, file_endname)
        else:
            normal_title = plugin._get_title()
            normal_title = re.sub(r"[\\/:?\"'\s]", "_", normal_title)
            if is_py2:
                # python 2.7 - UnicodeDecodeError
                # https://unicode.org/reports/tr15/
                from unicodedata import normalize
                normal_title = normalize("NFKD", str(normal_title))
            full_download_path = os.path.join(download_path, normal_title + file_endname)

        console.logger.info("Download path: \"{0}\"".format(full_download_path))
        args.output = full_download_path

    if args.output:
        if args.output == "-":
            out = FileOutput(fd=stdout)
        else:
            out = check_file_output(args.output, args.force)
    elif args.stdout:
        out = FileOutput(fd=stdout)
    else:
        http = namedpipe = None

        if not args.player:
            console.exit("The default player (VLC) does not seem to be "
                         "installed. You must specify the path to a player "
                         "executable with --player.")

        if args.player_fifo:
            pipename = "liveclipipe-{0}".format(os.getpid())
            console.logger.info("Creating pipe {0}", pipename)

            try:
                namedpipe = NamedPipe(pipename)
            except IOError as err:
                console.exit("Failed to create pipe: {0}", err)
        elif args.player_http:
            http = create_http_server()

        console.logger.info("Starting player: {0}", args.player)
        out = PlayerOutput(args.player, args=args.player_args,
                           quiet=not args.verbose_player,
                           kill=not args.player_no_close,
                           namedpipe=namedpipe, http=http)

    return out