'Creates an elementTree XML structure for an KODI-style episode.nfo and
returns the resulting data object.
show_obj: a TVEpisode instance to create the NFO for'

def _ep_data(self, ep_obj):

    eps_to_write = ([ep_obj] + ep_obj.relatedEps)
    indexer_lang = ep_obj.show.lang
    lINDEXER_API_PARMS = sickbeard.indexerApi(ep_obj.show.indexer).api_params.copy()
    lINDEXER_API_PARMS[u'actors'] = True
    lINDEXER_API_PARMS[u'language'] = (indexer_lang or sickbeard.INDEXER_DEFAULT_LANGUAGE)
    if ep_obj.show.dvdorder:
        lINDEXER_API_PARMS[u'dvdorder'] = True
    try:
        t = sickbeard.indexerApi(ep_obj.show.indexer).indexer(**lINDEXER_API_PARMS)
        myShow = t[ep_obj.show.indexerid]
    except sickbeard.indexer_shownotfound as e:
        raise ShowNotFoundException(e.message)
    except sickbeard.indexer_error as e:
        logger.log((((u'Unable    to    connect    to    ' + sickbeard.indexerApi(ep_obj.show.indexer).name) + u'    while    creating    meta    files    -    skipping    -    ') + ex(e)), logger.ERROR)
        return
    if (len(eps_to_write) > 1):
        rootNode = etree.Element(u'kodimultiepisode')
    else:
        rootNode = etree.Element(u'episodedetails')
    for curEpToWrite in eps_to_write:
        try:
            myEp = myShow[curEpToWrite.season][curEpToWrite.episode]
        except (sickbeard.indexer_episodenotfound, sickbeard.indexer_seasonnotfound):
            logger.log(u'Metadata    writer    is    unable    to    find    episode    {0:d}x{1:d}    of    {2}    on    {3}...has    it    been    removed?    Should    I    delete    from    db?'.format(curEpToWrite.season, curEpToWrite.episode, curEpToWrite.show.name, sickbeard.indexerApi(ep_obj.show.indexer).name))
            return None
        if (not getattr(myEp, u'firstaired', None)):
            myEp[u'firstaired'] = str(datetime.date.fromordinal(1))
        if (not getattr(myEp, u'episodename', None)):
            logger.log(u'Not    generating    nfo    because    the    ep    has    no    title', logger.DEBUG)
            return None
        logger.log((((u'Creating    metadata    for    episode    ' + str(ep_obj.season)) + u'x') + str(ep_obj.episode)), logger.DEBUG)
        if (len(eps_to_write) > 1):
            episode = etree.SubElement(rootNode, u'episodedetails')
        else:
            episode = rootNode
        if getattr(myEp, u'episodename', None):
            title = etree.SubElement(episode, u'title')
            title.text = myEp[u'episodename']
        if getattr(myShow, u'seriesname', None):
            showtitle = etree.SubElement(episode, u'showtitle')
            showtitle.text = myShow[u'seriesname']
        season = etree.SubElement(episode, u'season')
        season.text = str(curEpToWrite.season)
        episodenum = etree.SubElement(episode, u'episode')
        episodenum.text = str(curEpToWrite.episode)
        uniqueid = etree.SubElement(episode, u'uniqueid')
        uniqueid.text = str(curEpToWrite.indexerid)
        if (curEpToWrite.airdate != datetime.date.fromordinal(1)):
            aired = etree.SubElement(episode, u'aired')
            aired.text = str(curEpToWrite.airdate)
        if getattr(myEp, u'overview', None):
            plot = etree.SubElement(episode, u'plot')
            plot.text = myEp[u'overview']
        if (curEpToWrite.season and getattr(myShow, u'runtime', None)):
            runtime = etree.SubElement(episode, u'runtime')
            runtime.text = myShow[u'runtime']
        if getattr(myEp, u'airsbefore_season', None):
            displayseason = etree.SubElement(episode, u'displayseason')
            displayseason.text = myEp[u'airsbefore_season']
        if getattr(myEp, u'airsbefore_episode', None):
            displayepisode = etree.SubElement(episode, u'displayepisode')
            displayepisode.text = myEp[u'airsbefore_episode']
        if getattr(myEp, u'filename', None):
            thumb = etree.SubElement(episode, u'thumb')
            thumb.text = myEp[u'filename'].strip()
        if getattr(myEp, u'rating', None):
            rating = etree.SubElement(episode, u'rating')
            rating.text = myEp[u'rating']
        if (getattr(myEp, u'writer', None) and isinstance(myEp[u'writer'], six.string_types)):
            for writer in self._split_info(myEp[u'writer']):
                cur_writer = etree.SubElement(episode, u'credits')
                cur_writer.text = writer
        if (getattr(myEp, u'director', None) and isinstance(myEp[u'director'], six.string_types)):
            for director in self._split_info(myEp[u'director']):
                cur_director = etree.SubElement(episode, u'director')
                cur_director.text = director
        if (getattr(myEp, u'gueststars', None) and isinstance(myEp[u'gueststars'], six.string_types)):
            for actor in self._split_info(myEp[u'gueststars']):
                cur_actor = etree.SubElement(episode, u'actor')
                cur_actor_name = etree.SubElement(cur_actor, u'name')
                cur_actor_name.text = actor
        if getattr(myShow, u'_actors', None):
            for actor in myShow[u'_actors']:
                cur_actor = etree.SubElement(episode, u'actor')
                if ((u'name' in actor) and actor[u'name'].strip()):
                    cur_actor_name = etree.SubElement(cur_actor, u'name')
                    cur_actor_name.text = actor[u'name'].strip()
                else:
                    continue
                if ((u'role' in actor) and actor[u'role'].strip()):
                    cur_actor_role = etree.SubElement(cur_actor, u'role')
                    cur_actor_role.text = actor[u'role'].strip()
                if ((u'image' in actor) and actor[u'image'].strip()):
                    cur_actor_thumb = etree.SubElement(cur_actor, u'thumb')
                    cur_actor_thumb.text = actor[u'image'].strip()
    helpers.indentXML(rootNode)
    data = etree.ElementTree(rootNode)
    return data
