-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfoobar2000
executable file
·159 lines (153 loc) · 4.51 KB
/
foobar2000
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env bash
# set RUN_FOOBAR2000 in ~/.foobar2000.conf
[[ -r "${HOME}"/.foobar2000.conf ]] && . "${HOME}"/.foobar2000.conf
RUN_FOOBAR2000="${RUN_FOOBAR2000:-wine ${HOME}/.wine/drive_c/Program Files/foobar2000}"
canonicalise () {
filename="${1}"
# prefix replacement
case "${1}" in
/*)
# absolute, nothing to do.
;;
~*)
# home-relative and for some odd reason calling shell
# didnt expand this already (for ex. it was quoted).
filename="${HOME}/${filename}"
;;
*)
# relative path.
filename="$(pwd)/${filename}"
;;
esac
# strip './' elements
filename=$(echo "${filename}" | sed -e 's:/\./:/:g')
# strip 'foo/../' elements
filename=$(echo "${filename}" | sed -e 's:/[^/]\+/\.\./:/:g')
# protect real backslashes
filename=$(echo "${filename}" | sed -e 's:\\:\\\\:g')
file="${filename}"
unset filename
}
get_filenames() {
local file
local -a files
while (( ${#} )); do
canonicalise "${1}"
if [[ -d "${file}" ]]; then
files=( "${files[*]}" "$(find ${file} \! -type d)" )
else
files=( "${files[*]}" "${file}" )
fi
shift
done
echo "${files[*]}"
}
case "${1}" in
-add)
shift
if [[ -n ${1} ]]; then
canonicalise "${1}"
${RUN_FOOBAR2000}/foobar2000.exe /add "z:$file" & &>/dev/null
echo "Action: adding Directory or Files \"${file}\" to foobar2000"
fi
;;
-addfiles)
shift
if (( ${#} )); then
files=( "$(get_filenames ${@})" )
while (( ${#files[*]} )); do
file="${files[0]}"
${RUN_FOOBAR2000}/foobar2000.exe /add "z:${file}" & &>/dev/null
echo "Action: adding $(echo ${file})"
shift files
done
echo "Result: added "$(( ${#} ))" files to foobar2000"
fi
;;
-play)
${RUN_FOOBAR2000}/foobar2000.exe /play & &>/dev/null
echo "Action: play Song in foobar2000"
;;
-pause)
${RUN_FOOBAR2000}/foobar2000.exe /pause & &>/dev/null
echo "Action: pause Song in foobar2000"
;;
-playpause)
${RUN_FOOBAR2000}/foobar2000.exe /playpause & &>/dev/null
echo "Action: play or pause Song in foobar2000"
;;
-prev)
${RUN_FOOBAR2000}/foobar2000.exe /prev & &>/dev/null
echo "Action: play previous Song in foobar2000"
;;
-next)
${RUN_FOOBAR2000}/foobar2000.exe /next & &>/dev/null
echo "Action: play next Song in foobar2000"
;;
-rand)
${RUN_FOOBAR2000}/foobar2000.exe /rand & &>/dev/null
echo "Action: play random Song in foobar2000"
;;
-stop)
${RUN_FOOBAR2000}/foobar2000.exe /stop & &>/dev/null
echo "Action: stop playing a Song in foobar2000"
;;
-mute)
${RUN_FOOBAR2000}/foobar2000.exe /command:Volume\ mute & &>/dev/null
echo "Action: mute foobar2000"
;;
-volup)
${RUN_FOOBAR2000}/foobar2000.exe /command:Volume\ up & &>/dev/null
echo "Action: raise Volume in foobar2000"
;;
-voldown)
${RUN_FOOBAR2000}/foobar2000.exe /command:Volume\ down & &>/dev/null
echo "Action: decrease Volume in foobar2000"
;;
-hide)
${RUN_FOOBAR2000}/foobar2000.exe /hide & &>/dev/null
echo "Action: hide foobar2000 window"
;;
-show)
${RUN_FOOBAR2000}/foobar2000.exe /show & &>/dev/null
echo "Action: show foobar2000 window"
;;
-exit)
${RUN_FOOBAR2000}/foobar2000.exe /exit & &>/dev/null
echo "Action: exit foobar2000"
;;
-rescan)
${RUN_FOOBAR2000}/foobar2000.exe /command:"Rescan Media Library" & &>/dev/null
echo "Action: Rescan foobar2000 Media Library"
;;
-command-*)
[[ -n ${1} ]] && command=${1##*command-}
${RUN_FOOBAR2000}/foobar2000.exe /command:"${command}" & &>/dev/null
echo "Action: call foobar2000 with command \"$command\""
;;
-playlist_command-*)
[[ -n ${1} ]] && command=${1##*command-}
${RUN_FOOBAR2000}/foobar2000.exe /playlist_command:"${command}" & &>/dev/null
echo "Action: call foobar2000 with playlist command \"$command\""
;;
-playing_command-*)
[[ -n ${1} ]] && command=${1##*command-}
${RUN_FOOBAR2000}/foobar2000.exe /playing_command:"${command}" & &>/dev/null
echo "Action: call foobar2000 with playing command \"$command\""
;;
-help)
echo "Using: foobar2000 [Command]
Where Command can be on of these:
-add -addfiles -play -pause -playpause -stop -next -prev -rand -mute -volup -voldown -hide -show -rescan -command-[fb2k command] -playlist_command-[fb2k playlist command] -playing_command-[fb2k playing command] -help"
;;
*)
if [[ -n ${1} ]]; then
canonicalise "${1}"
${RUN_FOOBAR2000}/foobar2000.exe "z:${file}" & &>/dev/null
echo "Action: start foobar2000 with file ${file}"
else
${RUN_FOOBAR2000}/foobar2000.exe & &>/dev/null
echo "Action: start foobar2000"
fi
;;
esac