1. Adrian Sampson
  2. beets


Adrian Sampson  committed 9ae0f66

fix inline for album plugin fields (#274)

  • Participants
  • Parent commits a9f65be
  • Branches default

Comments (0)

Files changed (1)

File beetsplug/inline.py

View file
 import traceback
 from beets.plugins import BeetsPlugin
+from beets.library import Item, Album
 from beets import config
 log = logging.getLogger('beets')
     eval(code, env)
     return env[FUNC_NAME]
+def _record(obj):
+    """Get a dictionary of values for an Item or Album object.
+    """
+    if isinstance(obj, Item):
+        return dict(obj.record)
+    else:
+        return dict(obj._record)
 def compile_inline(python_code):
     """Given a Python expression or function body, compile it as a path
     field function. The returned function takes a single argument, an
     if is_expr:
         # For expressions, just evaluate and return the result.
-        def _expr_func(item):
-            values = dict(item.record)
+        def _expr_func(obj):
+            values = _record(obj)
                 return eval(code, values)
             except Exception as exc:
         # For function bodies, invoke the function with values as global
         # variables.
-        def _func_func(item):
-            func.__globals__.update(item.record)
+        def _func_func(obj):
+            func.__globals__.update(_record(obj))
                 return func()
             except Exception as exc: