Match --jobs default & signature to that of convert plugin (--threads)
And change local function `func` to `ReplayGainPlugin` method `replaygain_func` so that `self` is passed explicitly
@@ -28,7 +28,7 @@ from six.moves import zip
from beets import ui
from beets.plugins import BeetsPlugin
from beets.util import (syspath, command_output, bytestring_path,
- displayable_path, py3_path)
+ displayable_path, py3_path, cpu_count)
# Utilities.
@@ -1170,6 +1170,7 @@ class ReplayGainPlugin(BeetsPlugin):
'overwrite': False,
'auto': True,
'backend': u'command',
+ 'threads': cpu_count(),
'per_disc': False,
'peak': 'true',
'targetlevel': 89,
@@ -1430,14 +1431,36 @@ class ReplayGainPlugin(BeetsPlugin):
def commands(self):
"""Return the "replaygain" ui subcommand.
"""
- def func(lib, opts, args):
+ cmd = ui.Subcommand('replaygain', help=u'analyze for ReplayGain')
+ cmd.parser.add_album_option()
+ cmd.parser.add_option(
+ "-t", "--threads", dest="threads",
+ help=u'change the number of threads, \
+ defaults to maximum available processors'
+ )
+ cmd.parser.add_option(
+ "-f", "--force", dest="force", action="store_true", default=False,
+ help=u"analyze all files, including those that "
+ "already have ReplayGain metadata")
+ cmd.parser.add_option(
+ "-w", "--write", default=None, action="store_true",
+ help=u"write new metadata to files' tags")
+ cmd.parser.add_option(
+ "-W", "--nowrite", dest="write", action="store_false",
+ help=u"don't write metadata (opposite of -w)")
+ cmd.func = self.replaygain_func
+ return [cmd]
+
+ def replaygain_func(self, lib, opts, args):
+ """Handle `replaygain` ui subcommand
+ """
write = ui.should_write(opts.write)
force = opts.force
- jobs = opts.jobs
+ threads = opts.threads or self.config['threads'].get(int)
- if self.backend_instance.do_parallel and jobs > 0:
+ if self.backend_instance.do_parallel:
from multiprocessing.pool import ThreadPool
- self.pool = ThreadPool(jobs)
+ self.pool = ThreadPool(threads)
if opts.album:
for album in lib.albums(ui.decargs(args)):
@@ -1450,22 +1473,3 @@ class ReplayGainPlugin(BeetsPlugin):
self.pool.close()
self.pool.join()
self.pool.terminate()
-
- cmd = ui.Subcommand('replaygain', help=u'analyze for ReplayGain')
- cmd.parser.add_album_option()
- cmd.parser.add_option(
- "-j", "--jobs", dest="jobs", type=int, default=0,
- help=u"worker pool size"
- )
- cmd.parser.add_option(
- "-f", "--force", dest="force", action="store_true", default=False,
- help=u"analyze all files, including those that "
- "already have ReplayGain metadata")
- cmd.parser.add_option(
- "-w", "--write", default=None, action="store_true",
- help=u"write new metadata to files' tags")
- cmd.parser.add_option(
- "-W", "--nowrite", dest="write", action="store_false",
- help=u"don't write metadata (opposite of -w)")
- cmd.func = func
- return [cmd]
