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