mirror of
https://github.com/beetbox/beets.git
synced 2025-12-08 01:23:09 +01:00
keyfinder: Only write on import when asked to
This should really be standard machinery.
This commit is contained in:
parent
b737102008
commit
5586fcee67
1 changed files with 11 additions and 7 deletions
|
|
@ -20,6 +20,7 @@ import subprocess
|
||||||
from beets import ui
|
from beets import ui
|
||||||
from beets import util
|
from beets import util
|
||||||
from beets.plugins import BeetsPlugin
|
from beets.plugins import BeetsPlugin
|
||||||
|
from beets import config
|
||||||
|
|
||||||
|
|
||||||
class KeyFinderPlugin(BeetsPlugin):
|
class KeyFinderPlugin(BeetsPlugin):
|
||||||
|
|
@ -31,7 +32,8 @@ class KeyFinderPlugin(BeetsPlugin):
|
||||||
u'auto': True,
|
u'auto': True,
|
||||||
u'overwrite': False,
|
u'overwrite': False,
|
||||||
})
|
})
|
||||||
self.config['auto'].get(bool)
|
|
||||||
|
if self.config['auto'].get(bool):
|
||||||
self.import_stages = [self.imported]
|
self.import_stages = [self.imported]
|
||||||
|
|
||||||
def commands(self):
|
def commands(self):
|
||||||
|
|
@ -41,13 +43,13 @@ class KeyFinderPlugin(BeetsPlugin):
|
||||||
return [cmd]
|
return [cmd]
|
||||||
|
|
||||||
def command(self, lib, opts, args):
|
def command(self, lib, opts, args):
|
||||||
self.find_key(lib.items(ui.decargs(args)))
|
self.find_key(lib.items(ui.decargs(args)),
|
||||||
|
write=config['import']['write'].get(bool))
|
||||||
|
|
||||||
def imported(self, session, task):
|
def imported(self, session, task):
|
||||||
if self.config['auto'].get(bool):
|
|
||||||
self.find_key(task.items)
|
self.find_key(task.items)
|
||||||
|
|
||||||
def find_key(self, items):
|
def find_key(self, items, write=False):
|
||||||
overwrite = self.config['overwrite'].get(bool)
|
overwrite = self.config['overwrite'].get(bool)
|
||||||
bin = util.bytestring_path(self.config['bin'].get(unicode))
|
bin = util.bytestring_path(self.config['bin'].get(unicode))
|
||||||
|
|
||||||
|
|
@ -64,5 +66,7 @@ class KeyFinderPlugin(BeetsPlugin):
|
||||||
item['initial_key'] = key
|
item['initial_key'] = key
|
||||||
self._log.debug(u'added computed initial key {0} for {1}',
|
self._log.debug(u'added computed initial key {0} for {1}',
|
||||||
key, util.displayable_path(item.path))
|
key, util.displayable_path(item.path))
|
||||||
|
|
||||||
|
if write:
|
||||||
item.try_write()
|
item.try_write()
|
||||||
item.store()
|
item.store()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue