Move functions only needed by audiod from stat.c to audiod_command.c.
[paraslash.git] / convert_0.3-0.4.sh
1 #!/usr/bin/env bash
2
3 #-------------------------------------------------------------------------------
4 ## Script to convert the database of paraslash 0.3.5 to version 0.4.x.
5 ##
6 ## Assumptions:
7 ## - para_server 0.3.5 is running
8 ## - "para_client check" reports no errors
9 ## - para_server 0.4.x is running, listens on another port and uses a
10 ## different afs database and a different afs socket
11 ## - The database of paraslash 0.4.x has been initialized (i.e.
12 ## para_client init has successfully been executed)
13 ## - All audio files in the 0.3.x database have already been added to
14 ## the 0.4.x database (execute para_client add /my/audio/file/dir to
15 ## do that)
16 ##
17 #-------------------------------------------------------------------------------
18
19 # Call this script without arguments to see usage info
20
21 # How to connect to para_server 0.3.x.
22 client03=/usr/local/bin/para_client
23 port03=2991
24 host03=localhost
25 database03=$HOME/.paraslash/afs_database
26
27 # How to connect to para_server 0.4.x.
28 client04=$(pwd)/para_client
29 port04=2990
30 host04=localhost
31 database04=$HOME/.paraslash/afs_database-0.4
32
33 # Any character that does not occur in any filename of an audio file
34 sep='|'
35
36
37 client03_cmd="$client03 -p $port03 -i $host03"
38 client04_cmd="$client04 -p $port04 -i $host04"
39
40 exec_client03_cmd()
41 {
42 result="$($client03_cmd -- "$@")"
43 }
44
45 exec_client04_cmd()
46 {
47 result="$($client04_cmd -- "$@")"
48 }
49
50 convert_attribute_table()
51 {
52 local atts
53
54 echo "converting attribute table"
55 exec_client03_cmd lsatt
56 atts="$result"
57 exec_client04_cmd addatt $atts
58 }
59
60 convert_attributes()
61 {
62 local OIFS="$IFS" a p att atts
63
64 printf "converting attributes: "
65 $client03_cmd -- ls -p -lv \
66 | grep '^path:\|^attributes_txt:' \
67 | sed -e "/^path:/N;s/\n/$sep/1" \
68 | {
69 IFS="$sep"
70 while read p a; do
71 p=${p#path: }
72 a=${a#attributes_txt:}
73 IFS=" "
74 atts=
75 for att in $a; do
76 atts="$atts $att+"
77 done
78 IFS="$OIFS"
79 [[ -n "$atts" ]] && $client04_cmd -- setatt $atts "$p"
80 IFS="$sep"
81 printf "."
82 done
83 echo done
84 }
85 IFS="$OIFS"
86 }
87
88 convert_lna()
89 {
90 local OIFS="$IFS" p l n a
91
92 printf "converting last_played, num_played, amplification values: "
93 $client03_cmd -- ls -p -d -lv \
94 | grep '^path:\|^last_played: \|^num_played: \|^amplification: ' \
95 | sed -e "/^path:/N;N;N;s/\n/$sep/g" \
96 | {
97 IFS="$sep"
98 while read p l n a; do
99 #echo "p: $p, l:$l, n:$n a:$a"
100 p=${p#path: }
101 l=${l#last_played: }
102 n=${n#num_played: }
103 a=${a#amplification: }
104 IFS="$OIFS"
105 $client04_cmd -- touch "-l$l" "-n$n" "-a$a" "$p"
106 IFS="$sep"
107 printf "."
108 done
109 echo done
110 }
111 IFS="$OIFS"
112 }
113
114 convert_blobs()
115 {
116 local blob name
117
118 for blob in img lyr mood pl; do
119 printf "converting $blob table: "
120 exec_client03_cmd ls$blob
121 echo "$result" | while read name; do
122 $client03_cmd -- cat$blob "$name" | $client04_cmd -- add$blob "$name"
123 printf "."
124 done
125 echo done
126 done
127 }
128
129 convert_ids()
130 {
131 local OIFS="$IFS" p i y iopts yopts
132
133 printf "converting image and lyrics ids: "
134 $client03_cmd -- ls -p -lv \
135 | grep '^path:\|^image_name: \|^lyrics_name: ' \
136 | sed -e "/^path:/N;N;s/\n/$sep/g" \
137 | {
138 IFS="$sep"
139 while read p i l; do
140 IFS="$OIFS"
141 iopts=
142 yopts=
143 p=${p#path: }
144 i=${i#image_name: }
145 l=${l#lyrics_name: }
146 if [[ "$i" != '(none)' ]]; then
147 exec_client04_cmd lsimg -l "$i"
148 iopts="-i${result%% *}"
149 fi
150 if [[ "$l" != '(none)' ]]; then
151 exec_client04_cmd lslyr -l "$l"
152 yopts="-y${result%% *}"
153 fi
154 if [[ -n "$iopts" && -n "$yopts" ]]; then
155 $client04_cmd -- touch "$iopts" "$yopts" "$p"
156 elif [[ -n "$iopts" ]]; then
157 $client04_cmd -- touch "$iopts" "$p"
158 elif [[ -n "$yopts" ]]; then
159 $client04_cmd -- touch "$yopts" "$p"
160 fi
161 printf "."
162 IFS="$sep"
163 done
164 echo done
165 }
166 IFS="$OIFS"
167 }
168
169
170 usage()
171 {
172 grep '^##' $0 | sed -e 's/^## *//'
173 echo '
174 Usage: $0 command
175
176 command is one of the following:
177
178 attribute_table: create attributes
179 attributes: convert attributes for each audio file
180 lna: convert the last_played/num_played/amplification values
181 blobs: convert the image/lyrics/moods/playlists tables
182 ids: convert image and the lyrics id of each audio file.
183 all: Do all of the above.
184
185 Edit the top of the script to customize some options.
186 '
187 }
188
189 if test $# -ne 1; then
190 usage
191 exit 1
192 fi
193
194 case "$1" in
195 attribute_table)
196 convert_attribute_table
197 ;;
198 attributes)
199 convert_attributes
200 ;;
201 lna)
202 convert_lna
203 ;;
204 blobs)
205 convert_blobs
206 ;;
207 ids)
208 convert_ids
209 ;;
210 all)
211 convert_attribute_table
212 convert_attributes
213 convert_lna
214 convert_blobs
215 convert_ids
216 ;;
217 *)
218 usage
219 exit 1
220 ;;
221 esac