'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 or sickrage.srCore.srConfig.INDEXER_DEFAULT_LANGUAGE)
    try:
        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
        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    ' + srIndexerApi(ep_obj.show.indexer).name) + u'    while    creating    meta    files    -    skipping    -    {}'.format(e.message)))
        return False
    rootNode = Element(u'details')
    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 ((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 = SubElement(rootNode, u'details')
        else:
            episode = rootNode
        episodeID = SubElement(episode, u'id')
        episodeID.text = str(curEpToWrite.indexerid)
        title = SubElement(episode, u'title')
        title.text = ep_obj.prettyName()
        if getattr(myShow, u'seriesname', None):
            seriesName = SubElement(episode, u'series_name')
            seriesName.text = myShow[u'seriesname']
        if curEpToWrite.name:
            episodeName = SubElement(episode, u'episode_name')
            episodeName.text = curEpToWrite.name
        seasonNumber = SubElement(episode, u'season_number')
        seasonNumber.text = str(curEpToWrite.season)
        episodeNum = SubElement(episode, u'episode_number')
        episodeNum.text = str(curEpToWrite.episode)
        firstAired = 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 = SubElement(episode, u'year')
                    year.text = year_text
            except Exception:
                pass
        if ((curEpToWrite.season != 0) and getattr(myShow, u'runtime', None)):
            runtime = SubElement(episode, u'runtime')
            runtime.text = myShow[u'runtime']
        if getattr(myShow, u'genre', None):
            genre = 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 = 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 = SubElement(episode, u'actor')
                cur_actor_name = 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 = SubElement(cur_actor, u'role')
                    cur_actor_role.text = actor[u'role'].strip()
        if curEpToWrite.description:
            overview = SubElement(episode, u'overview')
            overview.text = curEpToWrite.description
    indentXML(rootNode)
    data = ElementTree(rootNode)
    return data
