-
Notifications
You must be signed in to change notification settings - Fork 0
/
save1-GOOD
executable file
·243 lines (202 loc) · 7.01 KB
/
save1-GOOD
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
#!/bin/bash
#Gets the source of each of the correct cache folders
CHROME_DEFAULT=$(echo ~/Library/Caches/Google/Chrome/Default)
CHROME_MEDIA="${CHROME_DEFAULT}/Media Cache"
CHROME_CACHE=$(echo ~/Library/Caches/Google/Chrome/Default/Cache)
FIREFOX_CACHE=$(echo ~/Library/Caches/Firefox/Profiles/en0nsfkm.default/Cache)
#Finds out how long it should start collecting songs from, if the user didn't enter then it doesn't know
if [ $# -ne 1 ]; then
echo "Usage $0: Please enter how long you've been listening to music" 1>&2
exit 1;
fi
#Creates temporary files for output
fire_part_file=$(mktemp -t /)
tout_file=$(mktemp -t /)
out_file=$(mktemp -t /)
fire_out_file=$(mktemp -t /)
song_file=$(mktemp -t /)
#Used to say if last part of song captured was accepted
#If so then would allow said song to pass
prev=false
#Used as a boolean to see if data file
data=false
#Find all the files largers than 100Kb (b/c of ending of song might be small) and in the user time zone
#and outputs it to a file
find $CHROME_CACHE -size +100k -mmin -$1 -exec ls -ls {} + | awk '{print $10}' > $tout_file
find "$CHROME_MEDIA" -size +100k -mmin -$1 -exec ls -ls {} + | awk '{print $10"\\ "$11}' >> $tout_file
find $FIREFOX_CACHE -size +100k -mmin -$1 -exec ls -ls {} + | awk '{print $10}' >> $fire_part_file
#Progress report
echo "Progress: 15%"
SAVE_IFS=$IFS
IFS=$'\n'
#Currently have bug with for loop reading in word by word so it breaks after Cache (Google Chrome)
for check in `cat $tout_file`; do
#Does a double check to see whether something could possible be converted to audio files
#Based on trial and error, google likes to protect the files
file_check=$(file $check | awk '{print $2}')
echo $file_check
exiftool "$check" | egrep "MP3" > /dev/null
exif_check=$?
#If it's a MPEG it could be part of a larger song - send to out_file
if [ $file_check == MPEG ]; then
echo $check >> $out_file
prev=true
#If it's Audio it's a song unto itself for sure - and has id3 data - send to special song_file
elif [ $file_check == Audio ]; then
echo $check >> $song_file
prev=false
#Otherwise check for special cases for long podcast etc.
elif [ $file_check == data -o $exif_check -eq 0 -o $file_check = DOS -o $file_check == ACB ]; then
#double check file to see if mp3 - figure out how to parse to see if mp3 (for surefire way)
#some files are not passing both tests
#If it passed the first test send to out_file
if [ $exif_check -eq 0 ]; then
echo $check >> $out_file
prev=true
else
#If it didn't past first test try some more checks to see if we can send to out_file
echo $check | egrep "data" > /dev/null
if [ $? -eq 0 ]; then
data=true
else
data=false
fi
#You might be missing a prev=false somewhere in here
if [ $data != true ]; then
egrep "(.*)LAME3.(.*)(UUUUUU)* (.)(.*)" $check > /dev/null
if [ $? -eq 0 ]; then
echo $check >> $out_file
prev=false
elif [ $prev == true ]; then
echo $check >> $out_file
fi
fi
fi
else
#Changes to false if song was not accepted into file
prev=false
fi
#Stating progress
echo -n "."
done
cat $out_file
IFS=$SAVE_IFS
#Used to say if last part of song captured was accepted
#If so then would allow said song to pass
prev=false
#Used as a boolean to see if data file
data=false
for check in `cat $fire_part_file`; do
#echo $check
#Does a double check to see whether something could possible be converted to audio files
#Based on trial and error, google likes to protect the files
file_check=$(file $check | awk '{print $2}')
#exiftool $check | egrep "MP3" > /dev/null
#exif_check=$?
#If it's a MPEG it could be part of a larger song - send to out_file
if [ $file_check == MPEG ]; then
echo $check >> $fire_out_file
#prev=true
#If it's Audio it's a song unto itself for sure - and has id3 data - send to special song_file
elif [ $file_check == Audio ]; then
echo $check >> $song_file
#prev=false
#Otherwise check for special cases for long podcast etc.
else
#Changes to false if song was not accepted into file
prev=false
fi
#Stating progress
echo -n "."
done
echo "."
echo "Progress: 40%"
#If in special song file then make the file's name all that good stuff
for song in `cat $song_file`; do
# used mp3info before
title=$(exiftool $song | egrep "Title" | cut -d ' ' -f 29-)
artist=$(exiftool $song | egrep "Artist" | cut -d ' ' -f 28-)
echo $title
echo $artist
cp $song "${artist} - ${title}.mp3"
cp "${artist} - ${title}.mp3" ~/Music
rm "${artist} - ${title}.mp3"
echo -n "."
done
echo "."
echo "Progress: 60%"
#cat $out_file
#cmp_file=$(mktemp -t /)
#find . -size +100k -mmin -1105 -exec ls -ls {} + | awk '{print $10}' > $cmp_file
#diff $out_file $cmp_file
#: << 'END'
#As stated - the number of songs created
songs=0
#The parts of a song created
parts=0
#Where we store the parts out
parts_out=$(mktemp -t /)
#temp_song=$(mktemp -t /)
#For songs that weren't special
for file in `cat $out_file`; do
#Check to see if the file contains these lines
egrep "(.*)LAME3.(.*)(UUUUUU)* (.)(.*)" $file > /dev/null
#If it did continue here
if [ $? -eq 0 ]; then
#Last file is never MPEG?
if [ `file $file | awk '{print $2}'` == MPEG ]; then
echo $file >> $parts_out
parts=`expr $parts + 1`
else
if [ $parts -eq 0 ]; then
#Create a small song
cp $file "song${songs}.mp3"
cp "song${songs}.mp3" ~/Music
rm "song${songs}.mp3"
echo "Created Small Song: No Parts"
else
#Runs through the parts and combines them together
for part in `cat $parts_out`; do
#echo $part
cat $part >> "song${songs}.mp3"
done
#Adds the current file to the song
cat $file >> "song${songs}.mp3"
#Moves it to the music folder
cp "song${songs}.mp3" ~/Music
rm "song${songs}.mp3"
#Reset the parts out file
parts_out=$(mktemp -t /)
#Not really sure
temp_song=$(mktemp -t /)
echo "Created Large Song"
fi
#Adds 1 to the number of song created
songs=`expr $songs + 1`
fi
#If not add the parts the the parts file to be added to a song later
else
#temp${parts}=file
echo $file >> $parts_out
parts=`expr $parts + 1`
echo -n "."
fi
done
#The parts of a song created
parts=0
#Where we store the parts out
parts_out=$(mktemp -t /)
#temp_song=$(mktemp -t /)
#For songs that weren't special
for file in `cat $fire_out_file`; do
#echo $file
cp $file $(echo ~/Music/song${songs}.mp3)
#cp "song${songs}.mp3" ~/Music
#rm "song${songs}.mp3"
songs=`expr $songs + 1`
echo "Firefox: Created Small Song: No Parts"
done
#Completed
echo "."
echo "Completed"
#END