mirror of
https://github.com/KrumpetPirate/AAXtoMP3.git
synced 2024-11-18 03:08:57 +01:00
commit
72c949359b
54
AAXtoMP3.sh
54
AAXtoMP3.sh
@ -1,42 +1,52 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
AUTHCODE=$1
|
AUTHCODE=$1
|
||||||
shift
|
shift
|
||||||
while [ $# -gt 0 ]; do
|
|
||||||
FILE=$1
|
|
||||||
echo "Decoding $FILE with AUTHCODE $AUTHCODE..."
|
|
||||||
|
|
||||||
ffmpeg -i "$FILE" 2> tmp.txt
|
if ! command -v ffmpeg 2> /dev/null ; then
|
||||||
TITLE=`grep -a -m1 -h -r "title" tmp.txt | head -1 | cut -d: -f2- | xargs -0`
|
date "+%F %Tz ABORT: ffmpeg is missing"
|
||||||
TITLE=`echo $TITLE | sed -e 's/(Unabridged)//' | xargs -0`
|
exit 1
|
||||||
ARTIST=`grep -a -m1 -h -r "artist" tmp.txt | head -1 | cut -d: -f2- | xargs`
|
fi
|
||||||
GENRE=`grep -a -m1 -h -r "genre" tmp.txt | head -1 | cut -d: -f2- | xargs`
|
|
||||||
BITRATE=`grep -a -m1 -h -r "bitrate" tmp.txt | head -1 | rev | cut -d: -f 1 | rev | egrep -o [0-9]+ | xargs`
|
trap 'rm -f "tmp.txt" ; exit 0 ;' EXIT TERM INT
|
||||||
|
|
||||||
|
while [ $# -gt 0 ]; do
|
||||||
|
FILE="$1"
|
||||||
|
echo "$(date "+%F %T%z") Decoding ${FILE} with AUTHCODE ${AUTHCODE}..."
|
||||||
|
|
||||||
|
ffmpeg -i "${FILE}" 2> tmp.txt
|
||||||
|
TITLE=$(grep -a -m1 -h -r "title" tmp.txt | head -1 | cut -d: -f2- | xargs echo )
|
||||||
|
TITLE=$(echo "${TITLE}" | sed -e 's/ (Unabridged)//' | xargs echo )
|
||||||
|
ARTIST=$(grep -a -m1 -h -r "artist" tmp.txt | head -1 | cut -d: -f2- | xargs echo )
|
||||||
|
GENRE=$(grep -a -m1 -h -r "genre" tmp.txt | head -1 | cut -d: -f2- | xargs echo )
|
||||||
|
BITRATE=$(grep -a -m1 -h -r "bitrate" tmp.txt | head -1 | rev | cut -d: -f 1 | rev | egrep -o [0-9]+ | xargs echo )
|
||||||
BITRATE="${BITRATE}k"
|
BITRATE="${BITRATE}k"
|
||||||
OUTPUT=`echo $TITLE | sed -e 's/\:/-/g' | xargs -0`
|
OUTPUT=$(echo "${TITLE}" | sed -e 's/\:/-/g' | xargs echo )
|
||||||
OUTPUT_DIR="${GENRE}/${ARTIST}/${TITLE}"
|
OUTPUT_DIR="${GENRE}/${ARTIST}/${TITLE}"
|
||||||
|
|
||||||
ffmpeg -v error -stats -activation_bytes $AUTHCODE -i "${FILE}" -vn -c:a libmp3lame -ab $BITRATE "${OUTPUT}.mp3"
|
ffmpeg -v error -stats -activation_bytes "${AUTHCODE}" -i "${FILE}" -vn -c:a libmp3lame -ab "${BITRATE}" "${OUTPUT}.mp3"
|
||||||
|
|
||||||
echo "Created ${OUTPUT}.mp3."
|
echo "$(date "+%F %T%z") Created ${OUTPUT}.mp3."
|
||||||
|
|
||||||
echo "Extracting chaptered mp3 files from ${OUTPUT}.mp3..."
|
echo "$(date "+%F %T%z") Extracting chaptered mp3 files from ${OUTPUT}.mp3..."
|
||||||
mkdir -p "${OUTPUT_DIR}"
|
mkdir -p "${OUTPUT_DIR}"
|
||||||
|
set -x
|
||||||
while read -r first _ _ start _ end; do
|
while read -r first _ _ start _ end; do
|
||||||
if [[ $first = Chapter ]]; then
|
if [[ "${first}" = "Chapter" ]]; then
|
||||||
read
|
read -r
|
||||||
read _ _ chapter
|
read -r _ _ chapter
|
||||||
ffmpeg -v error -stats -i "${OUTPUT}.mp3" -ss "${start%?}" -to "$end" -acodec copy "${OUTPUT} - $chapter.mp3" < /dev/null
|
ffmpeg -v error -stats -i "${OUTPUT}.mp3" -ss "${start%?}" -to "${end}" -acodec copy "${OUTPUT} - ${chapter}.mp3" < /dev/null
|
||||||
mv "${OUTPUT} - $chapter.mp3" "${OUTPUT_DIR}"
|
mv "${OUTPUT} - ${chapter}.mp3" "${OUTPUT_DIR}"
|
||||||
|
set +x
|
||||||
fi
|
fi
|
||||||
done < tmp.txt
|
done < tmp.txt
|
||||||
mv "${OUTPUT}.mp3" "${OUTPUT_DIR}"
|
mv "${OUTPUT}.mp3" "${OUTPUT_DIR}"
|
||||||
echo "Done creating chapters. Single file and chaptered files contained in ${OUTPUT_DIR}."
|
echo "$(date "+%F %T%z") Done creating chapters. Single file and chaptered files contained in ${OUTPUT_DIR}."
|
||||||
|
|
||||||
rm tmp.txt
|
rm tmp.txt
|
||||||
|
|
||||||
echo "Extracting cover into ${OUTPUT_DIR}/cover.jpg..."
|
echo "$(date "+%F %T%z") Extracting cover into ${OUTPUT_DIR}/cover.jpg..."
|
||||||
ffmpeg -v error -activation_bytes $AUTHCODE -i "$FILE" -an -vcodec copy "${OUTPUT_DIR}/cover.jpg"
|
ffmpeg -v error -activation_bytes "${AUTHCODE}" -i "${FILE}" -an -vcodec copy "${OUTPUT_DIR}/cover.jpg"
|
||||||
echo "Done."
|
echo "$(date "+%F %T%z") Done."
|
||||||
|
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
Loading…
Reference in New Issue
Block a user