'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)
    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    TVDB    while    creating    meta    files    -    skipping    -    {}'.format(e.message))
        return False
    rootNode = Element(u'details')
    movie = SubElement(rootNode, u'movie')
    movie.attrib[u'isExtra'] = u'false'
    movie.attrib[u'isSet'] = u'false'
    movie.attrib[u'isTV'] = u'true'
    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 ((curEpToWrite.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 = movie
            if curEpToWrite.name:
                EpisodeName = SubElement(episode, u'title')
                EpisodeName.text = curEpToWrite.name
            SeasonNumber = SubElement(episode, u'season')
            SeasonNumber.text = str(curEpToWrite.season)
            EpisodeNumber = SubElement(episode, u'episode')
            EpisodeNumber.text = str(curEpToWrite.episode)
            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:
                    pass
            if getattr(myShow, u'overview', None):
                plot = SubElement(episode, u'plot')
                plot.text = myShow[u'overview']
            if curEpToWrite.description:
                Overview = SubElement(episode, u'episodeplot')
                Overview.text = curEpToWrite.description
            if getattr(myShow, u'contentrating', None):
                mpaa = SubElement(episode, u'mpaa')
                mpaa.text = myShow[u'contentrating']
            if ((not ep_obj.relatedEps) and getattr(myEp, u'rating', None)):
                try:
                    rating = int((float(myEp[u'rating']) * 10))
                except ValueError:
                    rating = 0
                if rating:
                    Rating = SubElement(episode, u'rating')
                    Rating.text = str(rating)
            if getattr(myEp, u'director', None):
                director = SubElement(episode, u'director')
                director.text = myEp[u'director']
            if getattr(myEp, u'writer', None):
                writer = SubElement(episode, u'credits')
                writer.text = myEp[u'writer']
            if (getattr(myShow, u'_actors', None) or getattr(myEp, u'gueststars', None)):
                cast = SubElement(episode, u'cast')
                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(cast, u'actor')
                        cur_actor.text = actor
                if getattr(myShow, u'_actors', None):
                    for actor in myShow[u'_actors']:
                        if ((u'name' in actor) and actor[u'name'].strip()):
                            cur_actor = SubElement(cast, u'actor')
                            cur_actor.text = actor[u'name'].strip()
        else:
            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)
    indentXML(rootNode)
    data = ElementTree(rootNode)
    return data
