| 1 |
from confuse import ConfigValueError |
| 2 |
|
| 3 |
from beets.dbcore import types |
| 4 |
from beets.plugins import BeetsPlugin |
| 5 |
|
| 6 |
|
| 7 |
class TypesPlugin(BeetsPlugin): |
| 8 |
@property |
| 9 |
def item_types(self) -> dict[str, types.Type]: |
| 10 |
return self._types() |
| 11 |
|
| 12 |
@property |
| 13 |
def album_types(self) -> dict[str, types.Type]: |
| 14 |
return self._types() |
| 15 |
|
| 16 |
def _types(self) -> dict[str, types.Type]: |
| 17 |
if not self.config.exists(): |
| 18 |
return {} |
| 19 |
|
| 20 |
mytypes: dict[str, types.Type] = {} |
| 21 |
for key, value in self.config.items(): |
| 22 |
if value.get() == "int": |
| 23 |
mytypes[key] = types.INTEGER |
| 24 |
elif value.get() == "float": |
| 25 |
mytypes[key] = types.FLOAT |
| 26 |
elif value.get() == "bool": |
| 27 |
mytypes[key] = types.BOOLEAN |
| 28 |
elif value.get() == "date": |
| 29 |
mytypes[key] = types.DATE |
| 30 |
else: |
| 31 |
raise ConfigValueError( |
| 32 |
f"unknown type '{value}' for the '{key}' field" |
| 33 |
) |
| 34 |
return mytypes |