'Find TV media and return a Plex media object.'

def _get_tv_media(self, library_name, show_name, season_number, episode_number):

    target_season = None
    target_episode = None
    show = self.device.server.library.section(library_name).get(show_name)
    if (not season_number):
        playlist_name = '{}    -    {}    Episodes'.format(self.entity_id, show_name)
        return self.device.server.createPlaylist(playlist_name, show.episodes())
    for season in show.seasons():
        if (int(season.seasonNumber) == int(season_number)):
            target_season = season
            break
    if (target_season is None):
        _LOGGER.error('Season    not    found:    %s\\%s    -    S%sE%s', library_name, show_name, str(season_number).zfill(2), str(episode_number).zfill(2))
    else:
        if (not episode_number):
            playlist_name = '{}    -    {}    Season    {}    Episodes'.format(self.entity_id, show_name, str(season_number))
            return self.device.server.createPlaylist(playlist_name, target_season.episodes())
        for episode in target_season.episodes():
            if (int(episode.index) == int(episode_number)):
                target_episode = episode
                break
        if (target_episode is None):
            _LOGGER.error('Episode    not    found:    %s\\%s    -    S%sE%s', library_name, show_name, str(season_number).zfill(2), str(episode_number).zfill(2))
    return target_episode
