def get_language_from_id(instance_session, instance_url, instance_key, instance_language, instance_name=''):
    instance_language_url = get_language_path(instance_url, instance_key)
    language_response = instance_session.get(instance_language_url)
    if (language_response.status_code != 200):
        logger.error(f'Could not get language id from (instance{instance_name}) {instance_language_url} - only works on sonarr v3')
        exit_system()
    instance_languages = None
    try:
        instance_languages = language_response.json()
    except:
        logger.error(f'Could not decode language id from {instance_language_url}')
        exit_system()
    instance_languages = instance_languages[0]['languages']
    language = next((item for item in instance_languages if (item.get('language', {}).get('name').lower() == instance_language.lower())), False)
    if (not language):
        logger.error(f'Could not find language_id for instance {instance_name} and language {instance_language}')
        exit_system()
    instance_language_id = language.get('language', {}).get('id')
    logger.debug(f'found id "{instance_language_id}" from language "{instance_language}" for instance {instance_name}')
    if (instance_language_id is None):
        logger.error(f'language_id is None for instance {instance_name} and language {instance_language}')
        exit_system()
    return instance_language_id
def get_language_from_id(instance_session, instance_url, instance_key, instance_language, instance_name=):
    instance_language_url = get_language_path(instance_url, instance_key)
    language_response = instance_session.get(instance_language_url)
    if (language_response.status_code != 200):
        logger.error(f'Could not get language id from (instance{instance_name}) {instance_language_url} - only works on sonarr v3')
        exit_system()
    instance_languages = None
    try:
        instance_languages = language_response.json()
    except:
        logger.error(f'Could not decode language id from {instance_language_url}')
        exit_system()
    instance_languages = instance_languages[0]['languages']
    language = next((item for item in instance_languages if (item.get('language', {}).get('name').lower() == instance_language.lower())), False)
    if (not language):
        logger.error(f'Could not find language_id for instance {instance_name} and language {instance_language}')
        exit_system()
    instance_language_id = language.get('language', {}).get('id')
    logger.debug(f'found id "{instance_language_id}" from language "{instance_language}" for instance {instance_name}')
    if (instance_language_id is None):
        logger.error(f'language_id is None for instance {instance_name} and language {instance_language}')
        exit_system()
    return instance_language_id