-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.sh
executable file
·192 lines (156 loc) · 4.41 KB
/
index.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
#!/bin/bash
#
#
dir='mp3'
log='log'
title='html/index-titles.html'
album='html/index-albums.html'
artist='html/index-artists.html'
track='html/index-tracks.html'
year='html/index-years.html'
time='html/index-times.html'
file='html/index-files.html'
ul='html/index-ul.html'
index='index.html'
index_new='html/index.html'
index_head='html/index-head.html'
index_tail='html/index-tail.html'
index_old='html/index-old.html'
ranges='log/titles-range.csv'
mp3list='log/mp3-list.csv'
echo 'cleaning up temp folders...'
rm -f $title
rm -f $album
rm -f $artist
rm -f $year
rm -f $track
rm -f $time
rm -f $file
rm -f $ul
rm -f $index_new
rm -f $ranges
# list | sort | group
echo 'list all mp3s and generate metadata files from them...'
find $dir -name "*.mp3" | sort -r > $mp3list # list all mp3 files, latest first
while read i ; do
j=$(echo $i | cut -d'/' -f2|cut -d'.' -f1)
id3file="$log/$j.id3" # generate id3 metadata files
eyeD3 --no-color $i > $id3file
mkdir -p "$log/$j"
echo "write embedded images to...$log/$j"
eyeD3 -i "$log/$j" $i
cp "$log/$j/FRONT_COVER.jpeg" "jpg/final_covers/$j.jpg"
done < $mp3list
echo 'loop through metadata files...'
while read i ; do
n=$(echo $i | cut -d'/' -f2|cut -d'.' -f1)
csv="$log/$n.csv"
id3file="$log/$n.id3"
echo "reading id3 file... $id3file"
cover_image="jpg/album_covers/null.jpg"
generated_cover="jpg/final_covers/$n.jpg"
if [ -e "$generated_cover" ] ; then
cover_image=$generated_cover
fi
art=""
tit=""
alb=""
yea=""
tim=""
lyr=""
rm -f "$log/$n.lyr"
while read j ; do
ltitle=$(echo $j | grep title) # TITLE
if [ "$ltitle" != "" ] ; then
tit=$(echo $j | cut -d':' -f2)
titcc=$(echo $tit|wc -m)
titcc=$(($titcc-7))
tit=$(echo $tit|cut -c -$titcc|cut -c 1-)
art=$(echo $j | cut -d':' -f3|cut -c 2-) # ARTIST
fi
ltime=$(echo $j | grep Time) # TIME
if [ "$ltime" != "" ] ; then
tim=$(echo $j | cut -d' ' -f2)
fi
lya=$(echo $j | grep album) # YEAR
if [ "$lya" != "" ] ; then # ALBUM
alb=$(echo $j | cut -d':' -f2)
albcc=$(echo $alb|wc -m)
albcc=$(($albcc-5))
alb=$(echo $alb|cut -c -$albcc|cut -c 1-)
yea=$(echo $j | cut -d':' -f3|cut -c 2-) # ARTIST
fi
lyr=$(echo $j | grep '^[0-9]') # LYRICS
if [ "$lyr" != "" ] ; then
echo $lyr >> "$log/$n.lyr"
else
lyr=""
#alb=$(echo $j | cut -d' ' -f2)
fi # ALBUM
# if [ "$alb" != "" ] ; then
#alb=$(echo $j | cut -d' ' -f3)
#fi
done < $id3file
# CORRECTIONS
if [ "$tit" = "" ] ; then
tit=$n
tit=$(echo $tit | cut -d'.' -f1 | sed 's/-/ /g' | sed 's/_/ /g')
fi
echo "" >> "$log/$n.lyr"
echo "title: $tit"
echo "artist: $art"
echo "time : $tim"
echo "year : $yea"
echo "album : $alb"
echo "lyrics:"
cat "$log/$n.lyr"
echo "<li>" >> $ul
echo "<a href=\"#\"><img src=\"$cover_image\" width=\"100px\" height=\"100px\" alt=\"Cover image\" class=\"img_left\"></a>" >> $ul
echo "<div class=\"article\">" >> $ul
echo "<p class=\"text_article\">$art</p>" >> $ul
echo "<p class=\"title_article\">$alb</p>" >> $ul
echo "<p class=\"title_article\">$tit</p>" >> $ul
echo "<p class=\"text_article\">$tim</p>" >> $ul
echo "<p class=\"text_article\"> <br>" >> $ul
echo "<audio controls src=\"mp3/$n.mp3\"></audio>" >> $ul
echo "</p>" >> $ul
# if [ "$lyr" != "" ] ; then
echo "<p class=\"text_article\">" >> $ul
numlyr=$(cat "$log/$n.lyr" | wc -l)
numlyr=$(($numlyr-1))
a="1"
while read i ; do
#echo "numlyr: $numlyr a: $a"
if [ "$numlyr" = "$a" ] ; then
# echo "got end."
echo "$i" >> $ul
break
else
echo "$i<br>" >> $ul
fi
a=$(($a+1))
done < "$log/$n.lyr"
echo "</p>" >> $ul
echo '<br>' >> $ul
echo "<a title=\"Download\" class=\"button right_download\" href=\"mp3/$n.mp3\">" >> $ul
echo "<span class=\"before\"></span>Download<span class=\"after\"></span>" >> $ul
echo "</a>" >> $ul
echo '<br><br>' >> $ul
echo "</div>" >> $ul
echo "<div class=\"separator\"></div>" >> $ul
echo "</li>" >> $ul
done < $mp3list
echo "wrote entries file to... $ul"
echo "concat + copy files..."
cat $index_head >> $index_new
cat $ul >> $index_new
cat $index_tail >> $index_new
#cat $index_new
cp $index $index_old
cp $index_new $index
while read i ; do
j=$(echo $i | cut -d'/' -f2|cut -d'.' -f1)
rm -Rif "$log/$j"
done < $mp3list
echo 'finished. index.html generated.'
exit 0