Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore list for scrub plugin #1515

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions beetsplug/scrub.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(self):
super(ScrubPlugin, self).__init__()
self.config.add({
'auto': True,
'preserve': None
})
self.register_listener("write", self.write_item)

Expand Down Expand Up @@ -101,6 +102,34 @@ def scrub_func(lib, opts, args):

return [scrub_cmd]

def _preserve(self, path, tags):
"""Save tags mentioned in tags white list.
"""
self._preservedTags = None

try:
mf = mediafile.MediaFile(path, config['id3v23'].get(bool))
except IOError as exc:
self._log.error(u'could not open file to preserve tags on scrub: {0}', exc)

self._preservedTags = dict.fromkeys(tags)
for tag in tags:
self._preservedTags[tag] = getattr(mf, tag)

def _restore(self, path):
"""Restore tags mentioned in tags white list.
"""
if not self._preservedTags:
return

self._log.debug(u'writing new tags after scrub')
mf = mediafile.MediaFile(path, config['id3v23'].get(bool))
for tag, value in self._preservedTags.items():
if value:
self._log.info(u'restoring {0} = {1}'.format(tag, value))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something is wrong on this line. Not sure what it is, but if I remove this all my tests were successful.
http://pastebin.com/QxFuXeTY

setattr(mf, tag, value)
mf.save()

@staticmethod
def _mutagen_classes():
"""Get a list of file type classes from the Mutagen module.
Expand Down Expand Up @@ -143,4 +172,9 @@ def write_item(self, item, path, tags):
"""Automatically embed art into imported albums."""
if not scrubbing and self.config['auto']:
self._log.debug(u'auto-scrubbing {0}', util.displayable_path(path))
if self.config['preserve'].get():
preserveTags = self.config["preserve"].as_str_seq()
self._preserve(path, preserveTags)
self._scrub(path)
if self.config['preserve'].get():
self._restore(path)