-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpdhist.in
118 lines (107 loc) · 2.27 KB
/
mpdhist.in
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/sh
#
# $Id: mpdhist.in,v 1.5 2024-03-11 16:47:12+05:30 Cprogrammer Exp mbhangui $
#
usage()
{
cat 1>&2 <<EOF
Usage: mpdhist [OPTION]
Known values for OPTION are:
-l limit
--limit=limit
Finds song with uri matching path
-r
--reverse
Reverse the order with song heard first
at the top
-h
--help
display this help and exit
EOF
exit $1
}
get_mpd_conf_value()
{
grep "^$1" @sysconfdir@/mpd.conf|awk '{print $2}' | \
sed -e 's{"{{g'
}
process_cmdline()
{
OPTS=$(getopt -o l:hr --long limit:,help,reverse -- "$@")
if [ $? -ne 0 ] ; then
usage 1
fi
#echo "OPTS=$OPTS"
#echo "args=$@"
eval set -- "$OPTS"
while true; do
case "$1" in
-l|--limit)
limit=$2
shift 2
;;
-r|--reverse)
do_rev=1
shift
;;
-h|--help)
usage 0
;;
--)
shift
break
;;
*)
echo "invalid option [$1]" 1>&2
usage 1;
break
;;
esac
done
}
limit=24
do_rev=0
process_cmdline "$@"
music_dir=`get_mpd_conf_value music_directory`
if [ $? -ne 0 ] ; then
echo "could not get music directory from mpd.conf" 1>&2
exit 1
fi
sticker_file=`get_mpd_conf_value sticker_file`
if [ $? -ne 0 ] ; then
echo "could not get sticker database from mpd.conf" 1>&2
exit 1
fi
stats_dir=$(dirname $sticker_file)
stats_file=$stats_dir/stats.db
stmt=""
stmt="$stmt select id, title, artist, album, play_count, rating, "
stmt="$stmt strftime('%d-%m-%Y %H:%M:%S', datetime(last_played, 'unixepoch', 'localtime')) "
if [ $do_rev -eq 0 ] ; then
stmt="$stmt from song where last_played is NOT NULL and play_count > 0 order by last_played DESC LIMIT $limit"
else
stmt="$stmt from song where last_played is NOT NULL and play_count > 0 order by last_played ASC LIMIT $limit"
fi
sqlite3 -header -batch -column $stats_file "$stmt" | \
sed \
-e 's/[ \t]\+$//' \
-e 's{strftime.*${Last Played{' \
-e 's{ -*${ ==================={'
#
# $Log: mpdhist.in,v $
# Revision 1.5 2024-03-11 16:47:12+05:30 Cprogrammer
# removed rompr
#
# Revision 1.4 2022-09-26 21:15:59+05:30 Cprogrammer
# removed debug statement
#
# Revision 1.3 2022-09-26 21:12:59+05:30 Cprogrammer
# added -r option to show earliest played song first
#
# Revision 1.2 2022-09-26 20:18:34+05:30 Cprogrammer
# pass -header option to sqlite3
#
# Revision 1.1 2022-09-26 19:11:08+05:30 Cprogrammer
# Initial revision
#
#