<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def format_filename(series_name, season_number, episode_numbers, episode_names, extension):
 """Generates a filename based on metadata using configured format. :param str series_name: name of TV series :param int season_number: the numeric season of series :param list(int) episode_numbers: the numeric episode of the series :param list(str) episode_names: episode title of the series :param str extension: media file extension :returns: formatted filename using input values and configured format :rtype: str """


    epdata = {
        'seriesname': tc.titlecase(_replace_series_name(
            series_name, cfg.CONF.output_series_replacements) or ''),
        'seasonnumber': season_number,
        'episode': _format_episode_numbers(episode_numbers),
        'episodename': tc.titlecase(_format_episode_name(episode_names)),
        'ext': extension,
    }

    value = apply_replacements(
        cfg.CONF.filename_format_ep % epdata,
        cfg.CONF.output_filename_replacements)

    return _make_valid_filename(value)