Merge pull request #4124 from tianon/album-info

Add a basic "--album" flag to "beet info"
This commit is contained in:
Adrian Sampson 2021-10-29 21:08:05 -04:00 committed by GitHub
commit be82fd0f4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 10 deletions

View file

@ -87,6 +87,10 @@ class ExportPlugin(BeetsPlugin):
'-l', '--library', action='store_true',
help='show library fields instead of tags',
)
cmd.parser.add_option(
'-a', '--album', action='store_true',
help='show album fields instead of tracks (implies "--library")',
)
cmd.parser.add_option(
'--append', action='store_true', default=False,
help='if should append data to the file',
@ -121,14 +125,20 @@ class ExportPlugin(BeetsPlugin):
}
)
items = []
data_collector = library_data if opts.library else tag_data
if opts.library or opts.album:
data_collector = library_data
else:
data_collector = tag_data
included_keys = []
for keys in opts.included_keys:
included_keys.extend(keys.split(','))
for data_emitter in data_collector(lib, ui.decargs(args)):
items = []
for data_emitter in data_collector(
lib, ui.decargs(args),
album=opts.album,
):
try:
data, item = data_emitter(included_keys or '*')
except (mediafile.UnreadableFileError, OSError) as ex:
@ -139,8 +149,6 @@ class ExportPlugin(BeetsPlugin):
if isinstance(value, bytes):
data[key] = util.displayable_path(value)
items += [data]
if file_format_is_line_based:
export_format.export(data, **format_options)
else:

View file

@ -25,7 +25,7 @@ from beets.library import Item
from beets.util import displayable_path, normpath, syspath
def tag_data(lib, args):
def tag_data(lib, args, album=False):
query = []
for arg in args:
path = normpath(arg)
@ -69,8 +69,8 @@ def tag_data_emitter(path):
return emitter
def library_data(lib, args):
for item in lib.items(args):
def library_data(lib, args, album=False):
for item in lib.albums(args) if album else lib.items(args):
yield library_data_emitter(item)
@ -156,6 +156,10 @@ class InfoPlugin(BeetsPlugin):
'-l', '--library', action='store_true',
help='show library fields instead of tags',
)
cmd.parser.add_option(
'-a', '--album', action='store_true',
help='show album fields instead of tracks (implies "--library")',
)
cmd.parser.add_option(
'-s', '--summarize', action='store_true',
help='summarize the tags of all files',
@ -186,7 +190,7 @@ class InfoPlugin(BeetsPlugin):
dictionary and only prints that. If two files have different values
for the same tag, the value is set to '[various]'
"""
if opts.library:
if opts.library or opts.album:
data_collector = library_data
else:
data_collector = tag_data
@ -199,7 +203,10 @@ class InfoPlugin(BeetsPlugin):
first = True
summary = {}
for data_emitter in data_collector(lib, ui.decargs(args)):
for data_emitter in data_collector(
lib, ui.decargs(args),
album=opts.album,
):
try:
data, item = data_emitter(included_keys or '*')
except (mediafile.UnreadableFileError, OSError) as ex:

View file

@ -35,6 +35,8 @@ Other new things:
* Permissions plugin now sets cover art permissions to the file permissions.
* :doc:`/plugins/unimported`: Support excluding specific
subdirectories in library.
* :doc:`/plugins/info`: Support ``--album`` flag.
* :doc:`/plugins/export`: Support ``--album`` flag.
For plugin developers:
@ -52,6 +54,8 @@ Bug fixes:
* :doc:`/plugins/discogs`: Remove requests ratel imit code from plugin in favor of discogs library built-in capability
:bug: `4108`
* :doc:`/plugins/export`: Fix duplicated output.
1.5.0 (August 19, 2021)
-----------------------

View file

@ -34,6 +34,9 @@ The ``export`` command has these command-line options:
* ``--library`` or ``-l``: Show data from the library database instead of the
files' tags.
* ``--album`` or ``-a``: Show data from albums instead of tracks (implies
``--library``).
* ``--output`` or ``-o``: Path for an output file. If not informed, will print
the data in the console.

View file

@ -31,6 +31,8 @@ Additional command-line options include:
* ``--library`` or ``-l``: Show data from the library database instead of the
files' tags.
* ``--album`` or ``-a``: Show data from albums instead of tracks (implies
``--library``).
* ``--summarize`` or ``-s``: Merge all the information from multiple files
into a single list of values. If the tags differ across the files, print
``[various]``.