Created
August 24, 2014 20:44
-
-
Save vmassuchetto/fdbcfe132f2f455e047a to your computer and use it in GitHub Desktop.
Shell script to list MP3 files in the format "<title> (<minute:seconds lengh>)", as required by the MusicBrainz parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
GREP="grep" | |
GREP_E="not found" | |
CURDIR=`pwd` | |
TITLEINFO_1="beet info " | |
TITLEINFO_2=" | grep \"\ title:\" | awk -F':' '{print \$2 }' | sed 's/^ //g'" | |
TIMEINFO_1="mp3info -p \"\%S\"" | |
TIMEINFO_2="" | |
function print_usage () { | |
echo "Usage:" | |
echo " mbclist path" | |
} | |
function sec2minsec () { | |
NUM=$1 | |
MIN=0 | |
HOUR=0 | |
DAY=0 | |
if ((NUM>59)) ; then | |
((SEC=NUM%60)) | |
((NUM=NUM/60)) | |
if ((NUM>59)) ; then | |
((MIN=NUM%60)) | |
((NUM=NUM/60)) | |
if ((NUM>23)) ; then | |
((HOUR=NUM%24)) | |
((DAY=NUM/24)) | |
else | |
((HOUR=NUM)) | |
fi | |
else | |
((MIN=NUM)) | |
fi | |
else | |
((SEC=NUM)) | |
fi | |
echo "$MIN":"$SEC" | |
} | |
if [ "." == "$1" ] ; then | |
DIR=`pwd` | |
else | |
DIR=$1 | |
fi | |
if [ ! -d "$DIR" ]; then | |
echo "Error: Invalid directory." | |
exit 1 | |
fi | |
cd "$DIR" | |
for FILE in *; do | |
TITLE=`bash -c "$TITLEINFO_1 \"$FILE\" $TITLEINFO_2"` | |
TIME=`bash -c "$TIMEINFO_1 \"$FILE\" $TIMEINFO_2"` | |
echo "$TITLE (`sec2minsec $TIME`)" | |
done | |
cd "$CURDIR" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment