diff --git a/fastanime/__init__.py b/fastanime/__init__.py index 0b6f432..e0a90cb 100644 --- a/fastanime/__init__.py +++ b/fastanime/__init__.py @@ -6,7 +6,7 @@ if sys.version_info < (3, 10): ) # noqa: F541 -__version__ = "v1.6.0" +__version__ = "v1.6.1" APP_NAME = "FastAnime" AUTHOR = "Benex254" diff --git a/fastanime/constants.py b/fastanime/constants.py index 2fe1c4c..554a743 100644 --- a/fastanime/constants.py +++ b/fastanime/constants.py @@ -3,12 +3,19 @@ import sys from pathlib import Path from platform import system +from plyer import storagepath + from . import APP_NAME, AUTHOR, __version__ PLATFORM = system() # ---- app deps ---- -APP_DIR = os.path.abspath(os.path.dirname(__file__)) +try: + APP_DIR = storagepath.get_application_dir() # pyright:ignore +except Exception: + APP_DIR = None +if not APP_DIR: + APP_DIR = os.path.abspath(os.path.dirname(__file__)) CONFIGS_DIR = os.path.join(APP_DIR, "configs") ASSETS_DIR = os.path.join(APP_DIR, "assets") @@ -24,10 +31,18 @@ PREVIEW_IMAGE = os.path.join(ASSETS_DIR, "preview") # ----- user configs and data ----- S_PLATFORM = sys.platform - +try: + app_data_dir_base = None + video_dir_base = storagepath.get_videos_dir() # pyright:ignore + cache_dir_base = None +except Exception: + video_dir_base = None + cache_dir_base = None + app_data_dir_base = None if S_PLATFORM == "win32": # app data - app_data_dir_base = os.getenv("LOCALAPPDATA") + if not app_data_dir_base: + app_data_dir_base = os.getenv("LOCALAPPDATA") if not app_data_dir_base: raise RuntimeError("Could not determine app data dir please report to devs") APP_DATA_DIR = os.path.join(app_data_dir_base, AUTHOR, APP_NAME) @@ -36,38 +51,45 @@ if S_PLATFORM == "win32": APP_CACHE_DIR = os.path.join(APP_DATA_DIR, "cache") # videos dir - video_dir_base = os.path.expanduser("~/Videos") + if not video_dir_base: + video_dir_base = os.path.expanduser("~/Videos") USER_VIDEOS_DIR = os.path.join(video_dir_base, APP_NAME) elif S_PLATFORM == "darwin": # app data - app_data_dir_base = os.path.expanduser("~/Library/Application Support") + if not app_data_dir_base: + app_data_dir_base = os.path.expanduser("~/Library/Application Support") APP_DATA_DIR = os.path.join(app_data_dir_base, APP_NAME, __version__) # cache dir - cache_dir_base = os.path.expanduser("~/Library/Caches") + if not cache_dir_base: + cache_dir_base = os.path.expanduser("~/Library/Caches") APP_CACHE_DIR = os.path.join(cache_dir_base, APP_NAME, __version__) # videos dir - video_dir_base = os.path.expanduser("~/Movies") + if not video_dir_base: + video_dir_base = os.path.expanduser("~/Movies") USER_VIDEOS_DIR = os.path.join(video_dir_base, APP_NAME) else: # app data - app_data_dir_base = os.environ.get("XDG_CONFIG_HOME", "") - if not app_data_dir_base.strip(): - app_data_dir_base = os.path.expanduser("~/.config") + if not app_data_dir_base: + app_data_dir_base = os.environ.get("XDG_CONFIG_HOME", "") + if not app_data_dir_base.strip(): + app_data_dir_base = os.path.expanduser("~/.config") APP_DATA_DIR = os.path.join(app_data_dir_base, APP_NAME) # cache dir - cache_dir_base = os.environ.get("XDG_CACHE_HOME", "") - if not cache_dir_base.strip(): - cache_dir_base = os.path.expanduser("~/.cache") + if not cache_dir_base: + cache_dir_base = os.environ.get("XDG_CACHE_HOME", "") + if not cache_dir_base.strip(): + cache_dir_base = os.path.expanduser("~/.cache") APP_CACHE_DIR = os.path.join(cache_dir_base, APP_NAME) # videos dir - video_dir_base = os.environ.get("XDG_VIDEOS_DIR", "") - if not video_dir_base.strip(): - video_dir_base = os.path.expanduser("~/Videos") + if not video_dir_base: + video_dir_base = os.environ.get("XDG_VIDEOS_DIR", "") + if not video_dir_base.strip(): + video_dir_base = os.path.expanduser("~/Videos") USER_VIDEOS_DIR = os.path.join(video_dir_base, APP_NAME) # ensure paths exist diff --git a/pyproject.toml b/pyproject.toml index 2ff493e..982799e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "fastanime" -version = "1.6.0.dev1" +version = "1.6.1.dev1" description = "A browser anime site experience from the terminal" authors = ["Benextempest "] license = "UNLICENSE"