#=====================================
#xstem.sh                            |
#Version 1.1                         |
#Written by pocketjawa yo            |
#http://twitter.com/pocketjawa       |
#Do what you want (with this script) |
#'Cause a pirate is free             |
#YOU ARE A PIRATE                    |
#=====================================

#!/bin/sh -u
# UTF-8 (international) script header
PATH=/bin:/usr/bin ; export PATH   # add /sbin and /usr/sbin if needed
umask 022                          # use 077 for secure scripts
unset LC_ALL                       # unset the over-ride variable
LC_COLLATE=en_US.utf8 ; export LC_COLLATE # sort by character set
LC_CTYPE=en_US.utf8 ; export LC_CTYPE # handle multi-byte chars
LANG=en_US.utf8 ; export LANG      # legacy version of LC_CTYPE

if [ $# -ne 2 ] ;
 then
  echo "$0 is expecting 2 arguments, found $# ($@)" 1>&2
  echo "Usage: $0 StemFile.stem.mp4 OutputName (no extension)" 1>&2
  echo "Eg: $0 Darude-Sandstorm.stem.mp4 dankstorm"
  false
 else
  original="$1"
  ffmpeg -i "$original" -vn -acodec copy -map 0:0 "$2".0.m4a
  ffmpeg -i "$original" -vn -acodec copy -map 0:1 "$2".1.m4a
  ffmpeg -i "$original" -vn -acodec copy -map 0:2 "$2".2.m4a
  ffmpeg -i "$original" -vn -acodec copy -map 0:3 "$2".3.m4a
  ffmpeg -i "$original" -vn -acodec copy -map 0:4 "$2".4.m4a
fi
