~q3cpma/mus

ref: e99afe099fd0b6cf6a4cce58902c9612ecd9fca9 mus/mus_album_db_create -rwxr-xr-x 1.4 KiB
e99afe09q3cpma Finish build.sh and README, move TODO to root 1 year, 27 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh
# Dependencies:
# Portability:  POSIX
set -eu
rpath_bin=$(dirname -- "$0")
rpath_share=$(dirname -- "$0")
. "$rpath_share"/mus_util.sh


usage()
{
	cat <<EOF | text_format
**NAME**
    $(basename -- "$0") - Album db creator

**SYNOPSIS**
    $(basename -- "$0") [**-h**] [**-d** __FILE__] [__MUSIC_DIR__...]

**DESCRIPTION**
    Create an album database by searching in the __MUSIC_DIR__ arguments. If no
    __MUSIC_DIR__ is given, \$__MUS_MUSIC_DIR__ is used. The database lines
    format is "play_count album_absolute_path".

**OPTIONS**
    **-h**
        Print this notice and exit.

    **-d** __FILE__
        Set the album database path. Override the \$__MUS_ALBUM_DB__ environment
        variable.

**ENVIRONMENT**
    __MUS_ALBUM_DB__
        Album database path. Defaults to
        \${XDG_CONFIG_HOME:-\$HOME/.config}/mus/album_db.

    __MUS_MUSIC_DIR__
        Music directory. Defaults to \$HOME/Music.

EOF
	exit $1
}

album_db=${MUS_ALBUM_DB:-${XDG_CONFIG_HOME:-$HOME/.config}/mus/album_db}

while getopts "d:h" OPT
do
	case "$OPT" in
		d)
			album_db=$OPTARG
			;;
		h)
			usage 0
			;;
		\?)
			usage 1
			;;
	esac
done
shift $((OPTIND - 1))

forbidfile "$album_db"
[ $# -eq 0 ] && set -- "${MUS_MUSIC_DIR:-$HOME/Music}"

mkdir -p -- "$(dirname -- "$album_db")"
"$rpath_bin"/mus_album_find "$@" | LC_ALL=C sort | sed 's#^#0 #' | \
	flock -- "$album_db" sh -c 'cat >"$1"' dummy "$album_db"