'Scrub items that are torrents, if they\'re affected.'

@plugin.priority(SCRUB_PRIO)
def on_task_modify(self, task, config):

    if isinstance(config, list):
        mode = u'fields'
    else:
        mode = str(config).lower()
        if (mode in (u'off', u'false')):
            log.debug(u'Plugin    configured,    but    disabled')
            return
    for entry in task.entries:
        if (u'torrent' not in entry):
            continue
        modified = set()
        metainfo = entry[u'torrent'].content
        infohash = entry[u'torrent'].info_hash
        if (mode in (u'on', u'all', u'true')):
            modified = bittorrent.clean_meta(metainfo, including_info=(mode == u'all'), logger=log.debug)
        elif (mode in (u'resume', u'rtorrent')):
            if (mode == u'resume'):
                self.RT_KEYS = self.RT_KEYS[:1]
            for key in self.RT_KEYS:
                if (key in metainfo):
                    log.debug((u"Removing    key    '%s'..." % (key,)))
                    del metainfo[key]
                    modified.add(key)
        elif (mode == u'fields'):
            for key in config:
                fieldname = key
                key = bittorrent.Torrent.KEY_TYPE(key)
                field = metainfo
                while (field and (u'.' in key)):
                    (name, key) = key.split(u'.', 1)
                    try:
                        field = field[name]
                    except KeyError:
                        field = None
                    log.trace((key, field))
                if (field and (key in field)):
                    log.debug((u"Removing    key    '%s'..." % (fieldname,)))
                    del field[key]
                    modified.add(fieldname)
        else:
            raise ValueError((u'INTERNAL    ERROR:    Unknown    mode    %r' % mode))
        if modified:
            entry[u'torrent'].content = metainfo
            entry[u'torrent'].modified = True
            log.info((((u'Key    %s    was' if (len(modified) == 1) else u'Keys    %s    were') + u"    scrubbed    from    torrent    '%s'!") % (u',    '.join(sorted(modified)), entry[u'title'])))
            new_infohash = entry[u'torrent'].info_hash
            if (infohash != new_infohash):
                log.warning((u"Info    hash    changed    from    #%s    to    #%s    in    '%s'" % (infohash, new_infohash, entry[u'filename'])))
