def create_scheduled_recording(name=None, description=None,
                               start_time=None, end_time=None,
                               folder_id=None, recorders=None,
                               is_broadcast=None):
    """
    Create a new scheduled recording
    """
    if (name is None or description is None or start_time is None or
            end_time is None or folder_id is None or
            not isinstance(recorders, list) or len(recorders) == 0 or
            not isinstance(is_broadcast, bool)):
        raise Exception("Incomplete Recording Schedule")

    url = panopto_url("scheduledRecordings")

    recording = {
        "Name": name,
        "Description": description,
        "StartTime": str(start_time),
        "EndTime": str(end_time),
        "FolderId": folder_id,
        "Recorders": [],
        "IsBroadcast": is_broadcast
    }

    for recorder in recorders:
        recording["Recorders"].append({
            "RemoteRecorderId": recorder.get('remote_recorder_id'),
            "SuppressPrimary": recorder.get('suppress_primary'),
            "SuppressSecondary": recorder.get('suppress_secondary')
        })

    response = post_resource(url, recording)

    return _scheduled_recordings(response)
def delete_session(id):
    """
    Deletes a session based on the retention policies
    """
    url = "{}/{}".format(panopto_url("sessions"), id)

    delete_resource(url)
def delete_folder(id):
    """
    Deletes a folder and all of its contents (including sessions
    and subfolders) according to the retention policy.
    """
    url = "{}/{}".format(panopto_url("folders"), id)

    delete_resource(url)
def get_folder(id):
    """
    Get a folder by id
    """
    url = "{}/{}".format(panopto_url("folders"), id)

    response = json.loads(get_resource(url))
    return folder_from_json(response)
def get_session(id):
    """
    Get a session by Id
    """
    url = "{}/{}".format(panopto_url("sessions"), id)

    response = json.loads(get_resource(url))
    return session_from_json(response)
def delete_scheduled_recording(id):
    """
    Delete a scheduled recording
    """

    url = "{}/{}".format(
        panopto_url("scheduledRecordings"), id)

    delete_resource(url)
def get_scheduled_recordings(id):
    """
    Get the scheduled recording information for a session
    """
    url = "{}/{}".format(
        panopto_url("scheduledRecordings"), id)

    response = json.loads(get_resource(url))
    return _scheduled_recordings(response)
def get_folder_sessions(id):
    """
    Get a list of sessions in the given folder

    To fetch all elements, this endpoint can be called multiple times,
    starting at pageNumber = 0 and incrementing the page number until
    no results are returned.
    """
    url = "{}/{}/sessions".format(panopto_url("folders"), id)

    return get_paged_resource(url, session_from_json)
def get_folder_children(id):
    """
    Get a list of child folders from the given parent

    To fetch all elements, this endpoint can be called multiple times,
    starting at pageNumber = 0 and incrementing the page number until
    no results are returned.
    """
    url = "{}/{}/children".format(panopto_url("folders"), id)

    return get_paged_resource(url, folder_from_json)
def folder_search(query):
    """
    Search for folders based on a keyword

    To fetch all elements, this endpoint can be called multiple times,
    starting at pageNumber = 0 and incrementing the page number until
    no results are returned.
    """
    url = "{}?searchQuery={}".format(panopto_url("folders/search"), query)

    return get_paged_resource(url, folder_from_json)
def session_search(query):
    """
    Search for sessions based on a keyword

    To fetch all elements, this endpoint can be called multiple times,
    starting at pageNumber = 0 and incrementing the page number until
    no results are returned.

    Note: The Session Search API does not return all available properties
    for a session. The CreatedBy and Urls properties (except the ViewerUrl
    and ThumbnailUrl) are not returned when searching for a session.
    To get these properties, you can get the specific session by Id.
    """

    url = "{}?searchQuery={}".format(panopto_url("sessions/search"), query)

    return get_paged_resource(url, session_from_json)
def update_folder(id, name=None, description=None, parent=None):
    """
    Update the folders's name, description, or parent folder.
    """
    url = "{}/{}".format(panopto_url("folders"), id)

    if not name and not description and not parent:
        raise Exception("Incomplete folder update")

    folder = {}

    if name:
        folder["Name"] = name

    if description:
        folder["Description"] = description

    if folder:
        folder["Parent"] = parent

    response = put_resource(url, folder)
    return folder_from_json(response)
def update_session(id, name=None, description=None, folder=None):
    """
    Update the session's name, description, or parent folder
    """
    url = "{}/{}".format(panopto_url("sessions"), id)

    if not name and not description and not folder:
        raise Exception("Incomplete recording schedule update")

    session = {}

    if name:
        session["Name"] = name

    if description:
        session["Description"] = description

    if folder:
        session["Folder"] = folder

    response = put_resource(url, session)
    return session_from_json(response)
def update_scheduled_recording_times(id, start_time=None, end_time=None):
    """
    Update the start or end time of a scheduled recording
    """

    if not start_time and not end_time:
        raise Exception("Incomplete scheduled recording update")

    url = "{}/{}".format(
        panopto_url("scheduledRecordings"), id)

    times = {}

    if start_time:
        times["StartTime"] = str(start_time)

    if end_time:
        times["EndTime"] = str(end_time)

    response = put_resource(url, times)

    return _scheduled_recordings(response)