-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckArtist.sh
More file actions
141 lines (126 loc) · 3.33 KB
/
checkArtist.sh
File metadata and controls
141 lines (126 loc) · 3.33 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
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
#!/bin/bash
basedir=$1
#The exit status is 0 (true) if the pattern was found;
#The exit status is 1 (false) if the pattern was not found.
function check {
artist=$(echo "$1" | tr '[:upper:]' '[:lower:]')
grep -qx "$artist" "$basedir"/MP3Library/everyArtist.txt ; echo $?
}
function checkBad {
artist=$(echo "$1" | tr '[:upper:]' '[:lower:]')
grep -qx "$artist" "$basedir"/MP3Library/artists.txt ; echo $?
}
function checkNewBad {
artist=$(echo "$1" | tr '[:upper:]' '[:lower:]')
grep -qx "$artist" /tmp/tempBadArtists.txt ; echo $?
}
function containsElement () {
local e match="$1"
shift
for e; do [[ "$e" == "$match" ]] && return 0; done
return 1
}
function google {
xdg-open "http://www.google.com/search?q=%20$1"
echo ""
read -n1 delete
echo ""
artist=$(echo "$1" | tr '[:upper:]' '[:lower:]')
if [[ "$delete" == "y" ]]; then
echo "$artist" >> "$basedir"/MP3Library/artists.txt
echo "$artist" >> /tmp/tempBadArtists.txt
fi
echo "$artist" >> "$basedir"/MP3Library/everyArtist.txt
}
function store {
artist=$(echo "$1" | tr '[:upper:]' '[:lower:]')
echo "$artist" >> "$basedir"/MP3Library/artists.txt
echo "$artist" >> /tmp/tempBadArtists.txt
echo "$artist" >> "$basedir"/MP3Library/everyArtist.txt
}
function checkBadArray {
readarray -td, a <<<"$1"; declare -p a;
for artistName in "${a[@]}"
do
artistName=$(echo "$artistName" | xargs)
artistName=$(echo "$artistName" | tr -d '\n')
if [[ $(checkBad "$artistName") -eq 0 ]]; then
store "$1"
echo "bad artists: $artistName ........."
break
fi
if [[ $(checkNewBad "$artistName") -eq 0 ]]; then
store "$1"
echo "bad artists: $artistName ........."
break
fi
done
}
function arrayArtists {
artist=$(echo "$1" | tr '[:upper:]' '[:lower:]')
checkBadArray "${artist}"
readarray -td, a <<<"$artist"; declare -p a;
for artistName in "${a[@]}"
do
artistName=$(echo "$artistName" | xargs)
artistName=$(echo "$artistName" | tr -d '\n')
if [[ $(check "$artistName") -eq 1 ]]; then
echo "$artistName"
echo "y for search, a for add"
read -n1 userInput
echo ""
if [[ "$userInput" == "y" ]]; then
google "$artistName"
elif [[ "$userInput" == "a" ]]; then
store "$artistName"
else
artistName=$(echo "$artistName" | tr '[:upper:]' '[:lower:]')
echo "$artistName" >> "$basedir"/MP3Library/everyArtist.txt
fi
fi
done
checkBadArray "${artist}"
echo "$artist" >> "$basedir"/MP3Library/everyArtist.txt
}
function add {
artist="$1"
echo "$artist"
if [[ "$artist" == *,* ]]; then
arrayArtists "$artist"
else
echo "y for search, s for split, a for add"
read -n1 userInput
echo ""
if [[ "$userInput" == "y" ]]; then
google "$artist"
#elif [[ "$userInput" == "s" ]]; then
# arrayArtists "$artist"
elif [[ "$userInput" == "a" ]]; then
store "$artist"
elif [[ "$userInput" == "x" ]]; then
echo ""
else
artist=$(echo "$artist" | tr '[:upper:]' '[:lower:]')
echo "$artist" >> "$basedir"/MP3Library/everyArtist.txt
fi
fi
}
function iterate {
for f in "."/*
do
if [[ -d "$f" ]]; then
cd "$f"
iterate
cd ..
elif [[ -f "$f" ]]; then
artist=$(mp3infov2 -p %a "$f")
artist=$(echo "$artist" | awk -F '.feat' '{print $1}')
artist=$(tr ';' ',' <<<"$artist")
artist=$(tr '&' ";" <<<"$artist")
if [[ $(check "$artist") -eq 1 ]]; then
add "$artist"
fi
fi
done
}
iterate