我有一张音乐专辑,但整张专辑都在一个 flac 文件中,曲目则列在 cue 文件中。因此我想将其拆分成曲目,并填写 id3 标签,并按曲目名称命名文件。
答案1
在 Debian(Ubuntu)上安装所需的软件包:
sudo apt-get install cuetools shntool flac
分割flac文件并填充id3标签:
cuebreakpoints sample.cue | shnsplit -o flac sample.flac
cuetag sample.cue split-track*.flac
有些系统有提示标签代替提示标签。
答案2
以下是一个 PHP 脚本:
<?php
$s_cue = $argv[1];
$a_cue = file($s_cue);
$n_row = -1;
foreach ($a_cue as $s_row) {
$s_trim = trim($s_row);
$a_row = str_getcsv($s_trim, ' ');
if (preg_match('/^FILE\s/', $s_row) == 1) {
$s_file = $a_row[1];
}
if (preg_match('/^\s+TRACK\s/', $s_row) == 1) {
$n_row++;
$a_table[$n_row]['track'] = $a_row[1];
}
if (preg_match('/^\s+TITLE\s/', $s_row) == 1) {
$a_table[$n_row]['title'] = $a_row[1];
}
if (preg_match('/^\s+PERFORMER\s/', $s_row) == 1) {
$a_table[$n_row]['artist'] = $a_row[1];
}
if (preg_match('/^\s+INDEX\s/', $s_row) == 1) {
$s_dur = $a_row[2];
$a_frame = sscanf($s_dur, '%d:%d:%d', $n_min, $n_sec, $n_fra);
$n_index = $n_min * 60 + $n_sec + $n_fra / 75;
$a_table[$n_row]['ss'] = $n_index;
if ($n_row > 0) {
$a_table[$n_row - 1]['to'] = $n_index;
}
}
}
$a_table[$n_row]['to'] = 10 * 60 * 60;
foreach ($a_table as $m_row) {
$a_cmd = [
'ffmpeg',
'-i', $s_file,
'-ss', $m_row['ss'],
'-to', $m_row['to'],
'-metadata', 'artist=' . $m_row['artist'],
'-metadata', 'title=' . $m_row['title'],
'-metadata', 'track=' . $m_row['track'],
$m_row['track'] . ' ' . $m_row['title'] . '.m4a'
];
$a_esc = array_map('escapeshellarg', $a_cmd);
$s_esc = implode(' ', $a_esc);
system($s_esc);
}