def setup_config_args(parser, ignore_unknown=False): config_files = [] if args.config: # We want the config specified last to get highest priority for config_file in map(lambda path: Path(path).expanduser(), reversed(args.config)): if config_file.is_file(): config_files.append(config_file) else: # Only load first available default config for config_file in filter(lambda path: path.is_file(), CONFIG_FILES): if type(config_file) is DeprecatedPath: log.info(f"Loaded config from deprecated path, see CLI docs for how to migrate: {config_file}") config_files.append(config_file) break if streamlink and args.url: # Only load first available plugin config with ignored(NoPluginError): plugin = streamlink.resolve_url(args.url) for config_file in CONFIG_FILES: config_file = config_file.with_name(f"{config_file.name}.{plugin.module}") if not config_file.is_file(): continue if type(config_file) is DeprecatedPath: log.info(f"Loaded plugin config from deprecated path, see CLI docs for how to migrate: {config_file}") config_files.append(config_file) break if config_files: setup_args(parser, config_files, ignore_unknown=ignore_unknown)
def _close(self): # Close input to the player first to signal the end of the # stream and allow the player to terminate of its own accord if self.namedpipe: self.namedpipe.close() elif self.http: self.http.close() elif not self.filename: self.player.stdin.close() if self.record: self.record.close() if self.kill: with ignored(Exception): self.player.terminate() if not is_win32: t, timeout = 0.0, self.PLAYER_TERMINATE_TIMEOUT while self.player.poll() is None and t < timeout: sleep(0.5) t += 0.5 if not self.player.returncode: self.player.kill() self.player.wait()
def setup_config_args(parser, ignore_unknown=False): config_files = [] if streamlink and args.url: with ignored(NoPluginError): plugin = streamlink.resolve_url(args.url) config_files += [ "{0}.{1}".format(fn, plugin.module) for fn in CONFIG_FILES ] if args.config: # We want the config specified last to get highest priority config_files += list(reversed(args.config)) else: # Only load first available default config for config_file in filter(os.path.isfile, CONFIG_FILES): config_files.append(config_file) break if config_files: setup_args(parser, config_files, ignore_unknown=ignore_unknown)
def main(): error_code = 0 parser = build_parser() setup_args(parser, ignore_unknown=True) # call argument set up as early as possible to load args from config files setup_config_args(parser, ignore_unknown=True) # Console output should be on stderr if we are outputting # a stream to stdout. if args.stdout or args.output == "-" or args.record_and_pipe: console_out = sys.stderr else: console_out = sys.stdout # We don't want log output when we are printing JSON or a command-line. silent_log = any(getattr(args, attr) for attr in QUIET_OPTIONS) log_level = args.loglevel if not silent_log else "none" setup_logging(console_out, log_level) setup_console(console_out) setup_streamlink() # load additional plugins setup_plugins(args.plugin_dirs) setup_plugin_args(streamlink, parser) # call setup args again once the plugin specific args have been added setup_args(parser) setup_config_args(parser) # update the logging level if changed by a plugin specific config log_level = args.loglevel if not silent_log else "none" logger.root.setLevel(log_level) setup_http_session() check_root() log_current_versions() log_current_arguments(streamlink, parser) if args.version_check or args.auto_version_check: with ignored(Exception): check_version(force=args.version_check) if args.plugins: print_plugins() elif args.can_handle_url: try: streamlink.resolve_url(args.can_handle_url) except NoPluginError: error_code = 1 except KeyboardInterrupt: error_code = 130 elif args.can_handle_url_no_redirect: try: streamlink.resolve_url_no_redirect(args.can_handle_url_no_redirect) except NoPluginError: error_code = 1 except KeyboardInterrupt: error_code = 130 elif args.url: try: setup_options() handle_url() except KeyboardInterrupt: # Close output if output: output.close() console.msg("Interrupted! Exiting...") error_code = 130 finally: if stream_fd: try: log.info("Closing currently open stream...") stream_fd.close() except KeyboardInterrupt: error_code = 130 elif args.help: parser.print_help() else: usage = parser.format_usage() msg = ("{usage}\nUse -h/--help to see the available options or " "read the manual at https://streamlink.github.io").format( usage=usage) console.msg(msg) sys.exit(error_code)