'Creates an elementTree XML structure for a WDTV style episode.xml
and returns the resulting data object.
ep_obj: a TVShow 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
    try:
        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
        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 False
    rootNode = etree.Element(u'details')
    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 ((ep_obj.season == 0) and (not getattr(myEp, u'firstaired', None))):
            myEp[u'firstaired'] = str(datetime.date.fromordinal(1))
        if (not (getattr(myEp, u'episodename', None) and getattr(myEp, u'firstaired', None))):
            return None
        if (len(eps_to_write) > 1):
            episode = etree.SubElement(rootNode, u'details')
        else:
            episode = rootNode
        episodeID = etree.SubElement(episode, u'id')
        episodeID.text = str(curEpToWrite.indexerid)
        title = etree.SubElement(episode, u'title')
        title.text = ep_obj.prettyName()
        if getattr(myShow, u'seriesname', None):
            seriesName = etree.SubElement(episode, u'series_name')
            seriesName.text = myShow[u'seriesname']
        if curEpToWrite.name:
            episodeName = etree.SubElement(episode, u'episode_name')
            episodeName.text = curEpToWrite.name
        seasonNumber = etree.SubElement(episode, u'season_number')
        seasonNumber.text = str(curEpToWrite.season)
        episodeNum = etree.SubElement(episode, u'episode_number')
        episodeNum.text = str(curEpToWrite.episode)
        firstAired = etree.SubElement(episode, u'firstaired')
        if (curEpToWrite.airdate != datetime.date.fromordinal(1)):
            firstAired.text = str(curEpToWrite.airdate)
        if getattr(myShow, u'firstaired', None):
            try:
                year_text = str(datetime.datetime.strptime(myShow[u'firstaired'], dateFormat).year)
                if year_text:
                    year = etree.SubElement(episode, u'year')
                    year.text = year_text
            except Exception:
                pass
        if ((curEpToWrite.season != 0) and getattr(myShow, u'runtime', None)):
            runtime = etree.SubElement(episode, u'runtime')
            runtime.text = myShow[u'runtime']
        if getattr(myShow, u'genre', None):
            genre = etree.SubElement(episode, u'genre')
            genre.text = u'    /    '.join([x.strip() for x in myShow[u'genre'].split(u'|') if x.strip()])
        if getattr(myEp, u'director', None):
            director = etree.SubElement(episode, u'director')
            director.text = myEp[u'director']
        if getattr(myShow, u'_actors', None):
            for actor in myShow[u'_actors']:
                if (not ((u'name' in actor) and actor[u'name'].strip())):
                    continue
                cur_actor = etree.SubElement(episode, u'actor')
                cur_actor_name = etree.SubElement(cur_actor, u'name')
                cur_actor_name.text = actor[u'name']
                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 curEpToWrite.description:
            overview = etree.SubElement(episode, u'overview')
            overview.text = curEpToWrite.description
        helpers.indentXML(rootNode)
        data = etree.ElementTree(rootNode)
    return data
