diff --git a/NEWS b/NEWS index 45a50cf4d..78d3b74bd 100644 --- a/NEWS +++ b/NEWS @@ -38,6 +38,7 @@ quiet mode when there is no strong recommendation. The options are "skip" (the default) and "asis". * The "version" command now lists all the loaded plugins. +* A new plugin, called "info", just prints out audio file metadata. * Fix a bug where some files would be erroneously interpreted as MP4. * Fix permission bits applied to album art files. * Fix malformed MusicBrainz queries caused by null characters. diff --git a/beets/ui/commands.py b/beets/ui/commands.py index 57abf297b..ae71e60f3 100644 --- a/beets/ui/commands.py +++ b/beets/ui/commands.py @@ -25,7 +25,6 @@ from beets import ui from beets.ui import print_ from beets import autotag from beets import library -from beets.mediafile import UnreadableFileError, FileTypeError import beets.autotag.art from beets.ui import pipeline from beets import plugins diff --git a/beetsplug/info.py b/beetsplug/info.py new file mode 100644 index 000000000..5e5fde518 --- /dev/null +++ b/beetsplug/info.py @@ -0,0 +1,57 @@ +# This file is part of beets. +# Copyright 2011, Adrian Sampson. +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. + +"""Shows file metadata. +""" + +from beets.plugins import BeetsPlugin +from beets import library +from beets import ui +from beets import mediafile + +def info(paths): + # Set up fields to output. + fields = [] + for name, _, _, mffield in library.ITEM_FIELDS: + if mffield: + fields.append(name) + maxwidth = max(len(name) for name in fields) + lineformat = u'{{:>{0}}}: {{}}'.format(maxwidth) + + first = True + for path in paths: + if not first: + ui.print_() + + path = library._normpath(path) + ui.print_(path) + try: + mf = mediafile.MediaFile(path) + except mediafile.UnreadableFileError: + ui.print_('cannot read file') + continue + for name in fields: + ui.print_(lineformat.format(name, getattr(mf, name))) + + first = False + +class InfoPlugin(BeetsPlugin): + def commands(self): + cmd = ui.Subcommand('info', help='show file metadata') + def func(lib, config, opts, args): + if not args: + raise ui.UserError('no file specified') + info(args) + cmd.func = func + return [cmd]