Repository: beetbox/beets

Issue:
info: Add per-album option
Branched from https://github.com/beetbox/beets/issues/2132
### Problem

There is currently no option to find all the metadata from an album.
This would be especially handy for templating as path variables prefer album metadata.

`beet info -a Album` seems like a good idea, returning just the album metadata, not the info for the tracks.



Discussion:

Resolving patch:
diff --git a/beetsplug/export.py b/beetsplug/export.py
--- a/beetsplug/export.py
+++ b/beetsplug/export.py
@@ -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',
@@ -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:
@@ -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:
diff --git a/beetsplug/info.py b/beetsplug/info.py
--- a/beetsplug/info.py
+++ b/beetsplug/info.py
@@ -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)
@@ -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)
 
 
@@ -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',
@@ -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
@@ -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:


Test patch: