add albumize.sh to create albums
authorColin Patrick Mccabe <cmccabe@alumni.cmu.edu>
Sat, 28 Mar 2015 17:40:27 +0000 (10:40 -0700)
committerColin Patrick Mccabe <cmccabe@alumni.cmu.edu>
Sat, 28 Mar 2015 17:40:27 +0000 (10:40 -0700)
Signed-off-by: Colin Patrick McCabe <cmccabe@cloudera.com>

albumize.sh [new file with mode: 0755]

diff --git a/albumize.sh b/albumize.sh
new file mode 100755 (executable)
index 0000000..d3f1496
--- /dev/null
@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+
+die() {
+    echo $@
+    exit 1
+}
+
+DIR="${1}"
+[ x"${DIR}" == x ] && die "You must supply a directory to albumize"
+
+# Check for invalid files
+find "$DIR" -not -name '*.mp4' | while read $FILE; do
+    die "Found invalid file $FILE"
+done
+
+# Convert files to mp3
+for FILE in "${DIR}"/*.mp4; do
+    mp4-to-mp3.sh "${FILE}" || die "mp4-to-mp3.sh ${FILE} failed"
+    BASE="$(dirname "${FILE}")/$(basename "${FILE}" .mp4)"
+    mv -f "${BASE}.mp4.mp3" "${BASE}.mp3" || \
+        die "failed to rename ${BASE}.mp4.mp3 to ${BASE}.mp3"
+done
+
+NUM_MP3=$(find "$DIR" -type f -name '*.mp3' | wc -l)
+NUM_NON_MP3=$(find "$DIR" -type f -not -name '*.mp3' | wc -l)
+[ $NUM_MP3 -eq $NUM_NON_MP3 ] || die "found $NUM_MP3 mp3s, \
+but $NUM_NON_MP3 non-mp3 files."
+
+# Remove non-mp3 files
+rm "${DIR}/"*.mp4
+
+# Add id3 labels to files
+tagger.py "${DIR}"