aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorWolfgang Müller2024-09-19 18:51:08 +0200
committerWolfgang Müller2024-09-19 18:51:08 +0200
commit3cf32bc82c44e656c1d1753c0a14ac98dde26692 (patch)
tree24623a1646828a7129d4f2054302ef1303b35f34
parent1040bed83b94cbc18338773a1faa8110c4090ee7 (diff)
downloadlater-3cf32bc82c44e656c1d1753c0a14ac98dde26692.tar.gz
Use function to determine XDG directories
We do the same thing here twice, so this seems worth it.
-rwxr-xr-xlater16
1 files changed, 9 insertions, 7 deletions
diff --git a/later b/later
index 4b0a55b..9ae72a3 100755
--- a/later
+++ b/later
@@ -8,16 +8,18 @@ import re
import sys
from datetime import datetime as dt
-xdg_state_home = os.path.expanduser("~/.local/state")
-if "XDG_STATE_HOME" in os.environ:
- xdg_state_home = os.environ["XDG_STATE_HOME"]
-watch_later_dir = os.path.join(xdg_state_home, "mpv/watch_later")
+def get_xdg(type, fallback):
+ env = f"XDG_{type.upper()}_HOME"
+ if env in os.environ:
+ return os.environ[env]
+ return os.path.expanduser(fallback)
+
-xdg_cache_home = os.path.expanduser("~/.cache")
-if "XDG_CACHE_HOME" in os.environ:
- xdg_cache_home = os.environ["XDG_CACHE_HOME"]
+xdg_cache_home = get_xdg("cache", "~/.cache")
+xdg_state_home = get_xdg("state", "~/.local/state")
+watch_later_dir = os.path.join(xdg_state_home, "mpv/watch_later")
later_cache_dir = os.path.join(xdg_cache_home, "later")
title_map_file = os.path.join(later_cache_dir, "titles.json")