diff --git a/beetsplug/export.py b/beetsplug/export.py index 3cb8f8c4f..bb2c9ba28 100644 --- a/beetsplug/export.py +++ b/beetsplug/export.py @@ -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: diff --git a/beetsplug/info.py b/beetsplug/info.py index 1bb29d09b..1e6d4b329 100644 --- a/beetsplug/info.py +++ b/beetsplug/info.py @@ -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: diff --git a/docs/changelog.rst b/docs/changelog.rst index 1b345650d..72af36e3c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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) ----------------------- diff --git a/docs/plugins/export.rst b/docs/plugins/export.rst index 284d2b8b6..bca9d1e5a 100644 --- a/docs/plugins/export.rst +++ b/docs/plugins/export.rst @@ -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. diff --git a/docs/plugins/info.rst b/docs/plugins/info.rst index 3950cf0aa..1ed7582af 100644 --- a/docs/plugins/info.rst +++ b/docs/plugins/info.rst @@ -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]``.