5

I have a music album, but whole album is in single flac file and tracks are listed in cue file. So I'd like to split it into tracks, but also fill the id3 tags and name files by track name.

Hennes
  • 65,804
  • 7
  • 115
  • 169
kravemir
  • 2,704

2 Answers2

8

Install reaquired packages on Debian (Ubuntu):

sudo apt-get install cuetools shntool flac

Split flac file and fill id3 tags:

cuebreakpoints sample.cue | shnsplit -o flac sample.flac
cuetag sample.cue split-track*.flac

Some systems has cuetag.sh instead of cuetag.

kravemir
  • 2,704
0

Here is a PHP script:

<?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);
}
Zombo
  • 1