Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use XDG_DATA_HOME and XDG_CACHE_HOME if defined for UID and DB #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pacien
Copy link

@pacien pacien commented Jul 7, 2020

… Falling back to standard locations then the script's shared directory otherwise.

GitHub: closes #16

Falling back to standard locations then the script's shared directory otherwise.
scripts_dir = mp.find_config_file("scripts")
local scripts_dir = mp.find_config_file("scripts")
local home_dir = os.getenv("HOME")
local data_dir = os.getenv("XDG_DATA_HOME") or home_dir and utils.join_path(home_dir, ".local/share") or scripts_dir

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't make it fallback to home, maybe we can do something like this instead https://github.com/hishamhm/datafile/blob/master/datafile/openers/unix.lua

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I'm misreading, this never falls back to ~ and the preference order is:

  • ${XDG_DATA_HOME}
  • ${HOME}/.local/share
  • scripts_dir

@robertgzr
Copy link

this is also missing windows support... is that required @po5? look at the repo i linked they have https://github.com/hishamhm/datafile/blob/master/datafile/openers/windows.lua

not sure if APPDATA is the correct place to put this?

@po5
Copy link
Owner

po5 commented May 6, 2023

I didn't merge this PR since it's obvious it'll break on tons of systems.
You should not be trying to make up paths, they should come from a source of truth.
This is why the script queries mpv for the path, because it knows better than anyone where mpv scripts go.

@robertgzr
Copy link

agreed, but I don't think putting state into mpv's script directory is great either 😛

i don't think mpv exposes it's state/cache directories via the plugin api, so if we want to improve on the current situation the xdg paths (and their equivalent on other platforms) seem like a sane choice?

@defaultxr
Copy link

mpv's options support shortcuts for various paths. Maybe the directory could be an option for mpv_sponsorblock that defaults to ~~cache/mpv_sponsorblock/ or similar.

@mesvam
Copy link

mesvam commented Apr 27, 2024

I'm not sure why this dir is named "shared". No other users, scripts, or programs will be using this dir right? The only real requirement is that it be writable.

this is also missing windows support... is that required @po5? look at the repo i linked they have https://github.com/hishamhm/datafile/blob/master/datafile/openers/windows.lua

not sure if APPDATA is the correct place to put this?

On Windows, standard for user-specific app configs is %APPDATA%. %LOCALAPPDATA% is typically used for cache and temporary files, but can also be used for permanent storage. Both are generally writable, the main difference is %APPDATA% may be synced across multiple systems while %LOCALAPPDATA% is local to a specific machine, but this syncing feature is rarely used. Cache and temporary files are supposed to be in %TEMP%. mpv uses %APPDATA%\mpv for it's config dir by default.

If you wanted to do everything "by-the-book", I would say sponsorblock.db should go in %LOCALAPPDATA%\\mpv_sponsorblock and sponsorblock.txt should go in %APPDATA%\mpv_sponsorblock, but that is probably too much trouble for no real benefit.

I would say the best location for both files on Windows is simply the script directory, %APPDATA%\mpv\scripts\sponsorblock. You'll want to move the script itself into that dir as main.lua as well #66

nbraud added a commit to nbraud/mpv_sponsorblock that referenced this pull request May 1, 2024
This is the most platform-independent way, and fixes things
for users who have a global scripts directory. (see po5#66)

Closes po5#17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Write data to a standard writable directory for cache data
6 participants