import requests


def get_all_episodes(cfg, series_id):
    """
    Request all episodes within a series.

    :param series_id: Unique identifier for series
    :param cfg: Opencast configuration
    :return: List of pair of eventIds and titles for episodes
    """
    url = cfg['uri'] + "/api/events"
    params = {"filter": "is_part_of:" + series_id,
              "sort": "start_date:ASC"}
    result = []
    r = requests.get(url=url, params=params, auth=(cfg['user'], cfg['password']))
    json_data = r.json()
    for elem in json_data:
        result.append([elem['identifier'], elem['title']])
    return result