Commits

Adrian Sampson committed 7740b5b Merge

Merge pull request #276 from pedros/missing

Use newly defined '$missing' template field instead of hardcoded format (-c)

Comments (0)

Files changed (2)

beetsplug/missing.py

 import logging
 
 from beets.autotag import hooks
-from beets.library import Item
+from beets.library import Item, Album
 from beets.plugins import BeetsPlugin
 from beets.ui import decargs, print_obj, Subcommand
 
                 if count:
                     missing = _missing_count(album)
                     if missing:
-                        fmt = "$album: {}".format(missing)
-                        print_obj(album, lib, fmt=fmt)
+                        if not fmt:
+                            fmt = '$albumartist - $album: $missing'
+                        print_obj(album, lib, fmt=fmt.format(missing))
                     continue
 
                 for item in _missing(album):
 
         self._command.func = _miss
         return [self._command]
+
+
+@MissingPlugin.template_field('missing')
+def _tmpl_missing(album):
+    """Return number of missing items in 'album'.
+    """
+    if isinstance(album, Album):
+        return _missing_count(album)
+    else:
+        return ''

docs/plugins/missing.rst

 ==============
 
 This plugin adds a new command, ``missing`` or ``miss``, which finds
-and lists, for every album in your collection, which tracks are
-missing. Listing missing files requires one network call to
-MusicBrainz.
+and lists, for every album in your collection, which or how many
+tracks are missing. Listing missing files requires one network call to
+MusicBrainz. Merely counting missing files avoids any network calls.
+
 
 Installation
 ------------
 count
 ~~~~~
 
-The ``count`` option (default: false) prints a count of missing
-tracks per album, with ``format`` hard-coded to ``'$album: $count'``.
+The ``count`` option (default: false) prints a count of missing tracks
+per album, with ``format`` defaulting to ``$albumartist - $album:
+$missing``.
 
 total
 ~~~~~
 The ``total`` option (default: false) prints a single
 count of missing tracks in all albums
 
+Metadata fields
+---------------
+
+With this plugin enabled, templates can reference ``$missing`` as they
+can any standard metadata field for use in :doc:`Queries
+</reference/query>` and :doc:`Path Formats </reference/pathformat>`.
 
 Examples
 --------
 
   beet missing -t
 
+Call this plugin from other beet commands::
+
+  beet ls -a -f '$albumartist - $album: $missing'
 
 TODO
 ----