Skip to content

Commit

Permalink
Merge pull request #4124 from tianon/album-info
Browse files Browse the repository at this point in the history
Add a basic "--album" flag to "beet info"
  • Loading branch information
sampsyo committed Oct 30, 2021
2 parents b8b74a7 + 9ddc750 commit be82fd0
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
18 changes: 13 additions & 5 deletions beetsplug/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ def commands(self):
'-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',
Expand Down Expand Up @@ -121,14 +125,20 @@ def run(self, lib, opts, args):
}
)

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:
Expand All @@ -139,8 +149,6 @@ def run(self, lib, opts, args):
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:
Expand Down
17 changes: 12 additions & 5 deletions beetsplug/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
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)
Expand Down Expand Up @@ -69,8 +69,8 @@ def emitter(included_keys):
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)


Expand Down Expand Up @@ -156,6 +156,10 @@ def commands(self):
'-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',
Expand Down Expand Up @@ -186,7 +190,7 @@ def run(self, lib, opts, args):
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
Expand All @@ -199,7 +203,10 @@ def run(self, lib, opts, args):

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:
Expand Down
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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)
-----------------------

Expand Down
3 changes: 3 additions & 0 deletions docs/plugins/export.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 2 additions & 0 deletions docs/plugins/info.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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]``.
Expand Down

0 comments on commit be82fd0

Please sign in to comment.