12

I have a 44GB (yes, forty-four) folder of .ape CD files. Each .ape is a complete CD, and there is usually a .cue file along with each .ape. I need to convert but not split these, since there's no cue data to go by. There are also some .jpgs and .logs in there too, which I don't care about. If a tree command output helps visualize this, here you go:

├── Philips Mozart Collection - 180 CD
│   │   ├── box01-Symphonies
│   │   │   ├── 1B.jpg
│   │   │   ├── 1F.jpg
│   │   │   ├── cd01
│   │   │   │   ├── CDImage.ape
│   │   │   │   ├── CDImage.ape.cue
│   │   │   │   ├── Complete Mozart Edition, Vol. 01, Early Symphonies (Disc 1) - Neville Mariner, Academy of St. Martin in the Fields.log
│   │   │   │   ├── img421.jpg
│   │   │   │   └── img422.jpg
│   │   │   ├── cd02
│   │   │   │   └── CDImage.ape
│   │   │   ├── cd03
│   │   │   │   ├── CDImage.ape
│   │   │   │   ├── CDImage.ape.cue
│   │   │   │   ├── Complete Mozart Edition, Vol. 01, Early Symphonies (Disc 2) - Sir Neville Marinner - Acadamy of St Martin in the Fields.log
│   │   │   │   ├── img426.jpg
│   │   │   │   └── img427.jpg
│   │   │   ├── cd04

etc... all the way to 180 CDS.

Basically, I want to split all the .ape files into multiple .flac files, and copy over the tag info from the .cue, keeping the directory structure (preferably in a completely new and different directory). I prefer a single-line command to a script if possible. How would I go about this? Thanks to anyone who knows how to do this!

And before anyone flags this question as a duplicate to this one here: Convert all .ape files to .flac in different subfolders, I would like to point out that that user didn't need to split the .ape into multiple .flacs.

7
  • Hi, would you please explain more about your sentence "... and copy over the tag info from the .cue ...". Does it means the converted .flac files name should be pick-up from .cue file? Then would you please share sample content of it. Else how multiple files should be create and what is max number of these files? Thanks Apr 15, 2016 at 4:35
  • >I need to somehow skip those, since there's no cue data to go by. What do you mean by this? Without cue data, you could convert , but not split, since the info about where tracks start and end are in the cue.
    – emk2203
    Apr 15, 2016 at 5:43
  • @Afshin.Hamadi Yes, the filename would match the track title. The .cue file has info such as artist, album, etc. This info should be copied to the new flac files. Apr 16, 2016 at 1:54
  • @emk2203 Good point, I updated the question. Apr 16, 2016 at 1:55
  • You are contradicting yourself even more. "I need to convert but not split these, since there's no cue data to go by." - "Basically, I want to split all the .ape files into multiple .flac files, and copy over the tag info from the .cue...". So what is it? If it is the standard "I have .ape and .cue files, and I want them converted and split in-place to tagged .flac", the question could have been closed with two good answers 24 hours ago.
    – emk2203
    Apr 16, 2016 at 5:31

1 Answer 1

13
+50

I would do this in multiple steps, since you do this rarely. Transparency is more important than automation here. But a single line is also possible. I assume that if you use only one command for all the files each step, this is what you intended.

You need to have ffmpeg (or avconv), shntool and cuetools installed.

To convert all your .ape to .flac in place:

find . -name "*.ape" -exec sh -c 'exec ffmpeg -i "$1" "${1%.ape}.flac"' _ {} \;

If you install the patched MAC encoder and decoder for APE files from http://shnutils.freeshell.org/shntool/, this first step is unnecessary. But you would need to compile it with g++ and yasm yourself. Same goes for .tta files, which are also often used instead of .ape.

Split and name .flac files:

find . -name "*.cue" -exec sh -c 'exec shnsplit -f "$1" -o flac -t "%n_%p-%t" "${1%.cue}.flac"' _ {} \;

If shnsplit is also used for the conversion, replace the .flac in "${1%.cue}.flac" with the extension of the format you are converting from.

  • %n – track number
  • %p – performer
  • %t – track name

is taken from the .cue file for the .flac file names. To tag the resulting, split .flac files:

find . -name "*.cue" -execdir sh -c 'exec cuetag "$1" *.flac' _ {} \;

Remove the remaining CDImage.ape.cue, CDImage.flac, and CDImage.ape files at your leisure. The names are unique, so a simple find . -name "CDImage*" -delete is sufficient, except if Mozart made a composition starting with CDImage which I am not aware of.

For shnsplit to work, all necessary encoders/decoders need to be installed so it can read and write files. Modules for APE (and for the TTA format) would need to be compiled from source, the others by installing the package (i. e. FLAC).

This works for all standard cases where .cue and .tta/.flac/.ape files have the same name, except for the extension.


Side remark for others: If you deal with this conversion, your source files might be of Japanese origin, where APE and TTA were more popular than elsewhere. If the .cue files were initially SHIFT-JIS coded and now opened as UTF-8, the shnsplit step will break. You need to rename the .cue files with

find . -name "*.cue" -exec rename 's/\.cue$/.cux/' -- {} +

and convert the intermediate files to UTF-8 with

find . -name "*.cux" -exec sh -c 'exec iconv -f SHIFT-JIS -t UTF-8 -o "${1%.cux}.cue" -- "$1"' _ {} \;

before you attempt to do the steps above. Don't forget to get rid of the .cux files when you are done with:

find . -name "*.cux" -delete
10
  • shnsplit's manpage lists ape as a supported format so you can skip converting to flac with ffmpeg and use -o flac with shnsplit instead. Don't expect to find a standard basename and ape as the codec/container other lossless codecs are used too, so it's better to not hard code and it would be better to include all steps in one run of the find command. metaflac --add-replay-gain would also be a good idea.
    – LiveWireBT
    Apr 22, 2016 at 11:03
  • @LiveWireBT: Technically, you are correct. This is why I said "two solutions available" in one of my comment. However, you need to download the source for the plugins for ape and tta support, install g++ and yasm and compile and install them yourself. I went with the ffmpeg solution since it is easier.
    – emk2203
    Apr 22, 2016 at 11:07
  • 2
    For a one-command version: find -name '*.ape' -execdir sh -c 'flac="${1%.ape}.flac"; ffmpeg -i "$1" "$flac" && shnsplit -f CDImage.ape.cue "$flac" && cuetag CDImage.ape.cue "$flac"' _ {} \: Apr 22, 2016 at 14:54
  • 1
    Yes. I would always run once without the delete switch first to make sure that it runs as intended.
    – emk2203
    Apr 24, 2016 at 23:00
  • 1
    Please use the slightly revised instructions. Tried them, they work.
    – emk2203
    Apr 27, 2016 at 21:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .