import requests
import logging


def get_quality_score(API_KEY, JOB_ID):
    """
    Checks the average quality score of the diagnose job.
    Inputs:
       API_KEY: The Dolby.io media API key required for authenticating jobs.
       JOB_ID: The job ID that directs the server to your complete diagnose job.
    Returns: 
       Average audio quality for the input media.
    """

    #Check the outcome of the diagnose job
    url = "https://api.dolby.com/media/diagnose"
    headers = {"x-api-key": API_KEY,"Content-Type": "application/json","Accept": "application/json"}
    params = {"job_id": JOB_ID}

    response = requests.get(url, params=params, headers=headers)
    response.raise_for_status()

    res = response.json()
    logging.info("Outcome of diagnosis: " + str(res["result"]["audio"]["quality_score"]["average"]))

    return res["result"]["audio"]["quality_score"]["average"]