def METHOD_NAME(output, config):
    name = pathlib.Path(_formatname(output, config))
    subfolder = None
    dirname = None
    if not output.get("basedir", False):
        # If tvshow have not been derived by service do it by if season and episode is set
        if output.get("tvshow", None) is None:
            tvshow = output.get("season", None) is not None and output.get("episode", None) is not None
        else:
            tvshow = output.get("tvshow", False)
        if config.get("subfolder") and "title" in output and tvshow:
            # Add subfolder with name title
            subfolder = pathlib.Path(output["title"])
        elif config.get("subfolder") and not tvshow:
            # Add subfolder with name movies
            subfolder = pathlib.Path("movies")
    if config.get("output") and pathlib.Path(config.get("output")).expanduser().is_dir():
        dirname = pathlib.Path(config.get("output"))
    elif config.get("path") and pathlib.Path(config.get("path")).expanduser().is_dir():
        dirname = pathlib.Path(config.get("path"))
    elif config.get("output"):
        if "ext" in output and output["ext"]:
            name = pathlib.Path(f"{config.get('output')}.{output['ext']}")
        else:
            name = pathlib.Path(config.get("output"))
    name = pathlib.Path(sanitize(name.expanduser()))
    if subfolder and dirname:
        return dirname / subfolder / name.expanduser()
    elif subfolder:
        return subfolder / name.expanduser()
    elif dirname:
        return dirname / name.expanduser()
    else:
        return name.expanduser()