diff --git a/beetsplug/web/__init__.py b/beetsplug/web/__init__.py index 34d55e1ab..4697ffd65 100644 --- a/beetsplug/web/__init__.py +++ b/beetsplug/web/__init__.py @@ -1,5 +1,5 @@ # This file is part of beets. -# Copyright 2011, Adrian Sampson. +# Copyright 2012, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -15,9 +15,11 @@ """A Web interface to beets.""" from beets.plugins import BeetsPlugin from beets import ui +from beets import util import beets.library import flask from flask import g +import os DEFAULT_HOST = '' DEFAULT_PORT = 8337 @@ -26,10 +28,22 @@ DEFAULT_PORT = 8337 # Utilities. def _rep(obj): + """Get a flat -- i.e., JSON-ish -- representation of a beets Item or + Album object. + """ if isinstance(obj, beets.library.Item): out = dict(obj.record) del out['path'] + + # Get the size (in bytes) of the backing file. This is useful + # for the Tomahawk resolver API. + try: + out['size'] = os.path.getsize(util.syspath(obj.path)) + except OSError: + out['size'] = 0 + return out + elif isinstance(obj, beets.library.Album): out = dict(obj._record) del out['artpath'] diff --git a/docs/changelog.rst b/docs/changelog.rst index 005f9733f..c59fa8ea9 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -15,10 +15,14 @@ Changelog * :doc:`/plugins/fetchart`: Fix a bug where cover art filenames could lack a ``.jpg`` extension. * :doc:`/plugins/lyrics`: Fix an exception with non-ASCII lyrics. +* :doc:`/plugins/web`: The API now reports file sizes (for use with the + `Tomahawk resolver`_). * Add the track mapping dictionary to the ``album_distance`` plugin function. * Fix an assertion failure when the MusicBrainz main database and search server disagree. +.. _Tomahawk resolver: http://beets.radbox.org/blog/tomahawk-resolver.html + 1.0b15 (July 26, 2012) ----------------------