def get_episodes_and_subs(language, series, season=None):
    if season:
        episodes = set(ep for ep in tolist(series.episodes) if ep.season == int(season))
    else:
        episodes = set(tolist(series.episodes))

    subs = []
    for ep in episodes:
        subs.extend(tolist(ep.get('subtitles')))

    return episodes, subs