src/streamlink_cli/main.py
def handle_url():
    """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.

    """

    try:
        plugin = streamlink.resolve_url(args.url)
        setup_plugin_options(streamlink, plugin)
        log.info("Found matching plugin {0} for URL {1}",
                 plugin.module, args.url)

        plugin_args = []
        for parg in plugin.arguments:
            value = plugin.get_option(parg.dest)
            if value:
                plugin_args.append((parg, value))

        if plugin_args:
            log.debug("Plugin specific arguments:")
            for parg, value in plugin_args:
                log.debug(" {0}={1} ({2})".format(parg.argument_name(plugin.module),
                                                  value if not parg.sensitive else ("*" * 8),
                                                  parg.dest))

        if args.retry_max or args.retry_streams:
            retry_streams = 1
            retry_max = 0
            if args.retry_streams:
                retry_streams = args.retry_streams
            if args.retry_max:
                retry_max = args.retry_max
            streams = fetch_streams_with_retry(plugin, retry_streams,
                                               retry_max)
        else:
            streams = fetch_streams(plugin)
    except NoPluginError:
        console.exit("No plugin can handle URL: {0}", args.url)
    except PluginError as err:
        console.exit(u"{0}", err)

    if not streams:
        console.exit("No playable streams found on this URL: {0}", args.url)

    if args.default_stream and not args.stream and not args.json:
        args.stream = args.default_stream

    if args.stream:
        validstreams = format_valid_streams(plugin, streams)
        for stream_name in args.stream:
            if stream_name in streams:
                log.info("Available streams: {0}", validstreams)
                handle_stream(plugin, streams, stream_name)
                return

        err = ("The specified stream(s) '{0}' could not be "
               "found".format(", ".join(args.stream)))

        if console.json:
            console.msg_json(dict(streams=streams, plugin=plugin.module,
                                  error=err))
        else:
            console.exit("{0}.\n       Available streams: {1}",
                         err, validstreams)
    else:
        if console.json:
            console.msg_json(dict(streams=streams, plugin=plugin.module))
        else:
            validstreams = format_valid_streams(plugin, streams)
            console.msg("Available streams: {0}", validstreams)
def handle_url():
    """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.

    """

    try:
        plugin = streamlink.resolve_url(args.url)
        setup_plugin_options(streamlink, plugin)
        log.info("Found matching plugin {0} for URL {1}",
                 plugin.module, args.url)

        plugin_args = []
        for parg in plugin.arguments:
            value = plugin.get_option(parg.dest)
            if value:
                plugin_args.append((parg, value))

        if plugin_args:
            log.debug("Plugin specific arguments:")
            for parg, value in plugin_args:
                log.debug(" {0}={1} ({2})".format(parg.argument_name(plugin.module),
                                                  value if not parg.sensitive else ("*" * 8),
                                                  parg.dest))

        if args.retry_max or args.retry_streams:
            retry_streams = 1
            retry_max = 0
            if args.retry_streams:
                retry_streams = args.retry_streams
            if args.retry_max:
                retry_max = args.retry_max
            streams = fetch_streams_with_retry(plugin, retry_streams,
                                               retry_max)
        else:
            streams = fetch_streams(plugin)
    except NoPluginError:
        console.exit("No plugin can handle URL: {0}", args.url)
    except PluginError as err:
        console.exit(u"{0}", err)

    if not streams:
        console.exit("No playable streams found on this URL: {0}", args.url)

    if args.default_stream and not args.stream and not args.json:
        args.stream = args.default_stream

    if args.stream:
        validstreams = format_valid_streams(plugin, streams)
        for stream_name in args.stream:
            if stream_name in streams:
                log.info("Available streams: {0}", validstreams)
                handle_stream(plugin, streams, stream_name)
                return

        err = ("The specified stream(s) '{0}' could not be "
               "found".format(", ".join(args.stream)))

        if console.json:
            console.msg_json(dict(streams=streams, plugin=plugin.module,
                                  error=err))
        else:
            console.exit("{0}.\n       Available streams: {1}",
                         err, validstreams)
    else:
        if console.json:
            console.msg_json(dict(streams=streams, plugin=plugin.module))
        else:
            validstreams = format_valid_streams(plugin, streams)
            console.msg("Available streams: {0}", validstreams)
def handle_url ( ) : try : plugin = streamlink . resolve_url ( args . url ) setup_plugin_options ( streamlink , plugin ) log . info ( "Found matching plugin {0} for URL {1}" , plugin . module , args . url ) plugin_args = [ ] for parg in plugin . arguments : value = plugin . get_option ( parg . dest ) if value : plugin_args . append ( ( parg , value ) ) if plugin_args : log . debug ( "Plugin specific arguments:" ) for parg , value in plugin_args : log . debug ( " {0}={1} ({2})" . format ( parg . argument_name ( plugin . module ) , value if not parg . sensitive else ( "*" * 8 ) , parg . dest ) ) if args . retry_max or args . retry_streams : retry_streams = 1 retry_max = 0 if args . retry_streams : retry_streams = args . retry_streams if args . retry_max : retry_max = args . retry_max streams = fetch_streams_with_retry ( plugin , retry_streams , retry_max ) else : streams = fetch_streams ( plugin ) except NoPluginError : console . exit ( "No plugin can handle URL: {0}" , args . url ) except PluginError as err : console . exit ( u"{0}" , err ) if not streams : console . exit ( "No playable streams found on this URL: {0}" , args . url ) if args . default_stream and not args . stream and not args . json : args . stream = args . default_stream if args . stream : validstreams = format_valid_streams ( plugin , streams ) for stream_name in args . stream : if stream_name in streams : log . info ( "Available streams: {0}" , validstreams ) handle_stream ( plugin , streams , stream_name ) return err = ( "The specified stream(s) '{0}' could not be " "found" . format ( ", " . join ( args . stream ) ) ) if console . json : console . msg_json ( dict ( streams = streams , plugin = plugin . module , error = err ) ) else : console . exit ( "{0}.\n       Available streams: {1}" , err , validstreams ) else : if console . json : console . msg_json ( dict ( streams = streams , plugin = plugin . module ) ) else : validstreams = format_valid_streams ( plugin , streams ) console . msg ( "Available streams: {0}" , validstreams )
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.
The URL handler .