これは、元の問題を解決するためにすばやく一緒にハッキングしたPythonスクリプトです。音楽ライブラリの圧縮コピーを保持します。AACファイルがすでに存在し、ALACファイルよりも新しい場合を除き、スクリプトは.m4aファイル(ALACと想定)をAAC形式に変換します。ライブラリ内のMP3ファイルはすでに圧縮されているため、リンクされます。
スクリプト(ctrl-c)を中止すると、半分変換されたファイルが残ることに注意してください。
私ももともとこれを処理するためにMakefileを書きたかったのですが、ファイル名のスペースを処理できず(受け入れられた答えを参照)、bashスクリプトを書くことは苦痛の世界に私を置くことが保証されているので、Pythonはそうです。それはかなり単純で短いので、ニーズに合わせて簡単に調整できるはずです。
from __future__ import print_function
import glob
import os
import subprocess
UNCOMPRESSED_DIR = 'Music'
COMPRESSED = 'compressed_'
UNCOMPRESSED_EXTS = ('m4a', ) # files to convert to lossy format
LINK_EXTS = ('mp3', ) # files to link instead of convert
for root, dirs, files in os.walk(UNCOMPRESSED_DIR):
out_root = COMPRESSED + root
if not os.path.exists(out_root):
os.mkdir(out_root)
for file in files:
file_path = os.path.join(root, file)
file_root, ext = os.path.splitext(file_path)
if ext[1:] in LINK_EXTS:
if not os.path.exists(COMPRESSED + file_path):
print('Linking {}'.format(file_path))
link_source = os.path.relpath(file_path, out_root)
os.symlink(link_source, COMPRESSED + file_path)
continue
if ext[1:] not in UNCOMPRESSED_EXTS:
print('Skipping {}'.format(file_path))
continue
out_file_path = COMPRESSED + file_path
if (os.path.exists(out_file_path)
and os.path.getctime(out_file_path) > os.path.getctime(file_path)):
print('Up to date: {}'.format(file_path))
continue
print('Converting {}'.format(file_path))
subprocess.call(['ffmpeg', '-y', '-i', file_path,
'-c:a', 'libfdk_aac', '-vbr', '4',
out_file_path])
もちろん、これを拡張して、エンコードを並行して実行することもできます。それは読者の練習問題として残されています;-)