New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add whitelist feature to zero plugin #1641
Changes from 3 commits
9f51e46
1584863
84da4b8
da65553
d180d42
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,26 +41,50 @@ def __init__(self): | |
|
||
self.config.add({ | ||
'fields': [], | ||
'update_database': False, | ||
'keep_fields': [], | ||
'update_database': False | ||
}) | ||
|
||
self.patterns = {} | ||
self.warned = False | ||
|
||
for field in self.config['fields'].as_str_seq(): | ||
if field in ('id', 'path', 'album_id'): | ||
self._log.warn(u'field \'{0}\' ignored, zeroing ' | ||
u'it would be dangerous', field) | ||
continue | ||
if self.config['fields']: | ||
self.validate_config('fields') | ||
for field in self.config['fields'].as_str_seq(): | ||
self.write_patterns(field) | ||
|
||
elif self.config['keep_fields']: | ||
self.validate_config('keep_fields') | ||
|
||
for field in MediaFile.fields(): | ||
if field in self.config['keep_fields'].as_str_seq(): | ||
continue | ||
self.write_patterns(field) | ||
|
||
# These fields should be preserved | ||
for key in ('id', 'path', 'album_id'): | ||
if key in self.patterns: | ||
del self.patterns[key] | ||
|
||
def validate_config(self, mode): | ||
"""Check if fields written in config are correct.""" | ||
if self.config['fields'] and self.config['keep_fields']: | ||
self._log.warn(u'cannot blacklist and whitelist at the same time') | ||
for field in self.config[mode].as_str_seq(): | ||
if field not in MediaFile.fields(): | ||
self._log.error(u'invalid field: {0}', field) | ||
continue | ||
if mode == 'fields' and field in ('id', 'path', 'album_id'): | ||
self._log.warn(u'field \'{0}\' ignored, zeroing ' | ||
u'it would be dangerous', field) | ||
continue | ||
|
||
try: | ||
self.patterns[field] = self.config[field].as_str_seq() | ||
except confit.NotFoundError: | ||
# Matches everything | ||
self.patterns[field] = True | ||
def write_patterns(self, field): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May I suggest the slightly more descriptive name
|
||
try: | ||
self.patterns[field] = self.config[field].as_str_seq() | ||
except confit.NotFoundError: | ||
# Matches everything | ||
self.patterns[field] = True | ||
|
||
def import_task_choice_event(self, session, task): | ||
"""Listen for import_task_choice event.""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,10 @@ Zero Plugin | |
=========== | ||
|
||
The ``zero`` plugin allows you to null fields in files' metadata tags. Fields | ||
can be nulled unconditionally or conditioned on a pattern match. For example, | ||
the plugin can strip useless comments like "ripped by MyGreatRipper." | ||
can be nulled unconditionally or conditioned on a pattern match. It works in | ||
two independent modes - blacklist and whitelist. You can only choose one option, | ||
however blacklist is the default. For example, the plugin can strip useless | ||
comments like "ripped by MyGreatRipper." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One more writing suggestion: instead of adding to this paragraph, add a new one below (after the example).
|
||
|
||
To use the ``zero`` plugin, enable the plugin in your configuration | ||
(see :ref:`using-plugins`). | ||
|
@@ -18,6 +20,9 @@ fields to nullify and the conditions for nullifying them: | |
get the list of all available fields by running ``beet fields``. In | ||
addition, the ``images`` field allows you to remove any images | ||
embedded in the media file. | ||
* Set ``keep_fields`` respectively to list of fields that plugin should | ||
preserve. That way ``zero`` cleans anything other than fields written in this | ||
option. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To make this a little clearer, I suggest:
|
||
* To conditionally filter a field, use ``field: [regexp, regexp]`` to specify | ||
regular expressions. | ||
* By default this plugin only affects files' tags ; the beets database is left | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny style issue: please add a trailing comma, which helps with maintainability.