-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkplaylist
60 lines (49 loc) · 1.61 KB
/
mkplaylist
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
#!/bin/zsh
# Copyright 2015 Han Boetes <[email protected]>
# For license info see http://unlicense.org/
# This script generates a very simple database of all my music files.
unset LC_ALL
export LC_COLLATE=C
export LANG=en_US.UTF-8
config="~/.config/muzshic/config"
if [[ -r ${~config} ]]; then
source ${~config}
else
print 'run genconfig to generate a configuration file.' >&2
exit 0
fi
touch $playlist.new.gz || exit 1
if [[ $1 == -f ]]; then
database=($(find ${~database} -maxdepth 1 -mindepth 1 -type d -mmin -60))
if [[ -n "$database" ]]; then
database=($(find ${~database} -maxdepth 1 -mindepth 1 -type d -mmin -60))
fi
if [[ -z "$database" ]]; then
echo "No new files found."
exit 0
fi
fi
# Generate the search options for find from the supported filetypes
for i in $filetypes; do
st="$st -name '*'.$i -o"
done
# remove trailing -o
st=${st% -o}
unset progress
if command -v pv >& /dev/null; then
lines=$(zcat $playlist|wc -l)
progress='| pv -l -s $lines'
fi
# set -x
time eval find ${~database} -type f $st $progress | sort -n | gzip -c > $playlist.new.gz
# set +x
if [[ $1 == -f ]]; then
zcat $playlist $playlist.new.gz | sort -n | gzip -c > $playlist.newest.gz
mv $playlist.newest.gz $playlist.new.gz
fi
if [ -e $playlist ] && [[ -n $TERM ]]; then
# If zdiff returns an error, it's because a difference has been found.
(zdiff -u $playlist $playlist.new.gz || : ) | diff-so-fancy | less --tabs=4 -RFX || print "Consider installing diff and diff-so-fancy" >&2
fi
mv -f ${playlist}.new.gz $playlist
[[ -n $TERM ]] && zgrep -iE '\.(wav|ape)$' $playlist