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

Beets should respect $XDG_MUSIC_DIR #5168

Open
sebastianrasor opened this issue Mar 30, 2024 · 9 comments · May be fixed by #5333
Open

Beets should respect $XDG_MUSIC_DIR #5168

sebastianrasor opened this issue Mar 30, 2024 · 9 comments · May be fixed by #5333
Labels
feature features we would like to implement

Comments

@sebastianrasor
Copy link

By default beets is configured to use ~/Music unless otherwise specified. I think that the order of preference should be as follows:

  1. directory as configured in config.yaml
  2. $XDG_MUSIC_DIR if it exists
  3. $HOME/Music
@wisp3rwind wisp3rwind added the feature features we would like to implement label Mar 30, 2024
@bal-e
Copy link

bal-e commented Jun 14, 2024

While I love the XDG directory specification, I've seen it cause a lot of trouble in other open-source projects due to backward compatibility issues. I expect that anybody who sets $XDG_MUSIC_DIR to something other than $HOME/Music will not have a $HOME/Music directory. There are two options here:

  1. Immediately use the proposed directory order. This could potentially break things for a very, very small proportion of users.
  2. Release a minor version which shows a warning for users for whom things would break, and actually adopt the proposed directory order in the next minor version.
    I'm happy to try implementing either case but I want input from maintainers first.

@xeruf
Copy link

xeruf commented Jun 22, 2024

Those users who have set this variable will use a non-standard configuration anyways, so I would not be concerned with backwards compatibility - that is only a problem if the fallback is not reasonable or the config options are not properly prioritised.

However, the right directory to use for xdg is xdg-user-dir MUSIC - I have never seen a $XDG_MUSIC_DIR variable. I think you are referencing https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html while the right one is https://www.freedesktop.org/wiki/Software/xdg-user-dirs/

@sebastianrasor
Copy link
Author

Those users who have set this variable will use a non-standard configuration anyways, so I would not be concerned with backwards compatibility - that is only a problem if the fallback is not reasonable or the config options are not properly prioritised.

However, the right directory to use for xdg is xdg-user-dir MUSIC - I have never seen a $XDG_MUSIC_DIR variable. I think you are referencing https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html while the right one is https://www.freedesktop.org/wiki/Software/xdg-user-dirs/

XDG_MUSIC_DIR is a part of the standard.
man 5 user-dirs.dirs

DESCRIPTION
       The $HOME/.config/user-dirs.dirs file is a text file that contains the user-specific values for
       the XDG user dirs. It is created and updated by the xdg-user-dirs-update command.

       This file contains lines of the form

           XDG_NAME_DIR=VALUE

       The following names are recognised:

           VALUE must be of the form "$HOME/Path" or "/Path".

           Lines beginning with a # character are ignored.

           The format of user-dirs.dirs is designed to allow direct sourcing of this file in shell
           scripts.

cat /etc/xdg/user-dirs.defaults

# Default settings for user directories
#
# The values are relative pathnames from the home directory and
# will be translated on a per-path-element basis into the users locale
DESKTOP=Desktop
DOWNLOAD=Downloads
TEMPLATES=Templates
PUBLICSHARE=Public
DOCUMENTS=Documents
MUSIC=Music
PICTURES=Pictures
VIDEOS=Videos
# Another alternative is:
#MUSIC=Documents/Music
#PICTURES=Documents/Pictures
#VIDEOS=Documents/Videos

@sebastianrasor
Copy link
Author

sebastianrasor commented Jun 22, 2024

I expect that anybody who sets $XDG_MUSIC_DIR to something other than $HOME/Music will not have a $HOME/Music directory. There are two options here:

If they set XDG_MUSIC_DIR to something other than $HOME/Music then under the preference order I recommended, it would not matter as XDG_MUSIC_DIR would be used and $HOME/Music would never be considered.

@xeruf
Copy link

xeruf commented Jun 22, 2024

XDG_MUSIC_DIR is a part of the standard.

yes, but by default it is not an environment variable unlike the XDG base dirs, as explained in the spec too:

❯ xdg-user-dir MUSIC
/home/janek/data/4-media/music
❯ echo $XDG_MUSIC_DIR

just to keep in mind when implementing

@sebastianrasor
Copy link
Author

Oh that makes sense. Thanks for the clarification!

@bal-e
Copy link

bal-e commented Jun 22, 2024

If they set XDG_MUSIC_DIR to something other than $HOME/Music then under the preference order I recommended, it would not matter as XDG_MUSIC_DIR would be used and $HOME/Music would never be considered.

@sebastianrasor to be more explicit, here's an example:

A user has set XDG_MUSIC_DIR (through xdg-user-dir, thanks @xeruf) to $HOME/AllTheMusic, and uses $HOME/Music for beets without explicitly putting it in the beets config. This may happen, for example, if the user has some untagged music they don't want beets messing with, and they didn't know that they could change the directory beets uses. Now, with this change, beets will implicitly start using $HOME/AllTheMusic, leading to some possibly confusing errors. I agree that it's far-fetched, but I wanted it at least noted before this feature goes through (and to be clear, I want this feature).

@bal-e
Copy link

bal-e commented Jun 25, 2024

I haven't been able to find any utility to parse user-dirs.dirs(5), so I'll probably write a small utility module to parse it into a dict[str, pathlib.Path]. The only other change would be to change Library.__init__'s default value for directory.

@jn64
Copy link

jn64 commented Jun 25, 2024

The $HOME/.config/user-dirs.dirs file is a text file that [...]

Note the user-dirs.dirs(5) manpage is wrong/incomplete on the file location.

The xdg-user-dir shell script reads from $XDG_CONFIG_HOME/user-dirs.dirs (falling back to ~/.config/user-dirs.dirs if $XDG_CONFIG_HOME is undefined). Please do the same in your implementation.

bal-e pushed a commit to bal-e/beets that referenced this issue Jun 25, 2024
Fixes beetbox#5168.  Beets will now look for a music directory as follows:

1. Configuration in 'config.yaml'.
2. On Unix-like systems, 'XDG_MUSIC_DIR' in 'user-dirs.dirs'.
3. The fallback '~/Music'.
@bal-e bal-e linked a pull request Jun 25, 2024 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature features we would like to implement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants