2323# Also artistids are not used, but they are in the database.
2424
2525
26- ARTIST_SEPARATORS : list [str ] = get_config ().data .gui .library .artist_separators
26+ def artist_separators () -> list [str ]:
27+ return get_config ().data .gui .library .artist_separators
2728
2829
29- def _split_pattern (separators : list [str ]) -> str :
30+ def split_pattern (separators : list [str ]) -> str :
3031 return "|" .join (map (re .escape , separators ))
3132
3233
33- ARTIST_SPLIT_PATTERN = _split_pattern (ARTIST_SEPARATORS )
34-
35-
3634def get_artists_polars (table : str , artist : str | None = None ) -> pl .LazyFrame :
3735 """Get all artists from the database using polars.
3836
@@ -62,8 +60,10 @@ def get_artists_polars(table: str, artist: str | None = None) -> pl.LazyFrame:
6260
6361 # Split the artist string by the specified separators
6462 artists : list [str ] | None
65- if len (ARTIST_SEPARATORS ) > 0 and artist is not None :
66- artists = [a .strip () for a in re .split (ARTIST_SPLIT_PATTERN , artist )]
63+ if len (artist_separators ()) > 0 and artist is not None :
64+ artists = [
65+ a .strip () for a in re .split (split_pattern (artist_separators ()), artist )
66+ ]
6767 elif artist is not None :
6868 artists = [artist .strip ()]
6969 else :
@@ -99,14 +99,14 @@ def get_artists_polars(table: str, artist: str | None = None) -> pl.LazyFrame:
9999 df = df .with_columns ((pl .col ("added" ) * 1000 ).alias ("added" ))
100100
101101 # Split artist strings into lists and explode into separate rows
102- if len (ARTIST_SEPARATORS ) > 0 :
102+ if len (artist_separators () ) > 0 :
103103 # split does not yet support regex...
104104 # see https://github.com/pola-rs/polars/issues/4819
105105 # we do a replace workaround
106106 df = df .with_columns (
107107 pl .col ("artist" )
108108 .str .replace_all ("\uffff " , "" )
109- .str .replace_all (ARTIST_SPLIT_PATTERN , "\uffff " )
109+ .str .replace_all (split_pattern ( artist_separators ()) , "\uffff " )
110110 .str .split ("\uffff " )
111111 ).explode ("artist" )
112112
@@ -122,7 +122,7 @@ def get_artists_polars(table: str, artist: str | None = None) -> pl.LazyFrame:
122122
123123 if artists is not None :
124124 # If an artist is specified, filter the result
125- pattern = _split_pattern (artists )
125+ pattern = split_pattern (artists )
126126 df = df .filter (pl .col ("artist" ).str .contains (pattern , literal = False ))
127127 # Overwrite if there are multiple artists (i.e. joined by a separator)
128128 if len (artists ) > 1 :
0 commit comments