-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilities.sh
273 lines (226 loc) · 4.7 KB
/
utilities.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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#!/bin/bash
function check_file {
touch temp
ls ~ > temp
while read line
do
if [[ $line == "music" ]]
then
rm -rf temp
return 1
fi
done < temp
rm -rf temp
return 0
}
# random
function random_song {
n=0
while read line;
do
n=$(( $n + 1 ))
done < ~/music/song_locations
num=$(( ( RANDOM % $n ) + 1 ))
n=0
while read line;
do
n=$(( $n + 1 ))
if [[ $n -eq $num ]]
then
IFS=" | "
set $line
IFS=" "
nvlc $1
fi
done < ~/music/song_locations
}
# search by singer
function search_by_singer {
touch temp
grep -i "$1" ~/music/song_data > temp
echo
echo
echo "Songs by $1 are : "
echo "-----------------------"
n=1
IFS=" | "
while read line;
do
set $line
echo "$n : $4"
n=$(( $n + 1 ))
done < temp
echo -n "Enter the song number to be played : "
read song_num
n=0
while read line;
do
n=$(( $n + 1 ))
if [[ $n -eq $song_num ]]
then
IFS=" | "
set $line
IFS=" "
song_loc=`grep -i $4 ~/music/song_locations`
nvlc $song_loc
fi
done < temp
IFS=" "
}
# search by album name
function search_by_album {
touch temp
grep -i $1 ~/music/song_data > temp
echo
echo
echo "Songs in the $1 album are : "
echo "-------------------------------"
n=1
IFS=" | "
while read line;
do
set $line
echo "$n : $4"
n=$(( $n+1 ))
done < temp
echo -n "Enter the song number to be played : "
read song_num
n=0
while read line;
do
n=$(( $n+1 ))
if [[ $n -eq $song_num ]]
then
IFS=" | "
set $line
IFS=" "
song_loc=`grep -i $4 ~/music/song_locations`
nvlc $song_loc
fi
done < ~/music/song_data
IFS=" "
}
# search by keyword
function search_by_keyword {
touch temp
grep -i $1 ~/music/song_data > temp
echo "Songs containing $1 in some sense are : "
echo "------------------------------------------"
IFS=" | "
n=1
while read line;
do
set $line
echo "$n : $4"
n=$(( $n+1 ))
done < temp
echo -n "Enter the song number to be played : "
read song_num
n=0
while read line;
do
n=$(( $n+1 ))
if [[ $n -eq $song_num ]]
then
IFS=" | "
set $line
IFS=" "
song_loc=`grep -i $4 ~/music/song_locations`
nvlc $song_loc
fi
done < ~/music/song_data
IFS=" "
}
# open directory
function open_dir {
song_name=$1
touch temp
grep -i $song_name ~/music/song_data > temp
IFS=" | "
while read line;
do
set $line
IFS=" "
xdg-open $2
done < temp
rm -rf temp
}
function scan_songs {
cd ~
rm -rf music/song_data music/song_names music/song_locations
check_file
if [[ $? == "0" ]]
then
mkdir ~/music
touch ~/music/song_locations
fi
cd ~
find ~ -name "*.mp3" > ~/music/song_locations
while read line;
do
entry=""
entry+=$line
entry+=" | "
IFS=" "
touch song_meta1
touch meta1
location=$line
# mediainfo $line
mediainfo $line > meta1
grep -i performer meta1 > song_meta1
grep -i album meta1 >> song_meta1
IFS=":"
while read line1;
do
set $line1
entry+="$2"
entry+=" | "
done < song_meta1
rm -rf meta1 song_meta1
IFS="/"
read -r -a arr <<< "$line"
song_name=${arr[-1]}
entry+=${song_name}
entry+=" | "
echo $song_name >> ~/music/song_names
echo $entry >> ~/music/song_data
done < ~/music/song_locations
rm -rf temp
} # add genre as well
function list_songs {
echo
echo
touch temp
cat ~/music/song_names > temp
n=0
while read line;
do
n=$(( $n + 1 ))
if [[ $n%4 -eq 0 ]]
then
echo "$n : $line "
else
echo -n "$n : $line "
fi
done < temp
echo
echo
rm -rf temp
}
# deleted_list
function deleted_songs {
touch ~/music/deleted_song_list
echo $1 >> ~/music/deleted_song_list
IFS="/"
while read line;
do
read -r -a arr <<< $line
song_name=${arr[-1]}
if [[ song_name == $1 ]]
then
rm -rf $line
scan_songs
fi
done < ~/music/song_data
IFS=" "
}