'Generates a replacement map for this episode which maps all possible custom naming patterns to the correct
value for this episode.
Returns: A dict with patterns as the keys and their replacement values as the values.'

def _replace_map(self):

    ep_name = self._ep_name()
    def dot(name):
        return sanitizeSceneName(name)
    def us(name):
        return re.sub(u'[    -]', u'_', name)
    def release_name(name):
        if name:
            name = remove_non_release_groups(remove_extension(name))
        return name
    def release_group(show, name):
        if name:
            name = remove_non_release_groups(remove_extension(name))
        else:
            return u''
        try:
            parse_result = NameParser(name, showObj=show, naming_pattern=True).parse(name)
        except (InvalidNameException, InvalidShowException) as e:
            sickrage.srCore.srLogger.debug(u'Unable    to    get    parse    release_group:    {}'.format(e.message))
            return u''
        if (not parse_result.release_group):
            return u''
        return parse_result.release_group
    (_, epQual) = Quality.splitCompositeStatus(self.status)
    if sickrage.srCore.srConfig.NAMING_STRIP_YEAR:
        show_name = re.sub(u'\\(\\d+\\)$', u'', self.show.name).rstrip()
    else:
        show_name = self.show.name
    rel_grp = {u'SiCKRAGE': u'SiCKRAGE'}
    if hasattr(self, u'location'):
        rel_grp[u'location'] = release_group(self.show, self.location)
        if (not rel_grp[u'location']):
            del rel_grp[u'location']
    if hasattr(self, u'_release_group'):
        rel_grp[u'database'] = self.release_group
        if (not rel_grp[u'database']):
            del rel_grp[u'database']
    if hasattr(self, u'release_name'):
        rel_grp[u'release_name'] = release_group(self.show, self.release_name)
        if (not rel_grp[u'release_name']):
            del rel_grp[u'release_name']
    if (u'database' in rel_grp):
        relgrp = u'database'
    elif (u'release_name' in rel_grp):
        relgrp = u'release_name'
    elif (u'location' in rel_grp):
        relgrp = u'location'
    else:
        relgrp = u'SiCKRAGE'
    encoder = Quality.sceneQualityFromName(self.release_name.replace(rel_grp[relgrp], u''), epQual)
    if encoder:
        sickrage.srCore.srLogger.debug(((((u"Found    codec    for    '" + show_name) + u':    ') + ep_name) + u"'."))
    return {u'%SN': show_name, u'%S.N': dot(show_name), u'%S_N': us(show_name), u'%EN': ep_name, u'%E.N': dot(ep_name), u'%E_N': us(ep_name), u'%QN': Quality.qualityStrings[epQual], u'%Q.N': dot(Quality.qualityStrings[epQual]), u'%Q_N': us(Quality.qualityStrings[epQual]), u'%SQN': (Quality.sceneQualityStrings[epQual] + encoder), u'%SQ.N': dot((Quality.sceneQualityStrings[epQual] + encoder)), u'%SQ_N': us((Quality.sceneQualityStrings[epQual] + encoder)), u'%S': str(self.season), u'%0S': (u'%02d' % self.season), u'%E': str(self.episode), u'%0E': (u'%02d' % self.episode), u'%XS': str(self.scene_season), u'%0XS': (u'%02d' % self.scene_season), u'%XE': str(self.scene_episode), u'%0XE': (u'%02d' % self.scene_episode), u'%AB': (u'%(#)03d' % {u'#': self.absolute_number}), u'%XAB': (u'%(#)03d' % {u'#': self.scene_absolute_number}), u'%RN': release_name(self.release_name), u'%RG': rel_grp[relgrp], u'%CRG': rel_grp[relgrp].upper(), u'%AD': str(self.airdate).replace(u'-', u'    '), u'%A.D': str(self.airdate).replace(u'-', u'.'), u'%A_D': us(str(self.airdate)), u'%A-D': str(self.airdate), u'%Y': str(self.airdate.year), u'%M': str(self.airdate.month), u'%D': str(self.airdate.day), u'%0M': (u'%02d' % self.airdate.month), u'%0D': (u'%02d' % self.airdate.day), u'%RT': (u'PROPER' if self.is_proper else u'')}
