Skip to content

Instantly share code, notes, and snippets.

@alexander-bauer
Forked from anonymous/convert.sh
Last active August 29, 2015 14:00
Show Gist options
  • Save alexander-bauer/fb0c3478c83da410f953 to your computer and use it in GitHub Desktop.
Save alexander-bauer/fb0c3478c83da410f953 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
## convert.sh
#
# This script is used to convert all of the WAV audio files of a given
# artist/album pair to a different encoding.
#
# usage:
# convert.sh [artist] [album]
CODEC="flac"
# Prompt for information.
ARTIST="$1"
ALBUM="$2"
if [ -z "$ARTIST" ]
then
echo -n "Please enter an artist: "
read ARTIST
fi
if [ -z "$ALBUM" ]
then
echo -n "Please enter an album: "
read ALBUM
fi
# Assume the directories to move from are incoming and untagged.
INDIR="incoming/$ARTIST/$ALBUM"
OUTDIR="untagged/$ARTIST/$ALBUM"
INFILES=$(ls "$INDIR")
mkdir -p "$OUTDIR"
for file in $INFILES
do
infile="$INDIR/$file"
outfile="$OUTDIR/$(basename "$file").$CODEC"
# Convert the file
ffmpeg -i "$infile" "$outfile"
# If the conversion was successful, remove the raw file.
if [ $? == 0 ]
then
rm "$infile"
fi
done
# Prune empty directories under the artist.
rm -d "$INDIR"
rm -d "incoming/$ARTIST"
#!/bin/sh
#
## getcd.sh
#
# This script opens the CD drive and prompts the user for an artist
# and album name. It then uses CDparanoia to rip the CD, and put it in
# the appropriate directory in raw form.
#
# usage:
# getcd.sh [artist] [album]
# Open the tray.
eject
# Prompt for information.
ARTIST="$1"
ALBUM="$2"
if [ -z "$ARTIST" ]
then
echo -n "Please enter an artist: "
read ARTIST
fi
if [ -z "$ALBUM" ]
then
echo -n "Please enter an album: "
read ALBUM
fi
# Close the tray, or prompt if necessary.
eject -t 2>&1 > /dev/null || ( echo -n "Please close the tray. " && read )
# Make the appropriate directory inside incoming/
DIR="incoming/$ARTIST/$ALBUM"
mkdir -p "$DIR"
echo "==== RIPPING ===="
# Wait for the drive to be mounted.
# TODO: something sensible
sleep 10
# Rip the CD in semi-paranoid batch mode, and put the WAV results in
# the appropriate directory.
CURDIR=$(pwd)
cd "$DIR"
cdparanoia -Y -B
cd "$CURDIR"
# Eject the tray again.
eject
echo "==== DONE ===="
#!/bin/sh
#
## importcd.sh
#
# This script combines getcd.sh and convert.sh.
#
# usage:
# importcd.sh [artist] [album]
# Prompt for information.
ARTIST="$1"
ALBUM="$2"
if [ -z "$ARTIST" ]
then
echo -n "Please enter an artist: "
read ARTIST
fi
if [ -z "$ALBUM" ]
then
echo -n "Please enter an album: "
read ALBUM
fi
# Invoke getcd.sh in the same directory.
"$(dirname $0)/getcd.sh" "$ARTIST" "$ALBUM"
# Same deal for convert.sh.
"$(dirname $0)/convert.sh" "$ARTIST" "$ALBUM"
# Send a terminal bell alert.
echo -n "\a"
#!/bin/sh
# Run the import command.
beet -d "/home/sasha/music" import -i -l "tag.log" "untagged/"
#!/bin/sh
#
## taruntagged.sh
#
# This script is used to create a tarball of all untagged music, and
# delete those files.
#
# usage:
# taruntagged.sh
# Generate a timestamp for the tarball.
TIMESTAMP="$(date +%Y-%m-%d_%H.%M.%S%z)"
# Create a tar archive including the timestamp, and delete
# files which are added to the repository.
tar --create --remove-files --file "untagged-$TIMESTAMP" "untagged/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment