How to use the beets.ui 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 beetbox / beets / beets / ui / commands.py View on Github external
lhs += templ.format(lhs_length)
            rhs += templ.format(rhs_length)
            lhs_width += len(cur_length) + 3

        # Penalties.
        penalties = penalty_string(match.distance.tracks[track_info])
        if penalties:
            rhs += ' %s' % penalties

        if lhs != rhs:
            lines.append((' * %s' % lhs, rhs, lhs_width))
        elif config['import']['detail']:
            lines.append((' * %s' % lhs, '', lhs_width))

    # Print each track in two columns, or across two lines.
    col_width = (ui.term_width() - len(''.join([' * ', ' -> ']))) // 2
    if lines:
        max_width = max(w for _, _, w in lines)
        for lhs, rhs, lhs_width in lines:
            if not rhs:
                print_(lhs)
            elif max_width > col_width:
                print_(u'%s ->\n   %s' % (lhs, rhs))
            else:
                pad = max_width - lhs_width
                print_(u'%s%s -> %s' % (lhs, ' ' * pad, rhs))

    # Missing and unmatched tracks.
    if match.extra_tracks:
        print_('Missing tracks:')
    for track_info in match.extra_tracks:
        line = ' ! %s (#%s)' % (track_info.title, format_index(track_info))
github beetbox / beets / test / test_ui.py View on Github external
def test_print_with_invalid_locale(self):
        old_lang = os.environ.get('LANG')
        os.environ['LANG'] = ''
        old_ctype = os.environ.get('LC_CTYPE')
        os.environ['LC_CTYPE'] = 'UTF-8'

        try:
            ui.print_(u'something')
        except ValueError:
            self.fail(u'ValueError during print')
        finally:
            if old_lang:
                os.environ['LANG'] = old_lang
            else:
                del os.environ['LANG']
            if old_ctype:
                os.environ['LC_CTYPE'] = old_ctype
            else:
                del os.environ['LC_CTYPE']
github rembo10 / headphones / lib / beets / ui / commands.py View on Github external
a UserError if no items match. also_items controls whether, when
    fetching albums, the associated items should be fetched also.
    """
    if album:
        albums = list(lib.albums(query))
        items = []
        if also_items:
            for al in albums:
                items += al.items()

    else:
        albums = []
        items = list(lib.items(query))

    if album and not albums:
        raise ui.UserError(u'No matching albums found.')
    elif not album and not items:
        raise ui.UserError(u'No matching items found.')

    return items, albums
github beetbox / beets / beetsplug / replaygain.py View on Github external
def func(lib, opts, args):
            write = ui.should_write(opts.write)
            force = opts.force

            if opts.album:
                for album in lib.albums(ui.decargs(args)):
                    self.handle_album(album, write, force)

            else:
                for item in lib.items(ui.decargs(args)):
                    self.handle_track(item, write, force)
github clinton-hall / nzbToMedia / libs / beetsplug / lyrics.py View on Github external
def func(lib, opts, args):
            # The "write to files" option corresponds to the
            # import_write config value.
            write = ui.should_write()
            for item in lib.items(ui.decargs(args)):
                self.fetch_item_lyrics(
                    lib, item, write,
                    opts.force_refetch or self.config['force'],
                )
                if opts.printlyr and item.lyrics:
                    ui.print_(item.lyrics)
github beetbox / beets / beetsplug / bucket.py View on Github external
# digits starting from yearfrom
        if d < 100:
            if (d % 100) < (yearfrom % 100):
                d = (yearfrom - yearfrom % 100) + 100 + d
            else:
                d = (yearfrom - yearfrom % 100) + d
        return d

    years = [int(x) for x in re.findall(r'\d+', span_str)]
    if not years:
        raise ui.UserError(u"invalid range defined for year bucket '%s': no "
                           u"year found" % span_str)
    try:
        years = [normalize_year(x, years[0]) for x in years]
    except BucketError as exc:
        raise ui.UserError(u"invalid range defined for year bucket '%s': %s" %
                           (span_str, exc))

    res = {'from': years[0], 'str': span_str}
    if len(years) > 1:
        res['to'] = years[-1]
    return res
github beetbox / beets / beetsplug / bpd / __init__.py View on Github external
def func(lib, config, opts, args):
            host = args.pop(0) if args else \
                beets.ui.config_val(config, 'bpd', 'host', DEFAULT_HOST)
            port = args.pop(0) if args else \
                beets.ui.config_val(config, 'bpd', 'port', str(DEFAULT_PORT))
            if args:
                raise beets.ui.UserError('too many arguments')
            password = beets.ui.config_val(config, 'bpd', 'password',
                                           DEFAULT_PASSWORD)
            debug = opts.debug or False
            self.start_bpd(lib, host, int(port), password, debug)
github beetbox / beets / beetsplug / bucket.py View on Github external
def build_alpha_spans(alpha_spans_str, alpha_regexs):
    """Extract alphanumerics from string and return sorted list of chars
    [from...to]
    """
    spans = []

    for elem in alpha_spans_str:
        if elem in alpha_regexs:
            spans.append(re.compile(alpha_regexs[elem]))
        else:
            bucket = sorted([x for x in elem.lower() if x.isalnum()])
            if bucket:
                begin_index = ASCII_DIGITS.index(bucket[0])
                end_index = ASCII_DIGITS.index(bucket[-1])
            else:
                raise ui.UserError(u"invalid range defined for alpha bucket "
                                   u"'%s': no alphanumeric character found" %
                                   elem)
            spans.append(
                re.compile(
                    "^[" + ASCII_DIGITS[begin_index:end_index + 1] +
                    ASCII_DIGITS[begin_index:end_index + 1].upper() + "]"
                )
            )
    return spans
github clinton-hall / nzbToMedia / libs / beetsplug / ipfs.py View on Github external
def ipfs_list(self, lib, args):
        fmt = config['format_album'].get()
        try:
            albums = self.query(lib, args)
        except IOError:
            ui.print_("No imported libraries yet.")
            return

        for album in albums:
            ui.print_(format(album, fmt), " : ", album.ipfs)
github beetbox / beets / beetsplug / replaygain.py View on Github external
)
                if len(album_gain.track_gains) != len(items):
                    raise ReplayGainError(
                        u"ReplayGain backend failed "
                        u"for some tracks in album {0}".format(album)
                    )

                for item, track_gain in zip(items, album_gain.track_gains):
                    store_track_gain(item, track_gain)
                    store_album_gain(item, album_gain.album_gain)
                    if write:
                        item.try_write()
            except ReplayGainError as e:
                self._log.info(u"ReplayGain error: {0}", e)
            except FatalReplayGainError as e:
                raise ui.UserError(
                    u"Fatal replay gain error: {0}".format(e))