def extract_episode_details(season, episode_response):
    """Clean and extract episode details response.

    Take an episode details response and cleans the data.
    Extract the relevant fields needed to construct an
    Episode object.

    Args:
        season: The season number
        episode_response: An episode_details response

    Returns:
        episode_details: Dictionary with relevant episode
            information
    """
    try:
        rating = float(episode_response['imdbRating'])
    except ValueError:
        # Rating may come through as 'N/A' if episode has not aired
        rating = None

    return {
        'title': episode_response['Title'],
        'episode': int(episode_response['Episode']),
        'season': season,
        'ratings': {'imdb': rating},
    }