-
Notifications
You must be signed in to change notification settings - Fork 1
/
convert-songs-2.18.2.sh
executable file
·51 lines (41 loc) · 1.72 KB
/
convert-songs-2.18.2.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
mkdir converted_songs
cd songs
for file in *; do
if [ -f "$file" ]; then
# Create a dir and convert the song
base_filename=`basename "${file%.*}"`
output_directory_name="../converted_songs/${base_filename}"
mkdir "${output_directory_name}"
/home/runner/bin/lilypond -dbackend=svg -o "$output_directory_name" "$file"
# Get svg_file
svg_file=$(basename "$output_directory_name"/*.svg)
# Get the metadata from the score
score=$(grep -A 10 '\\score' $file)
# Get title from score
title=$(echo "$score" | grep -o 'title = "[^"]*"' | sed 's/title = "//;s/"//')
# Get composer
composer=$(echo "$score" | grep -o 'composer = "[^"]*"' | sed 's/composer = "//;s/"//')
# If the metadata was unavailable from the score it can be found in the htitle & hcomposer
if [ -z "$title" ]; then
title=$(grep 'htitle=' $file | sed 's/htitle="\(.*\)"/\1/')
composer=$(grep 'hcomposer=' $file | sed 's/hcomposer="\(.*\)"/\1/')
fi
# Outfile
metadata_filename="${output_directory_name}/${base_filename}.md"
# Write the metadata
echo -e "---" >> "$metadata_filename"
echo -e "title: $title" >> "$metadata_filename"
echo -e "author: $composer" >> "$metadata_filename"
echo -e "svgFiles:" >> "$metadata_filename"
for svg_file in "$output_directory_name"/*.svg; do
svg_filename="$(basename "$svg_file")"
echo -e " - $svg_filename" >> "$metadata_filename"
done
echo -e "midiFiles:" >> "$metadata_filename"
for midi_file in "$output_directory_name"/*.midi; do
midi_filename="$(basename "$midi_file")"
echo -e " - $midi_filename" >> "$metadata_filename"
done
echo -e "---" >> "$metadata_filename"
fi
done