Skip to content

Instantly share code, notes, and snippets.

@ToshihitoKon
Created March 27, 2020 00:25
Show Gist options
  • Save ToshihitoKon/866c0cde3f8cbc80722c5b30f076a5cb to your computer and use it in GitHub Desktop.
Save ToshihitoKon/866c0cde3f8cbc80722c5b30f076a5cb to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -xeu
root_dir=`cd $(dirname $0) && pwd`
IFS='
'
function convert_aac () {
local audio_file="$1"
local audio_file_m4a="$2"
echo "> convert $audio_file"
# 画像抽出、無いなら無いでOK
echo "$(ffmpeg -hide_banner \
-i "${audio_file}" \
"cover.jpg")"
# convert
ffmpeg -hide_banner \
-i "${audio_file}" \
-vn \
-codec:a aac \
-ab 320k \
"${audio_file_m4a}"
# coverがあるなら付与
if [ -e "cover.jpg" ]; then
# jpgはjpgでもAtomicParsleyが駄目なjpgあるらしいのでconvertして確実にやる
convert cover.jpg must_jpg_cover.jpg
AtomicParsley "${audio_file_m4a}" --artwork must_jpg_cover.jpg --overWrite
rm cover.jpg must_jpg_cover.jpg
fi
}
audio_files=$(find . -type f | grep -vi hi-res)
for audio_file in ${audio_files[@]}; do
# 非対象ファイルたち
if [ -z "$(echo $audio_file | grep -v -E '\.(m4a|sh|jpg)')" ]; then
continue
fi
audio_file_m4a="${audio_file%.*}.m4a"
# convert済み
if [ -e "${audio_file_m4a}" ]; then
echo skip
continue
fi
# convert
echo convert_aac "${audio_file}" "${audio_file_m4a}"
done
alac_dirs=$(find . -type d -name 'M4A')
for alac_dir in ${alac_dirs[@]}; do
echo $alac_dir
cd $alac_dir
for audio_file_alac in `find . -type f`; do
echo $audio_file_alac
# 非対象ファイルたち
if [ -z "$(echo $audio_file_alac | grep -E '\.m4a')" ]; then
continue
fi
audio_file_aac="../AAC/${audio_file_alac}"
mkdir -p "$( dirname ${audio_file_aac})"
# convert済み
if [ -e "${audio_file_aac}" ]; then
echo skip
continue
fi
# convert
convert_aac "${audio_file_alac}" "${audio_file_aac}"
done
cd $root_dir
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment