import requests


def get_all_series(cfg):
    """
    Request and return all series in given Opencast organization.

    :param cfg: Opencast configuration
    :return: List of seriesId and title pairs
    """
    url = cfg['uri'] + "/api/series"
    params = {"sort": "title:ASC", "offset": 0, "limit": 10000}
    offset = 0
    result = []
    while True:
        params["offset"] = offset
        r = requests.get(url=url, params=params, auth=(cfg['user'], cfg['password']))
        if not r.json():
            break
        offset += 10000
        x = r.json()
        for elem in x:
            result.append((elem['identifier'], elem['title']))
    return result