mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 16:42:42 +01:00
Add whitelist feature to zero plugin
This commit is contained in:
parent
13fede597f
commit
9f51e46bae
1 changed files with 39 additions and 14 deletions
|
|
@ -41,12 +41,17 @@ class ZeroPlugin(BeetsPlugin):
|
||||||
|
|
||||||
self.config.add({
|
self.config.add({
|
||||||
'fields': [],
|
'fields': [],
|
||||||
'update_database': False,
|
'keep_fields': [],
|
||||||
|
'update_database': False
|
||||||
})
|
})
|
||||||
|
|
||||||
self.patterns = {}
|
self.patterns = {}
|
||||||
self.warned = False
|
self.warned = False
|
||||||
|
|
||||||
|
if self.config['fields'] and self.config['keep_fields']:
|
||||||
|
self._log.warn(u'cannot blacklist and whitelist at the same time')
|
||||||
|
|
||||||
|
if self.config['fields']:
|
||||||
for field in self.config['fields'].as_str_seq():
|
for field in self.config['fields'].as_str_seq():
|
||||||
if field in ('id', 'path', 'album_id'):
|
if field in ('id', 'path', 'album_id'):
|
||||||
self._log.warn(u'field \'{0}\' ignored, zeroing '
|
self._log.warn(u'field \'{0}\' ignored, zeroing '
|
||||||
|
|
@ -62,6 +67,26 @@ class ZeroPlugin(BeetsPlugin):
|
||||||
# Matches everything
|
# Matches everything
|
||||||
self.patterns[field] = True
|
self.patterns[field] = True
|
||||||
|
|
||||||
|
if self.config['keep_fields']:
|
||||||
|
for field in self.config['keep_fields'].as_str_seq():
|
||||||
|
if field not in MediaFile.fields():
|
||||||
|
self._log.error(u'invalid field: {0}', field)
|
||||||
|
continue
|
||||||
|
|
||||||
|
for field in MediaFile.fields():
|
||||||
|
if field in self.config['keep_fields'].as_str_seq():
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.patterns[field] = self.config[field].as_str_seq()
|
||||||
|
except:
|
||||||
|
self.patterns[field] = True
|
||||||
|
|
||||||
|
# These fields should be preserved
|
||||||
|
if 'id' in self.patterns: del self.patterns['id']
|
||||||
|
if 'path' in self.patterns: del self.patterns['path']
|
||||||
|
if 'album_id' in self.patterns: del self.patterns['album_id']
|
||||||
|
|
||||||
def import_task_choice_event(self, session, task):
|
def import_task_choice_event(self, session, task):
|
||||||
"""Listen for import_task_choice event."""
|
"""Listen for import_task_choice event."""
|
||||||
if task.choice_flag == action.ASIS and not self.warned:
|
if task.choice_flag == action.ASIS and not self.warned:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue