DaveParillo が提案したサイトで、BpmDj プロジェクトを見つけました。 bpmcount
があります bpm を計算する実行可能ファイルは非常に優れています:mp3 と flac を処理します:
161.135 Metallica/2008 - Death Magnetic/01-That Was Just Your Life.flac
63.5645 Doom3.mp3
残っている唯一のことは、コレクションにタグを付け直すことです。成功するたびにこの回答を更新します.Thanks! :)
ステップ 1
bpmcount
を実行 コレクション全体に対して、結果をテキストファイルに保存します。問題は bpmcount
時々クラッシュし、複数のファイルを処理するときに最大 2GB のメモリを消費しようとするため、ファイル名を 1 つずつ指定する必要があります。このように:
musicdir='/home/ootync/music'
find "$musicdir" -iregex ".*\.\(mp3\|ogg\|flac\|ape\)" -exec bpmcount {} \; \
| fgrep "$musicdir" > "$musicdir/BPMs.txt"
ステップ 2
追加のパッケージが必要です:apt-get install vorbis-tools flac python-mutagen
.'bpm' タグを追加する方法を見てみましょう:
mid3v2 --TBPM 100 doom3.mp3
vorbiscomment -a -t "BPM=100" mother.ogg
metaflac --set-tag="BPM=100" metallica.flac
残念ながら、*.ape トラックはありません
これで BPM が得られ、コレクション全体にタグを付け直す必要があります。スクリプトは次のとおりです:
cat "$musicdir/BPMs.txt" | while read bpm file ; do
bpm=`printf "%.0f" "$bpm"` ;
case "$file" in
*.mp3) mid3v2 --TBPM "$bpm" "$file" > /dev/null ;;
*.ogg) vorbiscomment -a -t "BPM=$bpm" "$file" ;;
*.flac) metaflac --set-tag="BPM=$bpm" "$file" ;;
esac
done
ステップ 2.1 の再訪 コレクションに BPM タグを追加するスクリプトは次のとおりです。
プロセスを高速化するために、CPU コアごとに 1 つのプロセスを実行します。さらに、一時ファイルを使用せず、ファイルが既にタグ付けされているかどうかを検出できます。
さらに、FLAC には ID3 と VorbisComment の両方が含まれている場合があることを発見しました。このスクリプトは両方を更新します。
#!/bin/bash
function display_help() {
cat <<-HELP
Recursive BPM-writer for multicore CPUs.
It analyzes BPMs of every media file and writes a correct tag there.
Usage: $(basename "$0") path [...]
HELP
exit 0
}
[ $# -lt 1 ] && display_help
#=== Requirements
requires="bpmcount mid3v2 vorbiscomment metaflac"
which $requires > /dev/null || { echo "E: These binaries are required: $requires" >&2 ; exit 1; }
#=== Functions
function bpm_read(){
local file="$1"
local ext="${file##*.}"
declare -l ext
# Detect
{ case "$ext" in
'mp3') mid3v2 -l "$file" ;;
'ogg') vorbiscomment -l "$file" ;;
'flac') metaflac --export-tags-to=- "$file" ;;
esac ; } | fgrep 'BPM=' | cut -d'=' -f2
}
function bpm_write(){
local file="$1"
local bpm="${2%%.*}"
local ext="${file##*.}"
declare -l ext
echo "BPM=$bpm @$file"
# Write
case "$ext" in
'mp3') mid3v2 --TBPM "$bpm" "$file" ;;
'ogg') vorbiscomment -a -t "BPM=$bpm" "$file" ;;
'flac') metaflac --set-tag="BPM=$bpm" "$file"
mid3v2 --TBPM "$bpm" "$file" # Need to store to ID3 as well :(
;;
esac
}
#=== Process
function oneThread(){
local file="$1"
#=== Check whether there's an existing BPM
local bpm=$(bpm_read "$file")
[ "$bpm" != '' ] && return 0 # there's a nonempty BPM tag
#=== Detect a new BPM
# Detect a new bpm
local bpm=$(bpmcount "$file" | grep '^[0-9]' | cut -f1)
[ "$bpm" == '' ] && { echo "W: Invalid BPM '$bpm' detected @ $file" >&2 ; return 0 ; } # problems
# Write it
bpm_write "$file" "${bpm%%.*}" >/dev/null
}
NUMCPU="$(grep ^processor /proc/cpuinfo | wc -l)"
find [email protected] -type f -regextype posix-awk -iregex '.*\.(mp3|ogg|flac)' \
| while read file ; do
[ `jobs -p | wc -l` -ge $NUMCPU ] && wait
echo "$file"
oneThread "$file" &
done
楽しみ! :)
これは、BPM を検出して FLAC ファイル タグに挿入するためのコマンド ライン ツールです:
http://www.pogo.org.uk/~mark/bpm-tools/
bpmcount
を使用して kolypto のオリジナル スクリプトを使用しました bpm-tag
用に書き直しました (bpm-tools
のユーティリティ ) インストールできて良かったです。また、独自の改善もいくつか行いました。
GitHub で見つけることができます https://github.com/meridius/bpmwrap