@@ -354,10 +354,27 @@ class LibModel(dbcore.Model["Library"]):
354
354
def writable_media_fields (cls ) -> set [str ]:
355
355
return set (MediaFile .fields ()) & cls ._fields .keys ()
356
356
357
+ @property
358
+ def genre (self ) -> str :
359
+ _type : types .DelimitedString = self ._type ("genres" )
360
+ return _type .to_sql (self .get ("genres" ))
361
+
362
+ @genre .setter
363
+ def genre (self , value : str ) -> None :
364
+ self .genres = value
365
+
366
+ @classmethod
367
+ def _getters (cls ):
368
+ return {
369
+ "genre" : lambda m : cls ._fields ["genres" ].delimiter .join (m .genres )
370
+ }
371
+
357
372
def _template_funcs (self ):
358
- funcs = DefaultTemplateFunctions (self , self ._db ).functions ()
359
- funcs .update (plugins .template_funcs ())
360
- return funcs
373
+ return {
374
+ ** DefaultTemplateFunctions (self , self ._db ).functions (),
375
+ ** plugins .template_funcs (),
376
+ "genre" : "$genres" ,
377
+ }
361
378
362
379
def store (self , fields = None ):
363
380
super ().store (fields )
@@ -533,7 +550,7 @@ class Item(LibModel):
533
550
"albumartists_sort" : types .MULTI_VALUE_DSV ,
534
551
"albumartist_credit" : types .STRING ,
535
552
"albumartists_credit" : types .MULTI_VALUE_DSV ,
536
- "genre " : types .STRING ,
553
+ "genres " : types .SEMICOLON_SPACE_DSV ,
537
554
"style" : types .STRING ,
538
555
"discogs_albumid" : types .INTEGER ,
539
556
"discogs_artistid" : types .INTEGER ,
@@ -614,7 +631,7 @@ class Item(LibModel):
614
631
"comments" ,
615
632
"album" ,
616
633
"albumartist" ,
617
- "genre " ,
634
+ "genres " ,
618
635
)
619
636
620
637
_types = {
@@ -689,10 +706,12 @@ def _cached_album(self, album):
689
706
690
707
@classmethod
691
708
def _getters (cls ):
692
- getters = plugins .item_field_getters ()
693
- getters ["singleton" ] = lambda i : i .album_id is None
694
- getters ["filesize" ] = Item .try_filesize # In bytes.
695
- return getters
709
+ return {
710
+ ** plugins .item_field_getters (),
711
+ "singleton" : lambda i : i .album_id is None ,
712
+ "filesize" : Item .try_filesize , # In bytes.
713
+ "genre" : lambda i : cls ._fields ["genres" ].delimiter .join (i .genres ),
714
+ }
696
715
697
716
def duplicates_query (self , fields : list [str ]) -> dbcore .AndQuery :
698
717
"""Return a query for entities with same values in the given fields."""
@@ -768,6 +787,10 @@ def get(self, key, default=None, with_album=True):
768
787
769
788
Set `with_album` to false to skip album fallback.
770
789
"""
790
+ if key in dir (self ) and isinstance (
791
+ getattr (self .__class__ , key ), property
792
+ ):
793
+ return getattr (self , key )
771
794
try :
772
795
return self ._get (key , default , raise_ = with_album )
773
796
except KeyError :
@@ -1181,7 +1204,7 @@ class Album(LibModel):
1181
1204
"albumartists_sort" : types .MULTI_VALUE_DSV ,
1182
1205
"albumartists_credit" : types .MULTI_VALUE_DSV ,
1183
1206
"album" : types .STRING ,
1184
- "genre " : types .STRING ,
1207
+ "genres " : types .SEMICOLON_SPACE_DSV ,
1185
1208
"style" : types .STRING ,
1186
1209
"discogs_albumid" : types .INTEGER ,
1187
1210
"discogs_artistid" : types .INTEGER ,
@@ -1215,7 +1238,7 @@ class Album(LibModel):
1215
1238
"original_day" : types .PaddedInt (2 ),
1216
1239
}
1217
1240
1218
- _search_fields = ("album" , "albumartist" , "genre " )
1241
+ _search_fields = ("album" , "albumartist" , "genres " )
1219
1242
1220
1243
_types = {
1221
1244
"path" : PathType (),
@@ -1237,7 +1260,7 @@ class Album(LibModel):
1237
1260
"albumartist_credit" ,
1238
1261
"albumartists_credit" ,
1239
1262
"album" ,
1240
- "genre " ,
1263
+ "genres " ,
1241
1264
"style" ,
1242
1265
"discogs_albumid" ,
1243
1266
"discogs_artistid" ,
@@ -1293,10 +1316,12 @@ def relation_join(cls) -> str:
1293
1316
def _getters (cls ):
1294
1317
# In addition to plugin-provided computed fields, also expose
1295
1318
# the album's directory as `path`.
1296
- getters = plugins .album_field_getters ()
1297
- getters ["path" ] = Album .item_dir
1298
- getters ["albumtotal" ] = Album ._albumtotal
1299
- return getters
1319
+ return {
1320
+ ** super ()._getters (),
1321
+ ** plugins .album_field_getters (),
1322
+ "path" : Album .item_dir ,
1323
+ "albumtotal" : Album ._albumtotal ,
1324
+ }
1300
1325
1301
1326
def items (self ):
1302
1327
"""Return an iterable over the items associated with this
0 commit comments