drop global XDG_CONFIG_DIR and use environment variables

+ handle string explicit flags
This commit is contained in:
cwilvx
2025-05-25 19:01:10 +03:00
parent 4a741d9ffc
commit f4bc525ae4
7 changed files with 152 additions and 28 deletions
-1
View File
@@ -116,5 +116,4 @@ class UserConfig:
if key.startswith("_") or not self._config_path:
return
print(f"writing to file: {key}={value}")
self.write_to_file(asdict(self))
+3 -1
View File
@@ -255,7 +255,9 @@ def get_tags(filepath: str, config: UserConfig):
)
metadata["trackhash"] = create_hash(
metadata.get("artists", ""), metadata.get("album", ""), metadata.get("title", "")
metadata.get("artists", ""),
metadata.get("album", ""),
metadata.get("title", ""),
)
extra: dict[str, Any] = {
+8 -1
View File
@@ -84,8 +84,15 @@ class Track:
self.og_album = self.album
self.folder = self.folder + "/"
self.weakhash = create_hash(self.title, self.artists)
explicit_tag = self.extra.get("explicit", ["0"])
self.explicit = int(explicit_tag[0]) == 1
if isinstance(explicit_tag, list):
explicit_tag = explicit_tag[0] if explicit_tag else "0"
if isinstance(explicit_tag, str):
explicit_tag = explicit_tag.lower()
self.explicit = explicit_tag in ("1", "yes", "true")
else:
self.explicit = bool(explicit_tag)
self.image = self.albumhash + ".webp" + "?pathhash=" + self.pathhash
# self.extra = {
+2 -4
View File
@@ -18,7 +18,6 @@ else:
class Paths:
XDG_CONFIG_DIR = ""
USER_HOME_DIR = os.path.expanduser("~")
# TODO: Break this down into getter methods for each path
@@ -30,9 +29,8 @@ class Paths:
@classmethod
def get_config_dir(cls):
return (
cls.XDG_CONFIG_DIR
or os.environ.get("SWINGMUSIC_XDG_CONFIG_DIR")
or os.path.realpath(".")
# cls.XDG_CONFIG_DIR
os.environ.get("SWINGMUSIC_XDG_CONFIG_DIR") or os.path.realpath(".")
)
@classmethod