diff --git a/beetsplug/convert.py b/beetsplug/convert.py index d4bc6d32b..11ea1f5ce 100644 --- a/beetsplug/convert.py +++ b/beetsplug/convert.py @@ -139,8 +139,6 @@ class ConvertPlugin(BeetsPlugin): cmd = ui.Subcommand('convert', help='convert to external location') cmd.parser.add_option('-p', '--pretend', action='store_true', help='show actions but do nothing') - cmd.parser.add_option('-a', '--album', action='store_true', - help='choose albums instead of tracks') cmd.parser.add_option('-t', '--threads', action='store', type='int', help='change the number of threads, \ defaults to maximum available processors') @@ -149,10 +147,10 @@ class ConvertPlugin(BeetsPlugin): and move the old files') cmd.parser.add_option('-d', '--dest', action='store', help='set the destination directory') - cmd.parser.add_option('-f', '--format', action='store', dest='format', - help='set the destination directory') cmd.parser.add_option('-y', '--yes', action='store_true', dest='yes', help='do not ask for confirmation') + cmd.parser.add_album_option() + cmd.parser.add_format_option(target='item') cmd.func = self.convert_func return [cmd] diff --git a/beetsplug/duplicates.py b/beetsplug/duplicates.py index fb697922b..1739d3530 100644 --- a/beetsplug/duplicates.py +++ b/beetsplug/duplicates.py @@ -125,17 +125,6 @@ class DuplicatesPlugin(BeetsPlugin): self._command = Subcommand('duplicates', help=__doc__, aliases=['dup']) - - self._command.parser.add_option('-f', '--format', dest='format', - action='store', type='string', - help='print with custom format', - metavar='FMT', default='') - - self._command.parser.add_option('-a', '--album', dest='album', - action='store_true', - help='show duplicate albums instead of' - ' tracks') - self._command.parser.add_option('-c', '--count', dest='count', action='store_true', help='show duplicate counts') @@ -168,15 +157,11 @@ class DuplicatesPlugin(BeetsPlugin): action='store', metavar='DEST', help='copy items to dest') - self._command.parser.add_option('-p', '--path', dest='path', - action='store_true', - help='print paths for matched items or' - ' albums') - self._command.parser.add_option('-t', '--tag', dest='tag', action='store', help='tag matched items with \'k=v\'' ' attribute') + self._command.parser.add_all_common_options() def commands(self): diff --git a/beetsplug/echonest.py b/beetsplug/echonest.py index c8d45f3b0..753bfb5c3 100644 --- a/beetsplug/echonest.py +++ b/beetsplug/echonest.py @@ -486,10 +486,7 @@ class EchonestMetadataPlugin(plugins.BeetsPlugin): '-t', '--threshold', dest='threshold', action='store', type='float', default=0.15, help='Set difference threshold' ) - sim_cmd.parser.add_option( - '-f', '--format', action='store', default='${difference}: ${path}', - help='print with custom format' - ) + sim_cmd.parser.add_format_option() def sim_func(lib, opts, args): self.config.set_args(opts) diff --git a/beetsplug/mbsync.py b/beetsplug/mbsync.py index 365d83193..974f7e894 100644 --- a/beetsplug/mbsync.py +++ b/beetsplug/mbsync.py @@ -52,8 +52,7 @@ class MBSyncPlugin(BeetsPlugin): cmd.parser.add_option('-W', '--nowrite', action='store_false', default=config['import']['write'], dest='write', help="don't write updated metadata to files") - cmd.parser.add_option('-f', '--format', action='store', default='', - help='print with custom format') + cmd.parser.add_format_option() cmd.func = self.func return [cmd] @@ -64,17 +63,16 @@ class MBSyncPlugin(BeetsPlugin): pretend = opts.pretend write = opts.write query = ui.decargs(args) - fmt = opts.format - self.singletons(lib, query, move, pretend, write, fmt) - self.albums(lib, query, move, pretend, write, fmt) + self.singletons(lib, query, move, pretend, write) + self.albums(lib, query, move, pretend, write) - def singletons(self, lib, query, move, pretend, write, fmt): + def singletons(self, lib, query, move, pretend, write): """Retrieve and apply info from the autotagger for items matched by query. """ for item in lib.items(query + ['singleton:true']): - item_formatted = format(item, fmt) + item_formatted = format(item) if not item.mb_trackid: self._log.info(u'Skipping singleton with no mb_trackid: {0}', item_formatted) @@ -93,13 +91,13 @@ class MBSyncPlugin(BeetsPlugin): autotag.apply_item_metadata(item, track_info) apply_item_changes(lib, item, move, pretend, write) - def albums(self, lib, query, move, pretend, write, fmt): + def albums(self, lib, query, move, pretend, write): """Retrieve and apply info from the autotagger for albums matched by query and their items. """ # Process matching albums. for a in lib.albums(query): - album_formatted = format(a, fmt) + album_formatted = format(a) if not a.mb_albumid: self._log.info(u'Skipping album with no mb_albumid: {0}', album_formatted) diff --git a/beetsplug/missing.py b/beetsplug/missing.py index 517a20758..7f976f75c 100644 --- a/beetsplug/missing.py +++ b/beetsplug/missing.py @@ -94,19 +94,13 @@ class MissingPlugin(BeetsPlugin): self._command = Subcommand('missing', help=__doc__, aliases=['miss']) - - self._command.parser.add_option('-f', '--format', dest='format', - action='store', type='string', - help='print with custom FORMAT', - metavar='FORMAT', default='') - self._command.parser.add_option('-c', '--count', dest='count', action='store_true', help='count missing tracks per album') - self._command.parser.add_option('-t', '--total', dest='total', action='store_true', help='count total of missing tracks') + self._command.add_format_option() def commands(self): def _miss(lib, opts, args): diff --git a/beetsplug/play.py b/beetsplug/play.py index 8a912505c..65d5b91ec 100644 --- a/beetsplug/play.py +++ b/beetsplug/play.py @@ -42,11 +42,7 @@ class PlayPlugin(BeetsPlugin): 'play', help='send music to a player as a playlist' ) - play_command.parser.add_option( - '-a', '--album', - action='store_true', default=False, - help='query and load albums rather than tracks' - ) + play_command.parser.add_album_option() play_command.func = self.play_music return [play_command] diff --git a/beetsplug/random.py b/beetsplug/random.py index f6a664a4c..180e954f0 100644 --- a/beetsplug/random.py +++ b/beetsplug/random.py @@ -67,16 +67,11 @@ def random_item(lib, opts, args): random_cmd = Subcommand('random', help='chose a random track or album') -random_cmd.parser.add_option('-a', '--album', action='store_true', - help='choose an album instead of track') -random_cmd.parser.add_option('-p', '--path', action='store_true', - help='print the path of the matched item') -random_cmd.parser.add_option('-f', '--format', action='store', - help='print with custom format', default='') random_cmd.parser.add_option('-n', '--number', action='store', type="int", help='number of objects to choose', default=1) random_cmd.parser.add_option('-e', '--equal-chance', action='store_true', help='each artist has the same chance') +random_cmd.parser.add_all_common_options() random_cmd.func = random_item diff --git a/beetsplug/replaygain.py b/beetsplug/replaygain.py index ce41cad57..d5b6ae8d4 100644 --- a/beetsplug/replaygain.py +++ b/beetsplug/replaygain.py @@ -760,7 +760,6 @@ class ReplayGainPlugin(BeetsPlugin): self.handle_track(item, write) cmd = ui.Subcommand('replaygain', help='analyze for ReplayGain') - cmd.parser.add_option('-a', '--album', action='store_true', - help='analyze albums instead of tracks') + cmd.parser.add_album_option() cmd.func = func return [cmd] diff --git a/test/test_mbsync.py b/test/test_mbsync.py index 701227366..ff6e01cf3 100644 --- a/test/test_mbsync.py +++ b/test/test_mbsync.py @@ -99,6 +99,10 @@ class MbsyncCliTest(unittest.TestCase, TestHelper): e = "mbsync: Skipping album with no mb_albumid: 'album info'" self.assertEqual(e, logs[0]) + # restore the config + config['format_item'] = '$artist - $album - $title' + config['format_album'] = '$albumartist - $album' + # Test singleton with no mb_trackid. # The default singleton format includes $artist and $album # so we need to stub them here