iPhone: Extracting m4a songs to Mp3

Tyler Aviss tjaviss-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Tue Mar 9 18:52:41 UTC 2010


Since there don't seem to be any tools (that don't require manually
recompiling half my OS) out yet that will interface with the current
iPhone/iPod/iFangledDoohickey devices, I thought I'd share my current
script used to dump all the M4A files from the phone and convert them
to appropriately named MP3's.

Some minor quality loss may occur during conversion, of course, as
it's going from lossy to lossy format. It will do a decent attempt at
naming the files appropriately. Modify as needed (and feel free to
supply your mods back if you come up with something useful).

Works with jailbroken phones with SSH, mounted via ipod-mount, etc

------------------------------------------------------------------------------------------------------------------------

#!/bin/bash

#This script requires atomicparsley, ffmpeg, and lame to work

SEARCHDIR="/media/ipod/iTunes_Control/Music"
WORKDIR="/tmp/convert"
SAVEDIR="${WORKDIR}"

###################

if [ ! -d "${WORKDIR}" ]; then
  mkdir "${WORKDIR}"
fi

if [ ! -d "${SAVEDIR}" ]; then
  mkdir "${SAVEDIR}"
fi
for FILE in $(find ${SEARCHDIR} -iname \*.m4a);
do
  #strip names
  BASEFILE=${FILE/\/*\//}
  BASENAME=${BASEFILE%.m4a}

  #UUUGLY hack to get file info, but this is the only app I know that
will get tags from m4a files...
  ARTIST=$(/usr/bin/AtomicParsley "${FILE}" -t | grep aART | awk -F ':
' '{ print $2}')
  ALBUM=$(/usr/bin/AtomicParsley "${FILE}" -t | grep '©alb' | awk -F
': ' '{ print $2}')
  NAME=$(/usr/bin/AtomicParsley "${FILE}" -t | grep '©nam' | awk -F ':
' '{ print $2}')
  TRACK=$(/usr/bin/AtomicParsley "${FILE}" -t | grep 'trkn' | awk -F
': ' '{ print $2}')
  echo "- Name : ${NAME}"
  echo "- Album : ${ALBUM}"
  echo "- Artist : ${ARTIST}"

  echo "COPYING to ${WORKDIR}/"
  cp "${FILE}" ${WORKDIR}/
  sleep 1
  if [ -z "${TRACK}" ]; then
    NEWNAME="${ARTIST} -- ${NAME}"
  else
    NEWNAME="${ARTIST} :: ${ALBUM} (${TRACK}) -- ${NAME}"
  fi
  WAVFILE="${WORKDIR}/${BASENAME}.wav"
  MP3FILE="${SAVEDIR}/${NEWNAME}.mp3"
  echo "Re-encoding to WAV: ${WAVFILE}" && ffmpeg -i
"${WORKDIR}/${BASEFILE}" -ar 44100 "${WAVFILE}" && \
  echo "Encoding \"${WAVFILE}\"as VBR MP3: ${MP3FILE}" && lame
--vbr-new --ta "${ARTIST}" --tl "${ALBUM}" --tt "${NAME}"  --tc
"${TRACK}" "${WAVFILE}" -o "${MP3FILE}" && \
  echo "Removing WAV file" && rm "${WAVFILE}" &&
  echo "Removing base file" && rm "${WORKDIR}/${BASEFILE}"
  echo
  echo
done
#END OF FILE

------------------------------------------------------------------------------------------------------------------------


-- 
Tyler Aviss
Systems Support
LPIC/LPIC-2/CLA

"You cannot herd cats, but you can move their food"
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list