-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path.bashrc_squeezebox
More file actions
114 lines (100 loc) · 3.15 KB
/
.bashrc_squeezebox
File metadata and controls
114 lines (100 loc) · 3.15 KB
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
# ~/.bashrc_squeezebox
# ======================================================================
# Bash shell configuration - Squeezebox and Lyrion Music Server controls
# Copyright (c) Corey Goldberg (https://github.com/cgoldberg)
# ======================================================================
LMS_URL="http://10.0.0.100:9000"
SQUEEZEBOX_MAC="00:04:20:23:82:6f"
# send request to LMS JSON-RPC API
send-squeezebox-cmd () {
local command="$1"
local payload='{
"method": "slim.request",
"params": [
"'"${SQUEEZEBOX_MAC}"'",
'"${command}"'
]
}'
lms_result="$(
curl \
--fail \
--ipv4 \
--silent \
--retry 0 \
--connect-timeout 3 \
--max-time 30 \
--data "${payload}" \
"${LMS_URL}/jsonrpc.js"
)"
if [ -z "${lms_result}" ]; then
err "can't reach LMS or Squeezebox"
return 1
fi
}
# show currently playing track on Squeezebox player
squeezebox-show () {
if send-squeezebox-cmd '["status", "-", 1, "tags:a"]'; then
jq -r '.result.playlist_loop | .[0] | "\(.artist) - \(.title)"' \
<<< "${lms_result}" \
| awk '{print "\033[1m" $0 "\033[0m"}'
fi
}
alias s=squeezebox-show
# skip to next track in playlist on Squeezebox player
squeezebox-next () {
if send-squeezebox-cmd '["button", "jump_fwd"]'; then
squeezebox-show
fi
}
alias n=squeezebox-next
# play random song mix on Squeezebox player
squeezebox-mix () {
if send-squeezebox-cmd '["randomplay", "tracks"]'; then
squeezebox-show
fi
}
alias m="squeezebox-mix"
# pause/play audio on Squeezebox player
squeezebox-pause () {
send-squeezebox-cmd '["pause"]'
}
alias p="squeezebox-pause"
# send POST request rescan music library
send-squeezebox-rescan () {
local music_dir=$(printf '%s' "$1" | sed -e 's/ /%20/g' -e 's/\//%2F/g')
local payload
printf -v payload '%s' \
"page=BASIC_SERVER_SETTINGS&" \
"pref_libraryname=Lyrion+Music+Server&" \
"pref_mediadirs0=%2Fmusic%2F${music_dir}&" \
"pref_ignoreInAudioScan0=1&" \
"pref_mediadirs1=&" \
"pref_ignoreInAudioScan1=1&" \
"pref_playlistdir=&" \
"pref_rescantype=2wipedb&" \
"pref_rescan=Rescan&" \
"pageAntiCSRFToken=&" \
"saveSettings=1"
lms_result="$(
curl \
--fail \
--ipv4 \
--silent \
--retry 0 \
--connect-timeout 3 \
--max-time 30 \
--data "${payload}" \
"${LMS_URL}/default/settings/server/basic.html"
)"
if [ -z "${lms_result}" ]; then
err "can't reach LMS or Squeezebox"
return 1
fi
echo "scanning '$(printf '%b' "${1//%/\\x}")' library ..."
}
alias rescan-concerts="send-squeezebox-rescan 'Concerts'"
alias rescan-edm="send-squeezebox-rescan 'EDM'"
alias rescan-flac="send-squeezebox-rescan 'FLAC'"
alias rescan-hiphop="send-squeezebox-rescan 'HipHop'"
alias rescan-mp3="send-squeezebox-rescan 'MP3'"
alias rescan-howard="send-squeezebox-rescan 'Audio/Howard Stern'"