mirror of
https://github.com/beetbox/beets.git
synced 2025-12-15 21:14:19 +01:00
web: add size to item JSON in API
This is to be used by the Tomahawk resolver, which wants file sizes.
This commit is contained in:
parent
6200f0a4c8
commit
473fe04f91
2 changed files with 19 additions and 1 deletions
|
|
@ -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']
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
----------------------
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue