'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 or sickrage.srCore.srConfig.INDEXER_DEFAULT_LANGUAGE)
    lINDEXER_API_PARMS = srIndexerApi(ep_obj.show.indexer).api_params.copy()
    lINDEXER_API_PARMS[u'language'] = indexer_lang
    if (ep_obj.show.dvdorder != 0):
        lINDEXER_API_PARMS[u'dvdorder'] = True
    try:
        t = srIndexerApi(ep_obj.show.indexer).indexer(**lINDEXER_API_PARMS)
        myShow = t[ep_obj.show.indexerid]
    except indexer_shownotfound as e:
        raise ShowNotFoundException(e.message)
    except indexer_error as e:
        sickrage.srCore.srLogger.error(u'Unable    to    connect    to    {}    while    creating    meta    files    -    skipping    -    {}'.format(srIndexerApi(ep_obj.show.indexer).name, e))
        return
    if (len(eps_to_write) > 1):
        rootNode = Element(u'kodimultiepisode')
    else:
        rootNode = Element(u'episodedetails')
    for curEpToWrite in eps_to_write:
        try:
            myEp = myShow[curEpToWrite.season][curEpToWrite.episode]
        except (indexer_episodenotfound, indexer_seasonnotfound):
            sickrage.srCore.srLogger.info((u'Unable    to    find    episode    %dx%d    on    %s...    has    it    been    removed?    Should    I    delete    from    db?' % (curEpToWrite.season, curEpToWrite.episode, srIndexerApi(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)):
            sickrage.srCore.srLogger.debug(u'Not    generating    nfo    because    the    ep    has    no    title')
            return None
        sickrage.srCore.srLogger.debug((((u'Creating    metadata    for    episode    ' + str(ep_obj.season)) + u'x') + str(ep_obj.episode)))
        if (len(eps_to_write) > 1):
            episode = SubElement(rootNode, u'episodedetails')
        else:
            episode = rootNode
        if getattr(myEp, u'episodename', None):
            title = SubElement(episode, u'title')
            title.text = myEp[u'episodename']
        if getattr(myShow, u'seriesname', None):
            showtitle = SubElement(episode, u'showtitle')
            showtitle.text = myShow[u'seriesname']
        season = SubElement(episode, u'season')
        season.text = str(curEpToWrite.season)
        episodenum = SubElement(episode, u'episode')
        episodenum.text = str(curEpToWrite.episode)
        uniqueid = SubElement(episode, u'uniqueid')
        uniqueid.text = str(curEpToWrite.indexerid)
        if (curEpToWrite.airdate != datetime.date.fromordinal(1)):
            aired = SubElement(episode, u'aired')
            aired.text = str(curEpToWrite.airdate)
        if getattr(myEp, u'overview', None):
            plot = SubElement(episode, u'plot')
            plot.text = myEp[u'overview']
        if (curEpToWrite.season and getattr(myShow, u'runtime', None)):
            runtime = SubElement(episode, u'runtime')
            runtime.text = myShow[u'runtime']
        if getattr(myEp, u'airsbefore_season', None):
            displayseason = SubElement(episode, u'displayseason')
            displayseason.text = myEp[u'airsbefore_season']
        if getattr(myEp, u'airsbefore_episode', None):
            displayepisode = SubElement(episode, u'displayepisode')
            displayepisode.text = myEp[u'airsbefore_episode']
        if getattr(myEp, u'filename', None):
            thumb = SubElement(episode, u'thumb')
            thumb.text = myEp[u'filename'].strip()
        if getattr(myEp, u'writer', None):
            ep_credits = SubElement(episode, u'credits')
            ep_credits.text = myEp[u'writer'].strip()
        if getattr(myEp, u'director', None):
            director = SubElement(episode, u'director')
            director.text = myEp[u'director'].strip()
        if getattr(myEp, u'rating', None):
            rating = SubElement(episode, u'rating')
            rating.text = myEp[u'rating']
        if (getattr(myEp, u'gueststars', None) and isinstance(myEp[u'gueststars'], basestring)):
            for actor in (x.strip() for x in myEp[u'gueststars'].split(u'|') if x.strip()):
                cur_actor = SubElement(episode, u'actor')
                cur_actor_name = SubElement(cur_actor, u'name')
                cur_actor_name.text = actor
        if getattr(myShow, u'_actors', None):
            for actor in myShow[u'_actors']:
                cur_actor = SubElement(episode, u'actor')
                if ((u'name' in actor) and actor[u'name'].strip()):
                    cur_actor_name = 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 = 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 = SubElement(cur_actor, u'thumb')
                    cur_actor_thumb.text = actor[u'image'].strip()
    indentXML(rootNode)
    data = ElementTree(rootNode)
    return data
