'Creates a key value structure for a Tivo episode metadata file and
returns the resulting data object.
ep_obj: a TVEpisode instance to create the metadata file for.
Lookup the show in http://thetvdb.com/ using the python library:
https://github.com/dbr/indexer_api/
The results are saved in the object myShow.
The key values for the tivo metadata file are from:
http://pytivo.sourceforge.net/wiki/index.php/Metadata'

def _ep_data(self, ep_obj):

    data = u''
    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(str(e))
    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    -    ') + str(e)), logger.ERROR)
        return False
    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 getattr(myShow, u'seriesname', None):
            data += ((u'title    :    ' + myShow[u'seriesname']) + u'\n')
            data += ((u'seriesTitle    :    ' + myShow[u'seriesname']) + u'\n')
        data += ((u'episodeTitle    :    ' + curEpToWrite._format_pattern(u'%Sx%0E    %EN')) + u'\n')
        data += ((u'episodeNumber    :    ' + str(curEpToWrite.episode)) + u'\n')
        data += u'isEpisode    :    true\n'
        sanitizedDescription = curEpToWrite.description
        sanitizedDescription = sanitizedDescription.replace(u'\u201c', u'"').replace(u'\u201d', u'"')
        sanitizedDescription = sanitizedDescription.replace(u'\u2018', u"'").replace(u'\u2019', u"'").replace(u'\u02bc', u"'")
        data += ((u'description    :    ' + sanitizedDescription) + u'\n')
        if getattr(myShow, u'zap2it_id', None):
            data += ((u'seriesId    :    ' + myShow[u'zap2it_id']) + u'\n')
        if getattr(myShow, u'network', None):
            data += ((u'callsign    :    ' + myShow[u'network']) + u'\n')
        if (curEpToWrite.airdate != datetime.date.fromordinal(1)):
            data += ((u'originalAirDate    :    ' + str(curEpToWrite.airdate)) + u'T00:00:00Z\n')
        if getattr(myShow, u'_actors', None):
            for actor in myShow[u'_actors']:
                if ((u'name' in actor) and actor[u'name'].strip()):
                    data += ((u'vActor    :    ' + actor[u'name'].strip()) + u'\n')
        if getattr(myEp, u'rating', None):
            try:
                rating = float(myEp[u'rating'])
            except ValueError:
                rating = 0.0
            rating = (round(((8 * rating) / 10)) / 2.0)
            data += ((u'starRating    :    ' + str(rating)) + u'\n')
        if getattr(myShow, u'contentrating', None):
            data += ((u'tvRating    :    ' + str(myShow[u'contentrating'])) + u'\n')
        if ep_obj.show.genre:
            for genre in ep_obj.show.genre.split(u'|'):
                if genre:
                    data += ((u'vProgramGenre    :    ' + str(genre)) + u'\n')
    return data
