diff options
author | Wolfgang Müller | 2024-09-19 18:51:08 +0200 |
---|---|---|
committer | Wolfgang Müller | 2024-09-19 18:51:08 +0200 |
commit | 3cf32bc82c44e656c1d1753c0a14ac98dde26692 (patch) | |
tree | 24623a1646828a7129d4f2054302ef1303b35f34 | |
parent | 1040bed83b94cbc18338773a1faa8110c4090ee7 (diff) | |
download | later-3cf32bc82c44e656c1d1753c0a14ac98dde26692.tar.gz |
Use function to determine XDG directories
We do the same thing here twice, so this seems worth it.
Diffstat (limited to '')
-rwxr-xr-x | later | 16 |
1 files changed, 9 insertions, 7 deletions
@@ -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") |