MCPcopy
hub / github.com/beetbox/beets / _rep

Function _rep

beetsplug/web/__init__.py:46–81  ·  view source on GitHub ↗

Get a flat -- i.e., JSON-ish -- representation of a beets Item or Album object. For Albums, `expand` dictates whether tracks are included.

(obj, expand=False)

Source from the content-addressed store, hash-verified

44
45
46def _rep(obj, expand=False):
47 """Get a flat -- i.e., JSON-ish -- representation of a beets Item or
48 Album object. For Albums, `expand` dictates whether tracks are
49 included.
50 """
51 out = dict(obj)
52
53 if isinstance(obj, beets.library.Item):
54 if app.config.get("INCLUDE_PATHS", False):
55 out["path"] = util.displayable_path(out["path"])
56 else:
57 del out["path"]
58
59 # Filter all bytes attributes and convert them to strings.
60 for key, value in out.items():
61 if isinstance(out[key], bytes):
62 out[key] = base64.b64encode(value).decode("ascii")
63
64 # Get the size (in bytes) of the backing file. This is useful
65 # for the Tomahawk resolver API.
66 try:
67 out["size"] = os.path.getsize(util.syspath(obj.path))
68 except OSError:
69 out["size"] = 0
70
71 return out
72
73 if isinstance(obj, beets.library.Album):
74 if app.config.get("INCLUDE_PATHS", False):
75 out["artpath"] = util.displayable_path(out["artpath"])
76 else:
77 del out["artpath"]
78 if expand:
79 out["items"] = [_rep(item) for item in obj.items()]
80 return out
81 return None
82
83
84def json_generator(items, root, expand=False):

Callers 3

json_generatorFunction · 0.85
responderFunction · 0.85
item_at_pathFunction · 0.85

Calls 2

getMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected