How to use the beets.ui.Subcommand function in beets

To help you get started, we’ve selected a few beets examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github igordertigor / beets-usertag / beetsplug / usertag.py View on Github external
newtags = opts.tags
    for item in items:
        usertags = item.get('usertags', None)
        if usertags is None:
            usertags = []
        else:
            usertags = usertags.split('|')
        # usertags.append(' '.join(newtags))
        usertags.extend(newtags)
        usertags = list(set(usertags))
        if '' in usertags:
            usertags.pop(usertags.index(''))
        item.update({'usertags': '|'.join(usertags)})
        item.store()
        print('Added tags\n   {}'.format(item))
add_tag_command = Subcommand(
    'addtag',
    help='Add user defined tags.',
    aliases=('adt',))
add_tag_command.func = add_usertag
add_tag_command.parser.add_option(
    '--tag', '-t',
    action='append', dest='tags',
    help='Tag to add. '
    'Combine multiple tags by specifiing this option repeatedly.')
add_tag_command.parser.usage += '\n'\
    'Example: beet addtag artist:beatles -t favourites'


def remove_usertag(lib, opts, args):
    """Remove a usertag"""
    items = lib.items(args)
github geigerzaehler / beets-alternatives / beetsplug / alternatives.py View on Github external
def alternative(self, name, lib):
        conf = self.config[name]
        if not conf.exists():
            raise KeyError(name)

        if conf['formats'].exists():
            fmt = conf['formats'].as_str()
            if fmt == u'link':
                return SymlinkView(self._log, name, lib, conf)
            else:
                return ExternalConvert(self._log, name, fmt.split(), lib, conf)
        else:
            return External(self._log, name, lib, conf)


class AlternativesCommand(Subcommand):

    name = 'alt'
    help = 'manage alternative files'

    def __init__(self, plugin):
        parser = ArgumentParser()
        subparsers = parser.add_subparsers(prog=parser.prog + ' alt')
        subparsers.required = True
        subparsers.dest = 'update'
        update = subparsers.add_parser('update')
        update.set_defaults(func=plugin.update)
        update.add_argument('name')
        update.add_argument('--create', action='store_const',
                            dest='create', const=True)
        update.add_argument('--no-create', action='store_const',
                            dest='create', const=False)
github rembo10 / headphones / lib / beets / ui / commands.py View on Github external
# Confirm with user.
        if not ui.input_yn(prompt, True):
            return

    # Remove (and possibly delete) items.
    with lib.transaction():
        for obj in (albums if album else items):
            obj.remove(delete)


def remove_func(lib, opts, args):
    remove_items(lib, decargs(args), opts.album, opts.delete, opts.force)


remove_cmd = ui.Subcommand(
    u'remove', help=u'remove matching items from the library', aliases=(u'rm',)
)
remove_cmd.parser.add_option(
    u"-d", u"--delete", action="store_true",
    help=u"also remove files from disk"
)
remove_cmd.parser.add_option(
    u"-f", u"--force", action="store_true",
    help=u"do not ask when removing items"
)
remove_cmd.parser.add_album_option()
remove_cmd.func = remove_func
default_commands.append(remove_cmd)


# stats: Show library/query statistics.
github beetbox / beets / beetsplug / edit.py View on Github external
def commands(self):
        edit_command = ui.Subcommand(
            'edit',
            help=u'interactively edit metadata'
        )
        edit_command.parser.add_option(
            u'-f', u'--field',
            metavar='FIELD',
            action='append',
            help=u'edit this field also',
        )
        edit_command.parser.add_option(
            u'--all',
            action='store_true', dest='all',
            help=u'edit all fields',
        )
        edit_command.parser.add_album_option()
        edit_command.func = self._edit_command
github rembo10 / headphones / lib / beets / ui / commands.py View on Github external
obj.move(copy, basedir=dest)
            obj.store()


def move_func(lib, opts, args):
    dest = opts.dest
    if dest is not None:
        dest = normpath(dest)
        if not os.path.isdir(dest):
            raise ui.UserError(u'no such directory: %s' % dest)

    move_items(lib, dest, decargs(args), opts.copy, opts.album, opts.pretend,
               opts.timid)


move_cmd = ui.Subcommand(
    u'move', help=u'move or copy items', aliases=(u'mv',)
)
move_cmd.parser.add_option(
    u'-d', u'--dest', metavar='DIR', dest='dest',
    help=u'destination directory'
)
move_cmd.parser.add_option(
    u'-c', u'--copy', default=False, action='store_true',
    help=u'copy instead of moving'
)
move_cmd.parser.add_option(
    u'-p', u'--pretend', default=False, action='store_true',
    help=u'show how files would be moved, but don\'t touch anything'
)
move_cmd.parser.add_option(
    u'-t', u'--timid', dest='timid', action='store_true',
github beetbox / beets / beetsplug / chroma.py View on Github external
def commands(self):
        submit_cmd = ui.Subcommand('submit',
                                   help=u'submit Acoustid fingerprints')

        def submit_cmd_func(lib, opts, args):
            try:
                apikey = config['acoustid']['apikey'].as_str()
            except confit.NotFoundError:
                raise ui.UserError(u'no Acoustid user API key provided')
            submit_items(self._log, apikey, lib.items(ui.decargs(args)))
        submit_cmd.func = submit_cmd_func

        fingerprint_cmd = ui.Subcommand(
            'fingerprint',
            help=u'generate fingerprints for items without them'
        )

        def fingerprint_cmd_func(lib, opts, args):
            for item in lib.items(ui.decargs(args)):
                fingerprint_item(self._log, item, write=ui.should_write())
        fingerprint_cmd.func = fingerprint_cmd_func

        return [submit_cmd, fingerprint_cmd]
github beetbox / beets / beetsplug / convert.py View on Github external
def commands(self):
        cmd = ui.Subcommand('convert', help=u'convert to external location')
        cmd.parser.add_option('-p', '--pretend', action='store_true',
                              help=u'show actions but do nothing')
        cmd.parser.add_option('-t', '--threads', action='store', type='int',
                              help=u'change the number of threads, \
                              defaults to maximum available processors')
        cmd.parser.add_option('-k', '--keep-new', action='store_true',
                              dest='keep_new', help=u'keep only the converted \
                              and move the old files')
        cmd.parser.add_option('-d', '--dest', action='store',
                              help=u'set the destination directory')
        cmd.parser.add_option('-f', '--format', action='store', dest='format',
                              help=u'set the target format of the tracks')
        cmd.parser.add_option('-y', '--yes', action='store_true', dest='yes',
                              help=u'do not ask for confirmation')
        cmd.parser.add_option('-l', '--link', action='store_true', dest='link',
                              help=u'symlink files that do not \
github beetbox / beets / beetsplug / keyfinder.py View on Github external
def commands(self):
        cmd = ui.Subcommand('keyfinder',
                            help=u'detect and add initial key from audio')
        cmd.func = self.command
        return [cmd]
github beetbox / beets / beetsplug / missing.py View on Github external
def __init__(self):
        super(MissingPlugin, self).__init__()

        self.config.add({
            'count': False,
            'total': False,
        })

        self.album_template_fields['missing'] = _missing_count

        self._command = Subcommand('missing',
                                   help=__doc__,
                                   aliases=['miss'])
        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.parser.add_format_option()
github beetbox / beets / beets / ui / commands.py View on Github external
fdict = plugin.template_fields
            plugin_fields += fdict.keys()
        if plugin_fields:
            print("Template fields from plugins:")
            _print_rows(plugin_fields)

    print("Item fields:")
    _print_rows(library.Item._fields.keys())
    _show_plugin_fields(False)

    print("\nAlbum fields:")
    _print_rows(library.Album._fields.keys())
    _show_plugin_fields(True)


fields_cmd = ui.Subcommand(
    'fields',
    help='show fields available for queries and format strings'
)
fields_cmd.func = fields_func
default_commands.append(fields_cmd)


# help: Print help text for commands

class HelpCommand(ui.Subcommand):

    def __init__(self):
        super(HelpCommand, self).__init__(
            'help', aliases=('?',),
            help='give detailed help on a specific sub-command',
        )