-
Notifications
You must be signed in to change notification settings - Fork 0
/
mplaylist.sh
executable file
·54 lines (44 loc) · 1.48 KB
/
mplaylist.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
#!/usr/bin/env bash
set -eEu -o pipefail
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd -P)"
usage() { printf "%s" "\
Usage: ./mplaylist.sh [-h] FILE
"; exit 0;
}
if [ "$1" == "-h" ]; then
usage
fi
FILE=$1
OUTPUT_FILE="$DIR/files/04_result-mplaylist.csv"
OUTPUT_FILE_MISSING="$DIR/files/05_result-mplaylist-missing.csv"
if [ -f $OUTPUT_FILE ]; then
printf "File $OUTPUT_FILE exists. Deleting.\n"
rm $OUTPUT_FILE
fi
if [ -f $OUTPUT_FILE_MISSING ]; then
printf "File $OUTPUT_FILE_MISSING exists. Deleting.\n"
rm $OUTPUT_FILE_MISSING
fi
printf "Replacing double quotes in file $FILE.\n"
sed -i 's/"//g' $FILE
while read name; do
artist="$(awk -F " - " '{printf $1}' <<<$name)"
track="$(awk -F " - " '{printf $2}' <<<$name)"
# remove leading whitespace characters
artist="${artist#"${artist%%[![:space:]]*}"}"
# remove trailing whitespace characters
artist="${artist%"${artist##*[![:space:]]}"}"
# remove leading whitespace characters
track="${track#"${track%%[![:space:]]*}"}"
# remove trailing whitespace characters
track="${track%"${track##*[![:space:]]}"}"
# printf "mpc search ((artist == \"$artist\") AND (title == \"$track\"))\n"
potential_tracks=$(mpc search "((artist == \"$artist\") AND (title == \"$track\"))")
if [[ $potential_tracks ]]; then
printf "$potential_tracks\n" >> $OUTPUT_FILE
else
printf "Track $artist - $track not found in mpd database.\n"
printf "$artist - $track\n" >> $OUTPUT_FILE_MISSING
fi
done < "$FILE"
#done < "$FILE" | head -n 15