'Creates an elementTree XML structure for a MediaBrowser style episode.xml
and returns the resulting data object.
show_obj: a TVShow instance to create the NFO for'

def _ep_data(self, ep_obj):

    eps_to_write = ([ep_obj] + ep_obj.relatedEps)
    persons_dict = {u'Director': [], u'GuestStar': [], u'Writer': []}
    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'Item')
    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 (curEpToWrite == ep_obj):
            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
            episode = rootNode
            if curEpToWrite.name:
                EpisodeName = etree.SubElement(episode, u'EpisodeName')
                EpisodeName.text = curEpToWrite.name
            EpisodeNumber = etree.SubElement(episode, u'EpisodeNumber')
            EpisodeNumber.text = str(ep_obj.episode)
            if ep_obj.relatedEps:
                EpisodeNumberEnd = etree.SubElement(episode, u'EpisodeNumberEnd')
                EpisodeNumberEnd.text = str(curEpToWrite.episode)
            SeasonNumber = etree.SubElement(episode, u'SeasonNumber')
            SeasonNumber.text = str(curEpToWrite.season)
            if ((not ep_obj.relatedEps) and getattr(myEp, u'absolute_number', None)):
                absolute_number = etree.SubElement(episode, u'absolute_number')
                absolute_number.text = str(myEp[u'absolute_number'])
            if (curEpToWrite.airdate != datetime.date.fromordinal(1)):
                FirstAired = etree.SubElement(episode, u'FirstAired')
                FirstAired.text = str(curEpToWrite.airdate)
            MetadataType = etree.SubElement(episode, u'Type')
            MetadataType.text = u'Episode'
            if curEpToWrite.description:
                Overview = etree.SubElement(episode, u'Overview')
                Overview.text = curEpToWrite.description
            if (not ep_obj.relatedEps):
                if getattr(myEp, u'rating', None):
                    Rating = etree.SubElement(episode, u'Rating')
                    Rating.text = myEp[u'rating']
                if getattr(myShow, u'imdb_id', None):
                    IMDB_ID = etree.SubElement(episode, u'IMDB_ID')
                    IMDB_ID.text = myShow[u'imdb_id']
                    IMDB = etree.SubElement(episode, u'IMDB')
                    IMDB.text = myShow[u'imdb_id']
                    IMDbId = etree.SubElement(episode, u'IMDbId')
                    IMDbId.text = myShow[u'imdb_id']
            indexerid = etree.SubElement(episode, u'id')
            indexerid.text = str(curEpToWrite.indexerid)
            Persons = etree.SubElement(episode, u'Persons')
            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(Persons, u'Person')
                    cur_actor_name = etree.SubElement(cur_actor, u'Name')
                    cur_actor_name.text = actor[u'name'].strip()
                    cur_actor_type = etree.SubElement(cur_actor, u'Type')
                    cur_actor_type.text = u'Actor'
                    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()
            Language = etree.SubElement(episode, u'Language')
            try:
                Language.text = myEp[u'language']
            except Exception:
                Language.text = sickbeard.INDEXER_DEFAULT_LANGUAGE
            thumb = etree.SubElement(episode, u'filename')
            thumb_text = self.get_episode_thumb_path(ep_obj)
            if thumb_text:
                thumb.text = thumb_text
        else:
            EpisodeNumberEnd.text = str(curEpToWrite.episode)
            if curEpToWrite.name:
                if (not EpisodeName.text):
                    EpisodeName.text = curEpToWrite.name
                else:
                    EpisodeName.text = ((EpisodeName.text + u',    ') + curEpToWrite.name)
            if curEpToWrite.description:
                if (not Overview.text):
                    Overview.text = curEpToWrite.description
                else:
                    Overview.text = ((Overview.text + u'\r') + curEpToWrite.description)
        if getattr(myEp, u'director', None):
            persons_dict[u'Director'] += [x.strip() for x in myEp[u'director'].split(u'|') if x.strip()]
        if getattr(myEp, u'gueststars', None):
            persons_dict[u'GuestStar'] += [x.strip() for x in myEp[u'gueststars'].split(u'|') if x.strip()]
        if getattr(myEp, u'writer', None):
            persons_dict[u'Writer'] += [x.strip() for x in myEp[u'writer'].split(u'|') if x.strip()]
    for (person_type, names) in six.iteritems(persons_dict):
        names = list(set(names))
        for cur_name in names:
            Person = etree.SubElement(Persons, u'Person')
            cur_person_name = etree.SubElement(Person, u'Name')
            cur_person_name.text = cur_name
            cur_person_type = etree.SubElement(Person, u'Type')
            cur_person_type.text = person_type
    helpers.indentXML(rootNode)
    data = etree.ElementTree(rootNode)
    return data
