aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-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")