This repository has been archived by the owner on Jun 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
run-mp3.sh
executable file
·71 lines (57 loc) · 1.48 KB
/
run-mp3.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
#!/bin/bash
# author: Alek Ratzloff
# Runs the spark-signal clean-it-up on an MP3 file.
# (Doesn't actually run on an MP3 file, uses lots of hacks to make it work)
### Functions ###
usage() {
echo "usage: $0 file1.mp3 [ file2.mp3 ... ]"
}
echo_err() {
echo -e "\x1b[30;1m[ ERROR ]\x1b[0m "$*
}
echo_warn() {
echo -e "\x1b[33;1m[ WARN ]\x1b[0m "$*
}
cleanup() {
for f in $wav_files
do rm $f
done
}
### Script variables ###
classname='edu.appstate.cs.SparkSignal'
jarfile='target/spark-signal-1.0-SNAPSHOT.jar'
data_dir='/hdfs/bee'
hdfs_tmp_dir='/hdfs/tmp'
local_tmp_dir='/tmp'
namenode='node1'
### Let's do this ###
# make sure that the user specified arguments
if [[ $# == 0 ]]; then
usage
exit 0
fi
# Get the list of wav files that we need to create
mp3_basenames=$@
for f in $mp3_basenames; do
# make sure it exists
mp3_path=$data_dir/$f
if [[ ! -f "$mp3_path" ]]; then
echo_err "$mp3_path not found, skipping"
continue
fi
wav_basename="${f%.mp3}.wav"
local_wav_path="$local_tmp_dir/$wav_basename"
hdfs_wav_path="$hdfs_tmp_dir/$wav_basename"
wav_hdfs="hdfs://$namenode/${hdfs_wav_path#/hdfs/}"
echo "$f -> $wav_basename"
# decode the MP3 to WAV
mpg123 -w $local_wav_path $mp3_path > /dev/null || \
{ echo_warn "Could not convert $f, skipping"; continue; }
mv $local_wav_path $hdfs_wav_path
wav_files="$wav_files $hdfs_wav_path"
hdfs_files="$hdfs_files $wav_hdfs"
done
spark-submit --class $classname $jarfile $hdfs_files
# Perform cleanup
echo "Cleaning up..."
cleanup