-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_playlist.sh
41 lines (37 loc) · 1.21 KB
/
generate_playlist.sh
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
#!/bin/sh
## generate rhythmbox playlist from folders in directory
## url encode taken from pure bash bible
urlencode() {
# Usage: urlencode "string"
local LC_ALL=C
for (( i = 0; i < ${#1}; i++ )); do
: "${1:i:1}"
case "$_" in
[a-zA-Z0-9.~_-])
printf '%s' "$_"
;;
*)
printf '%%%02X' "'$_"
;;
esac
done
printf '\n'
}
fout="rhythmbox_partial_playlist.xml"
echo -n "" > $fout;
exec >> $fout;
for dir in *; do
if [[ -d "$dir" ]]; then
dir_escaped=$(urlencode_safe='/' urlencode "$dir")
printf "<playlist name=\"%s\" show-browser=\"true\" browser-position=\"180\" search-type=\"search-match\" type=\"automatic\" sort-key=\"Artist\" sort-direction=\"0\">\n" "$dir";
echo "<conjunction>";
printf "<equals prop=\"type\">song</equals>\n";
echo "<subquery>";
echo "<conjunction>";
printf "<like prop=\"location\">%s</like>\n" "$dir_escaped";
echo "</conjunction>";
echo "</subquery>";
echo "</conjunction>";
echo "</playlist>";
fi
done