def tvnamer(paths):
    # type: (List[str]) -> None
    """Main tvnamer function, takes an array of paths, does stuff.
    """

    print("#" * 20)
    print("# Starting tvnamer")

    episodes_found = []

    for cfile in find_files(paths):
        parser = FileParser(cfile)
        try:
            episode = parser.parse()
        except InvalidFilename as e:
            warn("Invalid filename: %s" % e)
        else:
            if (
                episode.seriesname is None
                and Config["force_name"] is None
                and Config["series_id"] is None
            ):
                warn(
                    "Parsed filename did not contain series name (and --name or --series-id not specified), skipping: %s"
                    % cfile
                )

            else:
                episodes_found.append(episode)

    if len(episodes_found) == 0:
        raise NoValidFilesFoundError()

    print(
        "# Found %d episode" % len(episodes_found) + ("s" * (len(episodes_found) > 1))
    )

    # Sort episodes by series name, season and episode number
    episodes_found.sort(key=lambda x: x.sortable_info())

    # episode sort order
    if Config["order"] == "dvd":
        dvdorder = True
    else:
        dvdorder = False

    if Config["tvdb_api_key"] is not None:
        LOG.debug("Using custom API key from config")
        api_key = Config["tvdb_api_key"]
    else:
        LOG.debug("Using tvnamer default API key")
        api_key = TVNAMER_API_KEY

    if os.getenv("TVNAMER_TEST_MODE", "0") == "1":
        from .test_cache import get_test_cache_session
        cache = get_test_cache_session()
    else:
        cache = True

    tvdb_instance = tvdb_api.Tvdb(
        interactive=not Config["select_first"],
        search_all_languages=Config["search_all_languages"],
        language=Config["language"],
        dvdorder=dvdorder,
        cache=cache,
        apikey=api_key,
    )

    for episode in episodes_found:
        process_file(tvdb_instance, episode)
        print("")

    print("#" * 20)
    print("# Done")
Main tvnamer function, takes an array of paths, does stuff.
    
tvnamer/main.py