How do I split a flac with a cue?Splitting a flac from a cuesheet metadata blockHow do file managers split...

Weird resistor with dots around it

Symbol: Put a smile symbol under a plus

How big are the Choedan Kal?

How do you deal with the emotions of not being the one to find the cause of a bug?

Why did Saruman lie?

Does Nightpack Ambusher's second ability trigger if I cast spells during the end step?

Do I have to cite common CS algorithms?

Why is there a large performance impact when looping over an array over 240 elements?

How to remove ambiguity: "... lives in the city of H, the capital of the province of NS, WHERE the unemployment rate is ..."?

Website error: "Walmart can’t use this browser"

Escape Velocity - Won't the orbital path just become larger with higher initial velocity?

The cat ate your input again!

How to find directories containing only specific files

Are there really no countries that protect Freedom of Speech as the United States does?

How to Check all AD userers for "blank" password?

The cat exchanges places with a drawing of the cat

Is this n-speak?

How was the murder committed?

Does EU compensation apply to flights where the departure airport closes check-in counters during protests?

Why aren’t there water shutoff valves for each room?

Why is the second S silent in "Sens dessus dessous"?

How can God warn people of the upcoming rapture without disrupting society?

Heating Margarine in Pan = loss of calories?

My cat is a houdini



How do I split a flac with a cue?


Splitting a flac from a cuesheet metadata blockHow do file managers split off opened programs?How do I get song names and artists from mp3 files in a dir?Command Line alternative to IsoBusterWhat is the best way of getting rid of a symbol (question mark) in hundreds of FLAC filesUsing ffmpeg to split an Audible audio-book into chapters?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







70















I've got a full album flac and a cue file for it. How can I split this into a flac per track?



I'm a KDE user, so I would prefer a KDE/Qt way. I would like to see command line and other GUI answers as well, but they are not my preferred method.










share|improve this question



























  • superuser.com/questions/251362/…

    – Ciro Santilli 新疆改造中心996ICU六四事件
    Sep 3 '15 at 12:20


















70















I've got a full album flac and a cue file for it. How can I split this into a flac per track?



I'm a KDE user, so I would prefer a KDE/Qt way. I would like to see command line and other GUI answers as well, but they are not my preferred method.










share|improve this question



























  • superuser.com/questions/251362/…

    – Ciro Santilli 新疆改造中心996ICU六四事件
    Sep 3 '15 at 12:20














70












70








70


32






I've got a full album flac and a cue file for it. How can I split this into a flac per track?



I'm a KDE user, so I would prefer a KDE/Qt way. I would like to see command line and other GUI answers as well, but they are not my preferred method.










share|improve this question
















I've got a full album flac and a cue file for it. How can I split this into a flac per track?



I'm a KDE user, so I would prefer a KDE/Qt way. I would like to see command line and other GUI answers as well, but they are not my preferred method.







command-line audio gui flac






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 16 hours ago









SeeYouInDisneyland

1189 bronze badges




1189 bronze badges










asked Mar 28 '11 at 22:57









xenoterracidexenoterracide

27.1k55 gold badges161 silver badges227 bronze badges




27.1k55 gold badges161 silver badges227 bronze badges
















  • superuser.com/questions/251362/…

    – Ciro Santilli 新疆改造中心996ICU六四事件
    Sep 3 '15 at 12:20



















  • superuser.com/questions/251362/…

    – Ciro Santilli 新疆改造中心996ICU六四事件
    Sep 3 '15 at 12:20

















superuser.com/questions/251362/…

– Ciro Santilli 新疆改造中心996ICU六四事件
Sep 3 '15 at 12:20





superuser.com/questions/251362/…

– Ciro Santilli 新疆改造中心996ICU六四事件
Sep 3 '15 at 12:20










8 Answers
8






active

oldest

votes


















71














Shnsplit can read a cue file directly, which also means it can access the other data from the cue file (not just the breakpoints) and generate nicer filenames than 'split-*.flac':



shnsplit -f file.cue -t %n-%t -o flac file.flac


Granted, this makes it more difficult to use cuetag.sh if the original flac file is in the same directory.






share|improve this answer























  • 17





    Fellow debian users: sudo apt-get install cuetools shntool

    – jwbensley
    May 3 '14 at 12:47






  • 13





    You probably also want to tag the files with cuetag file.cue [0-9]*.flac

    – August Karlstrom
    Aug 28 '14 at 14:41






  • 6





    I also needed: sudo apt-get install flac

    – becko
    Mar 28 '16 at 10:13



















20














I only know a CLI way. You will need cuetools and shntool.



cuebreakpoints file.cue | shnsplit -o flac file.flac
cuetag.sh file.cue "split-*".flac





share|improve this answer























  • 2





    Thanks for this Kambus. I've been using cuebreakpoints file.cue | shnsplit -o flac file.flac for a long time. The 2nd bit is going to help a lot!

    – boehj
    Apr 12 '11 at 6:44






  • 1





    cuetag seems to break on filenames containing spaces but after removing them it worked.

    – scai
    Nov 20 '13 at 17:40



















19














Flacon is an intuitive open-source GUI that does exactly that: split a FLAC with a CUE.




Flacon extracts individual tracks from one big audio file containing the entire album of music and saves them as separate audio files. To do this, it uses information from the appropriate CUE file.




It supports among other things:




Supported input formats: WAV, FLAC, APE, WavPack, True Audio (TTA).



Supported out formats: FLAC, WAV, WavPack, AAC, OGG or MP3.



Automatic character set detection for CUE files.




To use it you only need to open the *.cue file with Flacon. It should then automatically detect the big *.flac file (if not, you can specify this manually), and then you should select Flac output format (and optionally configure the encoder), and start the conversion process.



Flacon v5.4.0






share|improve this answer























  • 1





    Welcome to Unix & Linux Stack Exchange! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.

    – slm
    Nov 3 '13 at 15:55













  • still updated in 2017

    – user32012
    Sep 28 '17 at 16:45



















6














if high-quality files are being used, shnsplit is happily erroring out with



shnsplit: error: m:ss.ff format can only be used with CD-quality files


fortunately the flac binary supports --skip=mm:ss.ss and --until=mm:ss.ss so a script can use cuebreakpoints like this:



[..]
time[0]="00:00.00"
c=1
for ts in $(cuebreakpoints "${cue_file}"); do
time[${c}]=${ts}
c=$((c+1))
done
time[${c}]='-0'
for ((i=0;i<$((${#time[@]}-1));i++)); do
trackno=$(($i+1))
TRACKNUMBER="$(printf %02d ${trackno})"
title="$(cueprint --track-number ${trackno} -t '%t' "${cue_file}")"
flac --silent --exhaustive-model-search --skip=${time[$i]} --until=${time[$(($i+1))]} --tag=ARTIST="${ARTIST}" --tag=ALBUM="${ALBUM}" --tag=DATE="${DATE}" --tag=TITLE="${title}" --tag=TRACKNUMBER="${TRACKNUMBER}" "${aud_file}" --output-name="${TRACKNUMBER}-${title}.flac"
done





share|improve this answer


























  • This is the only method that worked for me.

    – coffekid
    Feb 26 '18 at 2:57



















3














If you have cue set to use k3b in in the filetype settings, k3b will automatically split the file if you open the cue file, and allow you to re-rip.






share|improve this answer

































    1














    There is a project that works for several input files: split2flac



    From the project description:




    split2flac splits one big APE/FLAC/TTA/WV/WAV audio image (or a
    collection of such files, recursively) with CUE sheet into
    FLAC/M4A/MP3/OGG_VORBIS/WAV tracks with tagging, renaming, charset
    conversion of cue sheet, album cover images. It also uses
    configuration file, so no need to pass a lot of arguments every time,
    only an input file. Should work in any POSIX-compliant shell.







    share|improve this answer

































      1














      I found mac (which is the command that shntool used for decoding APE files) is way less tolerant than ffmpeg if the source file contains minor errors.



      Normally ffmpeg would still convert the file completely while mac very likely throws an error during the processing.



      So I ended up writing a script for spliting APE file by parsing the CUE file and converting the APE file to FLAC files separated by titles using ffmpeg:



      #!/usr/bin/env python2.7

      import subprocess as subp
      import sys
      import os
      from os.path import splitext, basename
      import random
      import glob

      records = []
      filename = ""
      album=''
      alb_artist=''
      codec = 'flac'
      ffmpeg_exec = 'ffmpeg'
      encodingList = ('utf-8','euc-kr', 'shift-jis', 'cp936', 'big5')

      filecontent = open(sys.argv[1]).read()
      for enc in encodingList:
      try:
      lines = filecontent.decode(enc).split('n')
      encoding = enc
      break
      except UnicodeDecodeError as e:
      if enc == encodingList[-1]:
      raise e
      else:
      pass

      for l in lines:
      a = l.split()
      if not a:
      continue
      if a[0] == "FILE":
      filename = ' '.join(a[1:-1]).strip(''"')
      elif a[0]=='TRACK':
      records.append({})
      records[-1]['index'] = a[1]
      elif a[0]=='TITLE':
      if len(records)>0:
      records[-1]['title'] = ' '.join(a[1:]).strip(''"')
      else:
      album = ' '.join(a[1:]).strip(''"')
      elif a[0]=='INDEX' and a[1]=='01':
      timea = a[2].split(':')
      if len(timea) == 3 and int(timea[0]) >= 60:
      timea.insert(0, str(int(timea[0])/60))
      timea[1] = str(int(timea[1])%60)
      times = '{0}.{1}'.format(':'.join(timea[:-1]), timea[-1])
      records[-1]['start'] = times
      elif a[0]=='PERFORMER':
      if len(records)>1:
      records[-1]['artist'] = ' '.join(a[1:]).strip(''"')
      else:
      alb_artist = ' '.join(a[1:]).strip(''"')

      for i, j in enumerate(records):
      try:
      j['stop'] = records[i+1]['start']
      except IndexError:
      pass

      if not os.path.isfile(filename):
      tmpname = splitext(basename(sys.argv[1]))[0]+splitext(filename)[1]
      if os.path.exists(tmpname):
      filename = tmpname
      del tmpname
      else:
      for ext in ('.ape', '.flac', '.wav', '.mp3'):
      tmpname = splitext(filename)[0] + ext
      if os.path.exists(tmpname):
      filename = tmpname
      break

      if not os.path.isfile(filename):
      raise IOError("Can't not find file: {0}".format(filename))

      fstat = os.stat(filename)
      atime = fstat.st_atime
      mtime = fstat.st_mtime

      records[-1]['stop'] = '99:59:59'

      if filename.lower().endswith('.flac'):
      tmpfile = filename
      else:
      tmpfile = splitext(filename)[0] + str(random.randint(10000,90000)) + '.flac'

      try:
      if filename != tmpfile:
      ret = subp.call([ffmpeg_exec, '-hide_banner', '-y', '-i', filename,
      '-c:a', codec,'-compression_level','12','-f','flac',tmpfile])

      if ret != 0:
      raise SystemExit('Converting failed.')

      for i in records:
      output = i['index'] +' - '+ i['title']+'.flac'
      commandline = [ffmpeg_exec, '-hide_banner',
      '-y', '-i', tmpfile,
      '-c', 'copy',
      '-ss', i['start'], '-to', i['stop'],
      '-metadata', u'title={0}'.format(i['title']),
      '-metadata', u'artist={0}'.format(i.get('artist', '')),
      '-metadata', u'performer={0}'.format(i.get('artist', '')),
      '-metadata', u'album={0}'.format(album),
      '-metadata', 'track={0}/{1}'.format(i['index'], len(records)),
      '-metadata', u'album_artist={0}'.format(alb_artist),
      '-metadata', u'composer={0}'.format(alb_artist),
      '-metadata', 'encoder=Meow',
      '-write_id3v1', '1',
      output]
      ret = subp.call(commandline)
      if ret == 0:
      os.utime(output, (atime, mtime))
      finally:
      if os.path.isfile(tmpfile):
      os.remove(tmpfile)





      share|improve this answer


























      • You might want to change if os.path.isfile(tmpfile) to if tmpfile != filename and os.path.isfile(tmpfile) to avoid deleting the original file on error.

        – wolfmanx
        Jan 19 '18 at 6:26











      • The condition for setting the track artist must be if len(records)>0.

        – wolfmanx
        Jan 19 '18 at 6:41



















      1














      shntool on Ubuntu 14.04



      snhtool is missing the mac (Monkey's Audio Console) executable dependency, and the only package I could find it was in the flacon PPA:



      sudo add-apt-repository -y ppa:flacon
      sudo apt-get update
      sudo apt-get install -y flacon shntool
      shntool split -f *.cue -o flac -t '%n - %p - %t' *.ape


      flacon is a GUI for shntool, but it comes with all the codecs it needs... otherwise I got the error:



      shnsplit: warning: failed to read data from input file using format: [ape]
      shnsplit: + you may not have permission to read file: [example.ape]
      shnsplit: + arguments may be incorrect for decoder: [mac]
      shnsplit: + verify that the decoder is installed and in your PATH
      shnsplit: + this file may be unsupported, truncated or corrupt
      shnsplit: error: cannot continue due to error(s) shown above





      share|improve this answer


























        protected by Community Dec 22 '14 at 9:16



        Thank you for your interest in this question.
        Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



        Would you like to answer one of these unanswered questions instead?














        8 Answers
        8






        active

        oldest

        votes








        8 Answers
        8






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        71














        Shnsplit can read a cue file directly, which also means it can access the other data from the cue file (not just the breakpoints) and generate nicer filenames than 'split-*.flac':



        shnsplit -f file.cue -t %n-%t -o flac file.flac


        Granted, this makes it more difficult to use cuetag.sh if the original flac file is in the same directory.






        share|improve this answer























        • 17





          Fellow debian users: sudo apt-get install cuetools shntool

          – jwbensley
          May 3 '14 at 12:47






        • 13





          You probably also want to tag the files with cuetag file.cue [0-9]*.flac

          – August Karlstrom
          Aug 28 '14 at 14:41






        • 6





          I also needed: sudo apt-get install flac

          – becko
          Mar 28 '16 at 10:13
















        71














        Shnsplit can read a cue file directly, which also means it can access the other data from the cue file (not just the breakpoints) and generate nicer filenames than 'split-*.flac':



        shnsplit -f file.cue -t %n-%t -o flac file.flac


        Granted, this makes it more difficult to use cuetag.sh if the original flac file is in the same directory.






        share|improve this answer























        • 17





          Fellow debian users: sudo apt-get install cuetools shntool

          – jwbensley
          May 3 '14 at 12:47






        • 13





          You probably also want to tag the files with cuetag file.cue [0-9]*.flac

          – August Karlstrom
          Aug 28 '14 at 14:41






        • 6





          I also needed: sudo apt-get install flac

          – becko
          Mar 28 '16 at 10:13














        71












        71








        71







        Shnsplit can read a cue file directly, which also means it can access the other data from the cue file (not just the breakpoints) and generate nicer filenames than 'split-*.flac':



        shnsplit -f file.cue -t %n-%t -o flac file.flac


        Granted, this makes it more difficult to use cuetag.sh if the original flac file is in the same directory.






        share|improve this answer















        Shnsplit can read a cue file directly, which also means it can access the other data from the cue file (not just the breakpoints) and generate nicer filenames than 'split-*.flac':



        shnsplit -f file.cue -t %n-%t -o flac file.flac


        Granted, this makes it more difficult to use cuetag.sh if the original flac file is in the same directory.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Feb 4 '12 at 20:27









        Kevin

        28.9k11 gold badges68 silver badges105 bronze badges




        28.9k11 gold badges68 silver badges105 bronze badges










        answered Feb 4 '12 at 19:17









        Michael HMichael H

        8116 silver badges2 bronze badges




        8116 silver badges2 bronze badges











        • 17





          Fellow debian users: sudo apt-get install cuetools shntool

          – jwbensley
          May 3 '14 at 12:47






        • 13





          You probably also want to tag the files with cuetag file.cue [0-9]*.flac

          – August Karlstrom
          Aug 28 '14 at 14:41






        • 6





          I also needed: sudo apt-get install flac

          – becko
          Mar 28 '16 at 10:13














        • 17





          Fellow debian users: sudo apt-get install cuetools shntool

          – jwbensley
          May 3 '14 at 12:47






        • 13





          You probably also want to tag the files with cuetag file.cue [0-9]*.flac

          – August Karlstrom
          Aug 28 '14 at 14:41






        • 6





          I also needed: sudo apt-get install flac

          – becko
          Mar 28 '16 at 10:13








        17




        17





        Fellow debian users: sudo apt-get install cuetools shntool

        – jwbensley
        May 3 '14 at 12:47





        Fellow debian users: sudo apt-get install cuetools shntool

        – jwbensley
        May 3 '14 at 12:47




        13




        13





        You probably also want to tag the files with cuetag file.cue [0-9]*.flac

        – August Karlstrom
        Aug 28 '14 at 14:41





        You probably also want to tag the files with cuetag file.cue [0-9]*.flac

        – August Karlstrom
        Aug 28 '14 at 14:41




        6




        6





        I also needed: sudo apt-get install flac

        – becko
        Mar 28 '16 at 10:13





        I also needed: sudo apt-get install flac

        – becko
        Mar 28 '16 at 10:13













        20














        I only know a CLI way. You will need cuetools and shntool.



        cuebreakpoints file.cue | shnsplit -o flac file.flac
        cuetag.sh file.cue "split-*".flac





        share|improve this answer























        • 2





          Thanks for this Kambus. I've been using cuebreakpoints file.cue | shnsplit -o flac file.flac for a long time. The 2nd bit is going to help a lot!

          – boehj
          Apr 12 '11 at 6:44






        • 1





          cuetag seems to break on filenames containing spaces but after removing them it worked.

          – scai
          Nov 20 '13 at 17:40
















        20














        I only know a CLI way. You will need cuetools and shntool.



        cuebreakpoints file.cue | shnsplit -o flac file.flac
        cuetag.sh file.cue "split-*".flac





        share|improve this answer























        • 2





          Thanks for this Kambus. I've been using cuebreakpoints file.cue | shnsplit -o flac file.flac for a long time. The 2nd bit is going to help a lot!

          – boehj
          Apr 12 '11 at 6:44






        • 1





          cuetag seems to break on filenames containing spaces but after removing them it worked.

          – scai
          Nov 20 '13 at 17:40














        20












        20








        20







        I only know a CLI way. You will need cuetools and shntool.



        cuebreakpoints file.cue | shnsplit -o flac file.flac
        cuetag.sh file.cue "split-*".flac





        share|improve this answer















        I only know a CLI way. You will need cuetools and shntool.



        cuebreakpoints file.cue | shnsplit -o flac file.flac
        cuetag.sh file.cue "split-*".flac






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 16 '14 at 21:17









        HalosGhost

        3,9039 gold badges22 silver badges36 bronze badges




        3,9039 gold badges22 silver badges36 bronze badges










        answered Mar 29 '11 at 11:20









        KambusKambus

        1,3519 silver badges5 bronze badges




        1,3519 silver badges5 bronze badges











        • 2





          Thanks for this Kambus. I've been using cuebreakpoints file.cue | shnsplit -o flac file.flac for a long time. The 2nd bit is going to help a lot!

          – boehj
          Apr 12 '11 at 6:44






        • 1





          cuetag seems to break on filenames containing spaces but after removing them it worked.

          – scai
          Nov 20 '13 at 17:40














        • 2





          Thanks for this Kambus. I've been using cuebreakpoints file.cue | shnsplit -o flac file.flac for a long time. The 2nd bit is going to help a lot!

          – boehj
          Apr 12 '11 at 6:44






        • 1





          cuetag seems to break on filenames containing spaces but after removing them it worked.

          – scai
          Nov 20 '13 at 17:40








        2




        2





        Thanks for this Kambus. I've been using cuebreakpoints file.cue | shnsplit -o flac file.flac for a long time. The 2nd bit is going to help a lot!

        – boehj
        Apr 12 '11 at 6:44





        Thanks for this Kambus. I've been using cuebreakpoints file.cue | shnsplit -o flac file.flac for a long time. The 2nd bit is going to help a lot!

        – boehj
        Apr 12 '11 at 6:44




        1




        1





        cuetag seems to break on filenames containing spaces but after removing them it worked.

        – scai
        Nov 20 '13 at 17:40





        cuetag seems to break on filenames containing spaces but after removing them it worked.

        – scai
        Nov 20 '13 at 17:40











        19














        Flacon is an intuitive open-source GUI that does exactly that: split a FLAC with a CUE.




        Flacon extracts individual tracks from one big audio file containing the entire album of music and saves them as separate audio files. To do this, it uses information from the appropriate CUE file.




        It supports among other things:




        Supported input formats: WAV, FLAC, APE, WavPack, True Audio (TTA).



        Supported out formats: FLAC, WAV, WavPack, AAC, OGG or MP3.



        Automatic character set detection for CUE files.




        To use it you only need to open the *.cue file with Flacon. It should then automatically detect the big *.flac file (if not, you can specify this manually), and then you should select Flac output format (and optionally configure the encoder), and start the conversion process.



        Flacon v5.4.0






        share|improve this answer























        • 1





          Welcome to Unix & Linux Stack Exchange! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.

          – slm
          Nov 3 '13 at 15:55













        • still updated in 2017

          – user32012
          Sep 28 '17 at 16:45
















        19














        Flacon is an intuitive open-source GUI that does exactly that: split a FLAC with a CUE.




        Flacon extracts individual tracks from one big audio file containing the entire album of music and saves them as separate audio files. To do this, it uses information from the appropriate CUE file.




        It supports among other things:




        Supported input formats: WAV, FLAC, APE, WavPack, True Audio (TTA).



        Supported out formats: FLAC, WAV, WavPack, AAC, OGG or MP3.



        Automatic character set detection for CUE files.




        To use it you only need to open the *.cue file with Flacon. It should then automatically detect the big *.flac file (if not, you can specify this manually), and then you should select Flac output format (and optionally configure the encoder), and start the conversion process.



        Flacon v5.4.0






        share|improve this answer























        • 1





          Welcome to Unix & Linux Stack Exchange! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.

          – slm
          Nov 3 '13 at 15:55













        • still updated in 2017

          – user32012
          Sep 28 '17 at 16:45














        19












        19








        19







        Flacon is an intuitive open-source GUI that does exactly that: split a FLAC with a CUE.




        Flacon extracts individual tracks from one big audio file containing the entire album of music and saves them as separate audio files. To do this, it uses information from the appropriate CUE file.




        It supports among other things:




        Supported input formats: WAV, FLAC, APE, WavPack, True Audio (TTA).



        Supported out formats: FLAC, WAV, WavPack, AAC, OGG or MP3.



        Automatic character set detection for CUE files.




        To use it you only need to open the *.cue file with Flacon. It should then automatically detect the big *.flac file (if not, you can specify this manually), and then you should select Flac output format (and optionally configure the encoder), and start the conversion process.



        Flacon v5.4.0






        share|improve this answer















        Flacon is an intuitive open-source GUI that does exactly that: split a FLAC with a CUE.




        Flacon extracts individual tracks from one big audio file containing the entire album of music and saves them as separate audio files. To do this, it uses information from the appropriate CUE file.




        It supports among other things:




        Supported input formats: WAV, FLAC, APE, WavPack, True Audio (TTA).



        Supported out formats: FLAC, WAV, WavPack, AAC, OGG or MP3.



        Automatic character set detection for CUE files.




        To use it you only need to open the *.cue file with Flacon. It should then automatically detect the big *.flac file (if not, you can specify this manually), and then you should select Flac output format (and optionally configure the encoder), and start the conversion process.



        Flacon v5.4.0







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 16 hours ago









        SeeYouInDisneyland

        1189 bronze badges




        1189 bronze badges










        answered Nov 3 '13 at 15:40









        YazeYaze

        1911 silver badge2 bronze badges




        1911 silver badge2 bronze badges











        • 1





          Welcome to Unix & Linux Stack Exchange! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.

          – slm
          Nov 3 '13 at 15:55













        • still updated in 2017

          – user32012
          Sep 28 '17 at 16:45














        • 1





          Welcome to Unix & Linux Stack Exchange! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.

          – slm
          Nov 3 '13 at 15:55













        • still updated in 2017

          – user32012
          Sep 28 '17 at 16:45








        1




        1





        Welcome to Unix & Linux Stack Exchange! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.

        – slm
        Nov 3 '13 at 15:55







        Welcome to Unix & Linux Stack Exchange! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.

        – slm
        Nov 3 '13 at 15:55















        still updated in 2017

        – user32012
        Sep 28 '17 at 16:45





        still updated in 2017

        – user32012
        Sep 28 '17 at 16:45











        6














        if high-quality files are being used, shnsplit is happily erroring out with



        shnsplit: error: m:ss.ff format can only be used with CD-quality files


        fortunately the flac binary supports --skip=mm:ss.ss and --until=mm:ss.ss so a script can use cuebreakpoints like this:



        [..]
        time[0]="00:00.00"
        c=1
        for ts in $(cuebreakpoints "${cue_file}"); do
        time[${c}]=${ts}
        c=$((c+1))
        done
        time[${c}]='-0'
        for ((i=0;i<$((${#time[@]}-1));i++)); do
        trackno=$(($i+1))
        TRACKNUMBER="$(printf %02d ${trackno})"
        title="$(cueprint --track-number ${trackno} -t '%t' "${cue_file}")"
        flac --silent --exhaustive-model-search --skip=${time[$i]} --until=${time[$(($i+1))]} --tag=ARTIST="${ARTIST}" --tag=ALBUM="${ALBUM}" --tag=DATE="${DATE}" --tag=TITLE="${title}" --tag=TRACKNUMBER="${TRACKNUMBER}" "${aud_file}" --output-name="${TRACKNUMBER}-${title}.flac"
        done





        share|improve this answer


























        • This is the only method that worked for me.

          – coffekid
          Feb 26 '18 at 2:57
















        6














        if high-quality files are being used, shnsplit is happily erroring out with



        shnsplit: error: m:ss.ff format can only be used with CD-quality files


        fortunately the flac binary supports --skip=mm:ss.ss and --until=mm:ss.ss so a script can use cuebreakpoints like this:



        [..]
        time[0]="00:00.00"
        c=1
        for ts in $(cuebreakpoints "${cue_file}"); do
        time[${c}]=${ts}
        c=$((c+1))
        done
        time[${c}]='-0'
        for ((i=0;i<$((${#time[@]}-1));i++)); do
        trackno=$(($i+1))
        TRACKNUMBER="$(printf %02d ${trackno})"
        title="$(cueprint --track-number ${trackno} -t '%t' "${cue_file}")"
        flac --silent --exhaustive-model-search --skip=${time[$i]} --until=${time[$(($i+1))]} --tag=ARTIST="${ARTIST}" --tag=ALBUM="${ALBUM}" --tag=DATE="${DATE}" --tag=TITLE="${title}" --tag=TRACKNUMBER="${TRACKNUMBER}" "${aud_file}" --output-name="${TRACKNUMBER}-${title}.flac"
        done





        share|improve this answer


























        • This is the only method that worked for me.

          – coffekid
          Feb 26 '18 at 2:57














        6












        6








        6







        if high-quality files are being used, shnsplit is happily erroring out with



        shnsplit: error: m:ss.ff format can only be used with CD-quality files


        fortunately the flac binary supports --skip=mm:ss.ss and --until=mm:ss.ss so a script can use cuebreakpoints like this:



        [..]
        time[0]="00:00.00"
        c=1
        for ts in $(cuebreakpoints "${cue_file}"); do
        time[${c}]=${ts}
        c=$((c+1))
        done
        time[${c}]='-0'
        for ((i=0;i<$((${#time[@]}-1));i++)); do
        trackno=$(($i+1))
        TRACKNUMBER="$(printf %02d ${trackno})"
        title="$(cueprint --track-number ${trackno} -t '%t' "${cue_file}")"
        flac --silent --exhaustive-model-search --skip=${time[$i]} --until=${time[$(($i+1))]} --tag=ARTIST="${ARTIST}" --tag=ALBUM="${ALBUM}" --tag=DATE="${DATE}" --tag=TITLE="${title}" --tag=TRACKNUMBER="${TRACKNUMBER}" "${aud_file}" --output-name="${TRACKNUMBER}-${title}.flac"
        done





        share|improve this answer













        if high-quality files are being used, shnsplit is happily erroring out with



        shnsplit: error: m:ss.ff format can only be used with CD-quality files


        fortunately the flac binary supports --skip=mm:ss.ss and --until=mm:ss.ss so a script can use cuebreakpoints like this:



        [..]
        time[0]="00:00.00"
        c=1
        for ts in $(cuebreakpoints "${cue_file}"); do
        time[${c}]=${ts}
        c=$((c+1))
        done
        time[${c}]='-0'
        for ((i=0;i<$((${#time[@]}-1));i++)); do
        trackno=$(($i+1))
        TRACKNUMBER="$(printf %02d ${trackno})"
        title="$(cueprint --track-number ${trackno} -t '%t' "${cue_file}")"
        flac --silent --exhaustive-model-search --skip=${time[$i]} --until=${time[$(($i+1))]} --tag=ARTIST="${ARTIST}" --tag=ALBUM="${ALBUM}" --tag=DATE="${DATE}" --tag=TITLE="${title}" --tag=TRACKNUMBER="${TRACKNUMBER}" "${aud_file}" --output-name="${TRACKNUMBER}-${title}.flac"
        done






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 6 '13 at 19:38









        peter_tuxpeter_tux

        691 silver badge3 bronze badges




        691 silver badge3 bronze badges
















        • This is the only method that worked for me.

          – coffekid
          Feb 26 '18 at 2:57



















        • This is the only method that worked for me.

          – coffekid
          Feb 26 '18 at 2:57

















        This is the only method that worked for me.

        – coffekid
        Feb 26 '18 at 2:57





        This is the only method that worked for me.

        – coffekid
        Feb 26 '18 at 2:57











        3














        If you have cue set to use k3b in in the filetype settings, k3b will automatically split the file if you open the cue file, and allow you to re-rip.






        share|improve this answer






























          3














          If you have cue set to use k3b in in the filetype settings, k3b will automatically split the file if you open the cue file, and allow you to re-rip.






          share|improve this answer




























            3












            3








            3







            If you have cue set to use k3b in in the filetype settings, k3b will automatically split the file if you open the cue file, and allow you to re-rip.






            share|improve this answer













            If you have cue set to use k3b in in the filetype settings, k3b will automatically split the file if you open the cue file, and allow you to re-rip.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Apr 4 '11 at 23:31









            xenoterracidexenoterracide

            27.1k55 gold badges161 silver badges227 bronze badges




            27.1k55 gold badges161 silver badges227 bronze badges


























                1














                There is a project that works for several input files: split2flac



                From the project description:




                split2flac splits one big APE/FLAC/TTA/WV/WAV audio image (or a
                collection of such files, recursively) with CUE sheet into
                FLAC/M4A/MP3/OGG_VORBIS/WAV tracks with tagging, renaming, charset
                conversion of cue sheet, album cover images. It also uses
                configuration file, so no need to pass a lot of arguments every time,
                only an input file. Should work in any POSIX-compliant shell.







                share|improve this answer






























                  1














                  There is a project that works for several input files: split2flac



                  From the project description:




                  split2flac splits one big APE/FLAC/TTA/WV/WAV audio image (or a
                  collection of such files, recursively) with CUE sheet into
                  FLAC/M4A/MP3/OGG_VORBIS/WAV tracks with tagging, renaming, charset
                  conversion of cue sheet, album cover images. It also uses
                  configuration file, so no need to pass a lot of arguments every time,
                  only an input file. Should work in any POSIX-compliant shell.







                  share|improve this answer




























                    1












                    1








                    1







                    There is a project that works for several input files: split2flac



                    From the project description:




                    split2flac splits one big APE/FLAC/TTA/WV/WAV audio image (or a
                    collection of such files, recursively) with CUE sheet into
                    FLAC/M4A/MP3/OGG_VORBIS/WAV tracks with tagging, renaming, charset
                    conversion of cue sheet, album cover images. It also uses
                    configuration file, so no need to pass a lot of arguments every time,
                    only an input file. Should work in any POSIX-compliant shell.







                    share|improve this answer













                    There is a project that works for several input files: split2flac



                    From the project description:




                    split2flac splits one big APE/FLAC/TTA/WV/WAV audio image (or a
                    collection of such files, recursively) with CUE sheet into
                    FLAC/M4A/MP3/OGG_VORBIS/WAV tracks with tagging, renaming, charset
                    conversion of cue sheet, album cover images. It also uses
                    configuration file, so no need to pass a lot of arguments every time,
                    only an input file. Should work in any POSIX-compliant shell.








                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Aug 25 '15 at 15:42









                    Paulo FidalgoPaulo Fidalgo

                    2371 silver badge6 bronze badges




                    2371 silver badge6 bronze badges


























                        1














                        I found mac (which is the command that shntool used for decoding APE files) is way less tolerant than ffmpeg if the source file contains minor errors.



                        Normally ffmpeg would still convert the file completely while mac very likely throws an error during the processing.



                        So I ended up writing a script for spliting APE file by parsing the CUE file and converting the APE file to FLAC files separated by titles using ffmpeg:



                        #!/usr/bin/env python2.7

                        import subprocess as subp
                        import sys
                        import os
                        from os.path import splitext, basename
                        import random
                        import glob

                        records = []
                        filename = ""
                        album=''
                        alb_artist=''
                        codec = 'flac'
                        ffmpeg_exec = 'ffmpeg'
                        encodingList = ('utf-8','euc-kr', 'shift-jis', 'cp936', 'big5')

                        filecontent = open(sys.argv[1]).read()
                        for enc in encodingList:
                        try:
                        lines = filecontent.decode(enc).split('n')
                        encoding = enc
                        break
                        except UnicodeDecodeError as e:
                        if enc == encodingList[-1]:
                        raise e
                        else:
                        pass

                        for l in lines:
                        a = l.split()
                        if not a:
                        continue
                        if a[0] == "FILE":
                        filename = ' '.join(a[1:-1]).strip(''"')
                        elif a[0]=='TRACK':
                        records.append({})
                        records[-1]['index'] = a[1]
                        elif a[0]=='TITLE':
                        if len(records)>0:
                        records[-1]['title'] = ' '.join(a[1:]).strip(''"')
                        else:
                        album = ' '.join(a[1:]).strip(''"')
                        elif a[0]=='INDEX' and a[1]=='01':
                        timea = a[2].split(':')
                        if len(timea) == 3 and int(timea[0]) >= 60:
                        timea.insert(0, str(int(timea[0])/60))
                        timea[1] = str(int(timea[1])%60)
                        times = '{0}.{1}'.format(':'.join(timea[:-1]), timea[-1])
                        records[-1]['start'] = times
                        elif a[0]=='PERFORMER':
                        if len(records)>1:
                        records[-1]['artist'] = ' '.join(a[1:]).strip(''"')
                        else:
                        alb_artist = ' '.join(a[1:]).strip(''"')

                        for i, j in enumerate(records):
                        try:
                        j['stop'] = records[i+1]['start']
                        except IndexError:
                        pass

                        if not os.path.isfile(filename):
                        tmpname = splitext(basename(sys.argv[1]))[0]+splitext(filename)[1]
                        if os.path.exists(tmpname):
                        filename = tmpname
                        del tmpname
                        else:
                        for ext in ('.ape', '.flac', '.wav', '.mp3'):
                        tmpname = splitext(filename)[0] + ext
                        if os.path.exists(tmpname):
                        filename = tmpname
                        break

                        if not os.path.isfile(filename):
                        raise IOError("Can't not find file: {0}".format(filename))

                        fstat = os.stat(filename)
                        atime = fstat.st_atime
                        mtime = fstat.st_mtime

                        records[-1]['stop'] = '99:59:59'

                        if filename.lower().endswith('.flac'):
                        tmpfile = filename
                        else:
                        tmpfile = splitext(filename)[0] + str(random.randint(10000,90000)) + '.flac'

                        try:
                        if filename != tmpfile:
                        ret = subp.call([ffmpeg_exec, '-hide_banner', '-y', '-i', filename,
                        '-c:a', codec,'-compression_level','12','-f','flac',tmpfile])

                        if ret != 0:
                        raise SystemExit('Converting failed.')

                        for i in records:
                        output = i['index'] +' - '+ i['title']+'.flac'
                        commandline = [ffmpeg_exec, '-hide_banner',
                        '-y', '-i', tmpfile,
                        '-c', 'copy',
                        '-ss', i['start'], '-to', i['stop'],
                        '-metadata', u'title={0}'.format(i['title']),
                        '-metadata', u'artist={0}'.format(i.get('artist', '')),
                        '-metadata', u'performer={0}'.format(i.get('artist', '')),
                        '-metadata', u'album={0}'.format(album),
                        '-metadata', 'track={0}/{1}'.format(i['index'], len(records)),
                        '-metadata', u'album_artist={0}'.format(alb_artist),
                        '-metadata', u'composer={0}'.format(alb_artist),
                        '-metadata', 'encoder=Meow',
                        '-write_id3v1', '1',
                        output]
                        ret = subp.call(commandline)
                        if ret == 0:
                        os.utime(output, (atime, mtime))
                        finally:
                        if os.path.isfile(tmpfile):
                        os.remove(tmpfile)





                        share|improve this answer


























                        • You might want to change if os.path.isfile(tmpfile) to if tmpfile != filename and os.path.isfile(tmpfile) to avoid deleting the original file on error.

                          – wolfmanx
                          Jan 19 '18 at 6:26











                        • The condition for setting the track artist must be if len(records)>0.

                          – wolfmanx
                          Jan 19 '18 at 6:41
















                        1














                        I found mac (which is the command that shntool used for decoding APE files) is way less tolerant than ffmpeg if the source file contains minor errors.



                        Normally ffmpeg would still convert the file completely while mac very likely throws an error during the processing.



                        So I ended up writing a script for spliting APE file by parsing the CUE file and converting the APE file to FLAC files separated by titles using ffmpeg:



                        #!/usr/bin/env python2.7

                        import subprocess as subp
                        import sys
                        import os
                        from os.path import splitext, basename
                        import random
                        import glob

                        records = []
                        filename = ""
                        album=''
                        alb_artist=''
                        codec = 'flac'
                        ffmpeg_exec = 'ffmpeg'
                        encodingList = ('utf-8','euc-kr', 'shift-jis', 'cp936', 'big5')

                        filecontent = open(sys.argv[1]).read()
                        for enc in encodingList:
                        try:
                        lines = filecontent.decode(enc).split('n')
                        encoding = enc
                        break
                        except UnicodeDecodeError as e:
                        if enc == encodingList[-1]:
                        raise e
                        else:
                        pass

                        for l in lines:
                        a = l.split()
                        if not a:
                        continue
                        if a[0] == "FILE":
                        filename = ' '.join(a[1:-1]).strip(''"')
                        elif a[0]=='TRACK':
                        records.append({})
                        records[-1]['index'] = a[1]
                        elif a[0]=='TITLE':
                        if len(records)>0:
                        records[-1]['title'] = ' '.join(a[1:]).strip(''"')
                        else:
                        album = ' '.join(a[1:]).strip(''"')
                        elif a[0]=='INDEX' and a[1]=='01':
                        timea = a[2].split(':')
                        if len(timea) == 3 and int(timea[0]) >= 60:
                        timea.insert(0, str(int(timea[0])/60))
                        timea[1] = str(int(timea[1])%60)
                        times = '{0}.{1}'.format(':'.join(timea[:-1]), timea[-1])
                        records[-1]['start'] = times
                        elif a[0]=='PERFORMER':
                        if len(records)>1:
                        records[-1]['artist'] = ' '.join(a[1:]).strip(''"')
                        else:
                        alb_artist = ' '.join(a[1:]).strip(''"')

                        for i, j in enumerate(records):
                        try:
                        j['stop'] = records[i+1]['start']
                        except IndexError:
                        pass

                        if not os.path.isfile(filename):
                        tmpname = splitext(basename(sys.argv[1]))[0]+splitext(filename)[1]
                        if os.path.exists(tmpname):
                        filename = tmpname
                        del tmpname
                        else:
                        for ext in ('.ape', '.flac', '.wav', '.mp3'):
                        tmpname = splitext(filename)[0] + ext
                        if os.path.exists(tmpname):
                        filename = tmpname
                        break

                        if not os.path.isfile(filename):
                        raise IOError("Can't not find file: {0}".format(filename))

                        fstat = os.stat(filename)
                        atime = fstat.st_atime
                        mtime = fstat.st_mtime

                        records[-1]['stop'] = '99:59:59'

                        if filename.lower().endswith('.flac'):
                        tmpfile = filename
                        else:
                        tmpfile = splitext(filename)[0] + str(random.randint(10000,90000)) + '.flac'

                        try:
                        if filename != tmpfile:
                        ret = subp.call([ffmpeg_exec, '-hide_banner', '-y', '-i', filename,
                        '-c:a', codec,'-compression_level','12','-f','flac',tmpfile])

                        if ret != 0:
                        raise SystemExit('Converting failed.')

                        for i in records:
                        output = i['index'] +' - '+ i['title']+'.flac'
                        commandline = [ffmpeg_exec, '-hide_banner',
                        '-y', '-i', tmpfile,
                        '-c', 'copy',
                        '-ss', i['start'], '-to', i['stop'],
                        '-metadata', u'title={0}'.format(i['title']),
                        '-metadata', u'artist={0}'.format(i.get('artist', '')),
                        '-metadata', u'performer={0}'.format(i.get('artist', '')),
                        '-metadata', u'album={0}'.format(album),
                        '-metadata', 'track={0}/{1}'.format(i['index'], len(records)),
                        '-metadata', u'album_artist={0}'.format(alb_artist),
                        '-metadata', u'composer={0}'.format(alb_artist),
                        '-metadata', 'encoder=Meow',
                        '-write_id3v1', '1',
                        output]
                        ret = subp.call(commandline)
                        if ret == 0:
                        os.utime(output, (atime, mtime))
                        finally:
                        if os.path.isfile(tmpfile):
                        os.remove(tmpfile)





                        share|improve this answer


























                        • You might want to change if os.path.isfile(tmpfile) to if tmpfile != filename and os.path.isfile(tmpfile) to avoid deleting the original file on error.

                          – wolfmanx
                          Jan 19 '18 at 6:26











                        • The condition for setting the track artist must be if len(records)>0.

                          – wolfmanx
                          Jan 19 '18 at 6:41














                        1












                        1








                        1







                        I found mac (which is the command that shntool used for decoding APE files) is way less tolerant than ffmpeg if the source file contains minor errors.



                        Normally ffmpeg would still convert the file completely while mac very likely throws an error during the processing.



                        So I ended up writing a script for spliting APE file by parsing the CUE file and converting the APE file to FLAC files separated by titles using ffmpeg:



                        #!/usr/bin/env python2.7

                        import subprocess as subp
                        import sys
                        import os
                        from os.path import splitext, basename
                        import random
                        import glob

                        records = []
                        filename = ""
                        album=''
                        alb_artist=''
                        codec = 'flac'
                        ffmpeg_exec = 'ffmpeg'
                        encodingList = ('utf-8','euc-kr', 'shift-jis', 'cp936', 'big5')

                        filecontent = open(sys.argv[1]).read()
                        for enc in encodingList:
                        try:
                        lines = filecontent.decode(enc).split('n')
                        encoding = enc
                        break
                        except UnicodeDecodeError as e:
                        if enc == encodingList[-1]:
                        raise e
                        else:
                        pass

                        for l in lines:
                        a = l.split()
                        if not a:
                        continue
                        if a[0] == "FILE":
                        filename = ' '.join(a[1:-1]).strip(''"')
                        elif a[0]=='TRACK':
                        records.append({})
                        records[-1]['index'] = a[1]
                        elif a[0]=='TITLE':
                        if len(records)>0:
                        records[-1]['title'] = ' '.join(a[1:]).strip(''"')
                        else:
                        album = ' '.join(a[1:]).strip(''"')
                        elif a[0]=='INDEX' and a[1]=='01':
                        timea = a[2].split(':')
                        if len(timea) == 3 and int(timea[0]) >= 60:
                        timea.insert(0, str(int(timea[0])/60))
                        timea[1] = str(int(timea[1])%60)
                        times = '{0}.{1}'.format(':'.join(timea[:-1]), timea[-1])
                        records[-1]['start'] = times
                        elif a[0]=='PERFORMER':
                        if len(records)>1:
                        records[-1]['artist'] = ' '.join(a[1:]).strip(''"')
                        else:
                        alb_artist = ' '.join(a[1:]).strip(''"')

                        for i, j in enumerate(records):
                        try:
                        j['stop'] = records[i+1]['start']
                        except IndexError:
                        pass

                        if not os.path.isfile(filename):
                        tmpname = splitext(basename(sys.argv[1]))[0]+splitext(filename)[1]
                        if os.path.exists(tmpname):
                        filename = tmpname
                        del tmpname
                        else:
                        for ext in ('.ape', '.flac', '.wav', '.mp3'):
                        tmpname = splitext(filename)[0] + ext
                        if os.path.exists(tmpname):
                        filename = tmpname
                        break

                        if not os.path.isfile(filename):
                        raise IOError("Can't not find file: {0}".format(filename))

                        fstat = os.stat(filename)
                        atime = fstat.st_atime
                        mtime = fstat.st_mtime

                        records[-1]['stop'] = '99:59:59'

                        if filename.lower().endswith('.flac'):
                        tmpfile = filename
                        else:
                        tmpfile = splitext(filename)[0] + str(random.randint(10000,90000)) + '.flac'

                        try:
                        if filename != tmpfile:
                        ret = subp.call([ffmpeg_exec, '-hide_banner', '-y', '-i', filename,
                        '-c:a', codec,'-compression_level','12','-f','flac',tmpfile])

                        if ret != 0:
                        raise SystemExit('Converting failed.')

                        for i in records:
                        output = i['index'] +' - '+ i['title']+'.flac'
                        commandline = [ffmpeg_exec, '-hide_banner',
                        '-y', '-i', tmpfile,
                        '-c', 'copy',
                        '-ss', i['start'], '-to', i['stop'],
                        '-metadata', u'title={0}'.format(i['title']),
                        '-metadata', u'artist={0}'.format(i.get('artist', '')),
                        '-metadata', u'performer={0}'.format(i.get('artist', '')),
                        '-metadata', u'album={0}'.format(album),
                        '-metadata', 'track={0}/{1}'.format(i['index'], len(records)),
                        '-metadata', u'album_artist={0}'.format(alb_artist),
                        '-metadata', u'composer={0}'.format(alb_artist),
                        '-metadata', 'encoder=Meow',
                        '-write_id3v1', '1',
                        output]
                        ret = subp.call(commandline)
                        if ret == 0:
                        os.utime(output, (atime, mtime))
                        finally:
                        if os.path.isfile(tmpfile):
                        os.remove(tmpfile)





                        share|improve this answer













                        I found mac (which is the command that shntool used for decoding APE files) is way less tolerant than ffmpeg if the source file contains minor errors.



                        Normally ffmpeg would still convert the file completely while mac very likely throws an error during the processing.



                        So I ended up writing a script for spliting APE file by parsing the CUE file and converting the APE file to FLAC files separated by titles using ffmpeg:



                        #!/usr/bin/env python2.7

                        import subprocess as subp
                        import sys
                        import os
                        from os.path import splitext, basename
                        import random
                        import glob

                        records = []
                        filename = ""
                        album=''
                        alb_artist=''
                        codec = 'flac'
                        ffmpeg_exec = 'ffmpeg'
                        encodingList = ('utf-8','euc-kr', 'shift-jis', 'cp936', 'big5')

                        filecontent = open(sys.argv[1]).read()
                        for enc in encodingList:
                        try:
                        lines = filecontent.decode(enc).split('n')
                        encoding = enc
                        break
                        except UnicodeDecodeError as e:
                        if enc == encodingList[-1]:
                        raise e
                        else:
                        pass

                        for l in lines:
                        a = l.split()
                        if not a:
                        continue
                        if a[0] == "FILE":
                        filename = ' '.join(a[1:-1]).strip(''"')
                        elif a[0]=='TRACK':
                        records.append({})
                        records[-1]['index'] = a[1]
                        elif a[0]=='TITLE':
                        if len(records)>0:
                        records[-1]['title'] = ' '.join(a[1:]).strip(''"')
                        else:
                        album = ' '.join(a[1:]).strip(''"')
                        elif a[0]=='INDEX' and a[1]=='01':
                        timea = a[2].split(':')
                        if len(timea) == 3 and int(timea[0]) >= 60:
                        timea.insert(0, str(int(timea[0])/60))
                        timea[1] = str(int(timea[1])%60)
                        times = '{0}.{1}'.format(':'.join(timea[:-1]), timea[-1])
                        records[-1]['start'] = times
                        elif a[0]=='PERFORMER':
                        if len(records)>1:
                        records[-1]['artist'] = ' '.join(a[1:]).strip(''"')
                        else:
                        alb_artist = ' '.join(a[1:]).strip(''"')

                        for i, j in enumerate(records):
                        try:
                        j['stop'] = records[i+1]['start']
                        except IndexError:
                        pass

                        if not os.path.isfile(filename):
                        tmpname = splitext(basename(sys.argv[1]))[0]+splitext(filename)[1]
                        if os.path.exists(tmpname):
                        filename = tmpname
                        del tmpname
                        else:
                        for ext in ('.ape', '.flac', '.wav', '.mp3'):
                        tmpname = splitext(filename)[0] + ext
                        if os.path.exists(tmpname):
                        filename = tmpname
                        break

                        if not os.path.isfile(filename):
                        raise IOError("Can't not find file: {0}".format(filename))

                        fstat = os.stat(filename)
                        atime = fstat.st_atime
                        mtime = fstat.st_mtime

                        records[-1]['stop'] = '99:59:59'

                        if filename.lower().endswith('.flac'):
                        tmpfile = filename
                        else:
                        tmpfile = splitext(filename)[0] + str(random.randint(10000,90000)) + '.flac'

                        try:
                        if filename != tmpfile:
                        ret = subp.call([ffmpeg_exec, '-hide_banner', '-y', '-i', filename,
                        '-c:a', codec,'-compression_level','12','-f','flac',tmpfile])

                        if ret != 0:
                        raise SystemExit('Converting failed.')

                        for i in records:
                        output = i['index'] +' - '+ i['title']+'.flac'
                        commandline = [ffmpeg_exec, '-hide_banner',
                        '-y', '-i', tmpfile,
                        '-c', 'copy',
                        '-ss', i['start'], '-to', i['stop'],
                        '-metadata', u'title={0}'.format(i['title']),
                        '-metadata', u'artist={0}'.format(i.get('artist', '')),
                        '-metadata', u'performer={0}'.format(i.get('artist', '')),
                        '-metadata', u'album={0}'.format(album),
                        '-metadata', 'track={0}/{1}'.format(i['index'], len(records)),
                        '-metadata', u'album_artist={0}'.format(alb_artist),
                        '-metadata', u'composer={0}'.format(alb_artist),
                        '-metadata', 'encoder=Meow',
                        '-write_id3v1', '1',
                        output]
                        ret = subp.call(commandline)
                        if ret == 0:
                        os.utime(output, (atime, mtime))
                        finally:
                        if os.path.isfile(tmpfile):
                        os.remove(tmpfile)






                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Dec 10 '15 at 15:27









                        MeowMeow

                        2272 silver badges4 bronze badges




                        2272 silver badges4 bronze badges
















                        • You might want to change if os.path.isfile(tmpfile) to if tmpfile != filename and os.path.isfile(tmpfile) to avoid deleting the original file on error.

                          – wolfmanx
                          Jan 19 '18 at 6:26











                        • The condition for setting the track artist must be if len(records)>0.

                          – wolfmanx
                          Jan 19 '18 at 6:41



















                        • You might want to change if os.path.isfile(tmpfile) to if tmpfile != filename and os.path.isfile(tmpfile) to avoid deleting the original file on error.

                          – wolfmanx
                          Jan 19 '18 at 6:26











                        • The condition for setting the track artist must be if len(records)>0.

                          – wolfmanx
                          Jan 19 '18 at 6:41

















                        You might want to change if os.path.isfile(tmpfile) to if tmpfile != filename and os.path.isfile(tmpfile) to avoid deleting the original file on error.

                        – wolfmanx
                        Jan 19 '18 at 6:26





                        You might want to change if os.path.isfile(tmpfile) to if tmpfile != filename and os.path.isfile(tmpfile) to avoid deleting the original file on error.

                        – wolfmanx
                        Jan 19 '18 at 6:26













                        The condition for setting the track artist must be if len(records)>0.

                        – wolfmanx
                        Jan 19 '18 at 6:41





                        The condition for setting the track artist must be if len(records)>0.

                        – wolfmanx
                        Jan 19 '18 at 6:41











                        1














                        shntool on Ubuntu 14.04



                        snhtool is missing the mac (Monkey's Audio Console) executable dependency, and the only package I could find it was in the flacon PPA:



                        sudo add-apt-repository -y ppa:flacon
                        sudo apt-get update
                        sudo apt-get install -y flacon shntool
                        shntool split -f *.cue -o flac -t '%n - %p - %t' *.ape


                        flacon is a GUI for shntool, but it comes with all the codecs it needs... otherwise I got the error:



                        shnsplit: warning: failed to read data from input file using format: [ape]
                        shnsplit: + you may not have permission to read file: [example.ape]
                        shnsplit: + arguments may be incorrect for decoder: [mac]
                        shnsplit: + verify that the decoder is installed and in your PATH
                        shnsplit: + this file may be unsupported, truncated or corrupt
                        shnsplit: error: cannot continue due to error(s) shown above





                        share|improve this answer






























                          1














                          shntool on Ubuntu 14.04



                          snhtool is missing the mac (Monkey's Audio Console) executable dependency, and the only package I could find it was in the flacon PPA:



                          sudo add-apt-repository -y ppa:flacon
                          sudo apt-get update
                          sudo apt-get install -y flacon shntool
                          shntool split -f *.cue -o flac -t '%n - %p - %t' *.ape


                          flacon is a GUI for shntool, but it comes with all the codecs it needs... otherwise I got the error:



                          shnsplit: warning: failed to read data from input file using format: [ape]
                          shnsplit: + you may not have permission to read file: [example.ape]
                          shnsplit: + arguments may be incorrect for decoder: [mac]
                          shnsplit: + verify that the decoder is installed and in your PATH
                          shnsplit: + this file may be unsupported, truncated or corrupt
                          shnsplit: error: cannot continue due to error(s) shown above





                          share|improve this answer




























                            1












                            1








                            1







                            shntool on Ubuntu 14.04



                            snhtool is missing the mac (Monkey's Audio Console) executable dependency, and the only package I could find it was in the flacon PPA:



                            sudo add-apt-repository -y ppa:flacon
                            sudo apt-get update
                            sudo apt-get install -y flacon shntool
                            shntool split -f *.cue -o flac -t '%n - %p - %t' *.ape


                            flacon is a GUI for shntool, but it comes with all the codecs it needs... otherwise I got the error:



                            shnsplit: warning: failed to read data from input file using format: [ape]
                            shnsplit: + you may not have permission to read file: [example.ape]
                            shnsplit: + arguments may be incorrect for decoder: [mac]
                            shnsplit: + verify that the decoder is installed and in your PATH
                            shnsplit: + this file may be unsupported, truncated or corrupt
                            shnsplit: error: cannot continue due to error(s) shown above





                            share|improve this answer













                            shntool on Ubuntu 14.04



                            snhtool is missing the mac (Monkey's Audio Console) executable dependency, and the only package I could find it was in the flacon PPA:



                            sudo add-apt-repository -y ppa:flacon
                            sudo apt-get update
                            sudo apt-get install -y flacon shntool
                            shntool split -f *.cue -o flac -t '%n - %p - %t' *.ape


                            flacon is a GUI for shntool, but it comes with all the codecs it needs... otherwise I got the error:



                            shnsplit: warning: failed to read data from input file using format: [ape]
                            shnsplit: + you may not have permission to read file: [example.ape]
                            shnsplit: + arguments may be incorrect for decoder: [mac]
                            shnsplit: + verify that the decoder is installed and in your PATH
                            shnsplit: + this file may be unsupported, truncated or corrupt
                            shnsplit: error: cannot continue due to error(s) shown above






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jul 31 '17 at 12:56









                            Ciro Santilli 新疆改造中心996ICU六四事件Ciro Santilli 新疆改造中心996ICU六四事件

                            6,2902 gold badges53 silver badges51 bronze badges




                            6,2902 gold badges53 silver badges51 bronze badges




















                                protected by Community Dec 22 '14 at 9:16



                                Thank you for your interest in this question.
                                Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                                Would you like to answer one of these unanswered questions instead?



                                Popular posts from this blog

                                Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

                                Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

                                Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...