def output_stream_http(plugin, initial_streams, external=False, port=<NUM_LIT:0>):
global output<EOL>if not external:<EOL><INDENT>if not args.player:<EOL><INDENT>console.exit("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>title = create_title(plugin)<EOL>server = create_http_server()<EOL>player = output = PlayerOutput(args.player, args=args.player_args,<EOL>filename=server.url,<EOL>quiet=not args.verbose_player,<EOL>title=title)<EOL>try:<EOL><INDENT>log.info("<STR_LIT>", args.player)<EOL>if player:<EOL><INDENT>player.open()<EOL><DEDENT><DEDENT>except OSError as err:<EOL><INDENT>console.exit("<STR_LIT>",<EOL>args.player, err)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>server = create_http_server(host=None, port=port)<EOL>player = None<EOL>log.info("<STR_LIT>")<EOL>for url in server.urls:<EOL><INDENT>log.info("<STR_LIT:U+0020>" + url)<EOL><DEDENT><DEDENT>for req in iter_http_requests(server, player):<EOL><INDENT>user_agent = req.headers.get("<STR_LIT>") or "<STR_LIT>"<EOL>log.info("<STR_LIT>".format(user_agent))<EOL>stream_fd = prebuffer = None<EOL>while not stream_fd and (not player or player.running):<EOL><INDENT>try:<EOL><INDENT>streams = initial_streams or fetch_streams(plugin)<EOL>initial_streams = None<EOL>for stream_name in (resolve_stream_name(streams, s) for s in args.stream):<EOL><INDENT>if stream_name in streams:<EOL><INDENT>stream = streams[stream_name]<EOL>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>log.info("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>sleep(<NUM_LIT:10>)<EOL>continue<EOL><DEDENT><DEDENT>except PluginError as err:<EOL><INDENT>log.error(u"<STR_LIT>", err)<EOL>continue<EOL><DEDENT>try:<EOL><INDENT>log.info("<STR_LIT>", stream_name,<EOL>type(stream).shortname())<EOL>stream_fd, prebuffer = open_stream(stream)<EOL><DEDENT>except StreamError as err:<EOL><INDENT>log.error("<STR_LIT>", err)<EOL><DEDENT><DEDENT>if stream_fd and prebuffer:<EOL><INDENT>log.debug("<STR_LIT>")<EOL>read_stream(stream_fd, server, prebuffer)<EOL><DEDENT>server.close(True)<EOL><DEDENT>player.close()<EOL>server.close()<EOL>
Continuously output the stream over HTTP.