def handle_url():
try:<EOL><INDENT>plugin = streamlink.resolve_url(args.url)<EOL>setup_plugin_options(streamlink, plugin)<EOL>log.info("<STR_LIT>",<EOL>plugin.module, args.url)<EOL>plugin_args = []<EOL>for parg in plugin.arguments:<EOL><INDENT>value = plugin.get_option(parg.dest)<EOL>if value:<EOL><INDENT>plugin_args.append((parg, value))<EOL><DEDENT><DEDENT>if plugin_args:<EOL><INDENT>log.debug("<STR_LIT>")<EOL>for parg, value in plugin_args:<EOL><INDENT>log.debug("<STR_LIT>".format(parg.argument_name(plugin.module),<EOL>value if not parg.sensitive else ("<STR_LIT:*>" * <NUM_LIT:8>),<EOL>parg.dest))<EOL><DEDENT><DEDENT>if args.retry_max or args.retry_streams:<EOL><INDENT>retry_streams = <NUM_LIT:1><EOL>retry_max = <NUM_LIT:0><EOL>if args.retry_streams:<EOL><INDENT>retry_streams = args.retry_streams<EOL><DEDENT>if args.retry_max:<EOL><INDENT>retry_max = args.retry_max<EOL><DEDENT>streams = fetch_streams_with_retry(plugin, retry_streams,<EOL>retry_max)<EOL><DEDENT>else:<EOL><INDENT>streams = fetch_streams(plugin)<EOL><DEDENT><DEDENT>except NoPluginError:<EOL><INDENT>console.exit("<STR_LIT>", args.url)<EOL><DEDENT>except PluginError as err:<EOL><INDENT>console.exit(u"<STR_LIT>", err)<EOL><DEDENT>if not streams:<EOL><INDENT>console.exit("<STR_LIT>", args.url)<EOL><DEDENT>if args.default_stream and not args.stream and not args.json:<EOL><INDENT>args.stream = args.default_stream<EOL><DEDENT>if args.stream:<EOL><INDENT>validstreams = format_valid_streams(plugin, streams)<EOL>for stream_name in args.stream:<EOL><INDENT>if stream_name in streams:<EOL><INDENT>log.info("<STR_LIT>", validstreams)<EOL>handle_stream(plugin, streams, stream_name)<EOL>return<EOL><DEDENT><DEDENT>err = ("<STR_LIT>"<EOL>"<STR_LIT>".format("<STR_LIT:U+002CU+0020>".join(args.stream)))<EOL>if console.json:<EOL><INDENT>console.msg_json(dict(streams=streams, plugin=plugin.module,<EOL>error=err))<EOL><DEDENT>else:<EOL><INDENT>console.exit("<STR_LIT>",<EOL>err, validstreams)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if console.json:<EOL><INDENT>console.msg_json(dict(streams=streams, plugin=plugin.module))<EOL><DEDENT>else:<EOL><INDENT>validstreams = format_valid_streams(plugin, streams)<EOL>console.msg("<STR_LIT>", validstreams)<EOL><DEDENT><DEDENT>
The URL handler.

    Attempts to resolve the URL to a plugin and then attempts
    to fetch a list of available streams.

    Proceeds to handle stream if user specified a valid one,
    otherwise output list of valid streams.