LibModel#

class beets.library.LibModel(db: D | None = None, **values)[source]#

Bases: Model[Library]

Shared concrete functionality for Items and Albums.

__init__(db: D | None = None, **values)#

Create a new object with an optional Database association and initial field values.

Public methods summary

add([lib])

Add the object to the library database.

all_keys()

Get a list of available keys for objects of this type.

any_field_query(*args, **kwargs)

any_writable_media_field_query(*args, **kwargs)

clear_dirty()

Mark all fields as clean (i.e., not needing to be stored to the database).

copy()

Create a copy of the model object.

duplicates_query(fields)

Return a query for entities with same values in the given fields.

evaluate_template(template[, for_path])

Evaluate a template (a string or a Template object) using the object's fields.

field_query(field, pattern, query_cls)

Get a FieldQuery for the given field on this model.

formatted([included_keys, for_path])

Get a mapping containing all values on this object formatted as human-readable unicode strings.

get(key[, default, raise_])

Get the value for a field, or default.

get_fresh_from_db()

Load this object from the database.

items()

Iterate over (key, value) pairs that this object contains.

keys([computed])

Get a list of available field names for this object.

load()

Refresh the object's metadata from the library database.

remove()

Remove the object's associated rows from the database.

set_parse(key, string)

Set the object's key to a value represented by a string.

store([fields])

Save the object's metadata into the library database.

update(values)

Assign all values in the given dict.

Methods definition

property filepath: Path#

The path to the entity as pathlib.Path.

store(fields=None)[source]#

Save the object's metadata into the library database. :param fields: the fields to be stored. If not specified, all fields will be.

remove()[source]#

Remove the object's associated rows from the database.

add(lib=None)[source]#

Add the object to the library database. This object must be associated with a database; you can provide one via the db parameter or use the currently associated database.

The object's id and added fields are set along with any current field values.

classmethod field_query(field: str, pattern: str, query_cls: FieldQueryType) FieldQuery[source]#

Get a FieldQuery for the given field on this model.

duplicates_query(fields: list[str]) AndQuery[source]#

Return a query for entities with same values in the given fields.

classmethod all_keys()#

Get a list of available keys for objects of this type. Includes fixed and computed fields.

clear_dirty()#

Mark all fields as clean (i.e., not needing to be stored to the database). Also update the revision.

copy() Model#

Create a copy of the model object.

The field values and other state is duplicated, but the new copy remains associated with the same database as the old object. (A simple copy.deepcopy will not work because it would try to duplicate the SQLite connection.)

property db: D#

Get the database associated with this object.

This validates that the database is attached and the object has an id.

evaluate_template(template: str | Template, for_path: bool = False) str#

Evaluate a template (a string or a Template object) using the object's fields. If for_path is true, then no new path separators will be added to the template.

formatted(included_keys: str = '*', for_path: bool = False) FormattedMapping#

Get a mapping containing all values on this object formatted as human-readable unicode strings.

get(key, default: Any = None, raise_: bool = False)#

Get the value for a field, or default. Alternatively, raise a KeyError if the field is not available.

get_fresh_from_db() Self#

Load this object from the database.

items() Iterator[tuple[str, Any]]#

Iterate over (key, value) pairs that this object contains. Computed fields are not included.

keys(computed: bool = False)#

Get a list of available field names for this object. The computed parameter controls whether computed (plugin-provided) fields are included in the key list.

load()#

Refresh the object's metadata from the library database.

If check_revision is true, the database is only queried loaded when a transaction has been committed since the item was last loaded.

set_parse(key, string: str)#

Set the object's key to a value represented by a string.

update(values)#

Assign all values in the given dict.