A bash tool for splitting single FLAC files with CUE sheets into individual, properly tagged tracks with album art.
Find a file
2025-05-02 17:49:16 +03:00
flacsplit.sh initial commit 2025-05-02 17:49:16 +03:00
LICENSE Initial commit 2025-05-02 17:46:52 +03:00
README.md initial commit 2025-05-02 17:49:16 +03:00
README_EN.md initial commit 2025-05-02 17:49:16 +03:00

FLAC Splitter (flacsplit.sh)

A bash tool for splitting single FLAC files with CUE sheets into individual, properly tagged tracks with album art.

Features

  • Splits a single FLAC file into individual tracks using CUE sheet
  • Handles Cyrillic and other non-ASCII characters (converts CUE from Windows-1251 to UTF-8)
  • Tags tracks with metadata from the CUE file
  • Automatically searches for and embeds album cover art from:
    1. MusicBrainz/CoverArtArchive (primary source)
    2. Last.fm (secondary source)
    3. Suggests a Google Images search link if no cover is found automatically
  • Uses unique filenames for cover art to avoid conflicts between albums
  • Handles URL redirects from cover art sources
  • Supports both ffmpeg and metaflac for embedding cover art

Requirements

  • shnsplit (from the 'shntool' package)
  • cuetag.sh (usually comes with 'cuetools')
  • jq for JSON parsing
  • file for MIME type detection
  • ffmpeg (recommended) or metaflac for embedding cover art

Install dependencies on macOS:

brew install shntool cuetools jq ffmpeg

On Debian/Ubuntu:

apt-get install shntool cuetools jq ffmpeg

Usage

  1. Place the script in a directory with a single FLAC file and its corresponding CUE sheet
  2. Make the script executable: chmod +x flacsplit.sh
  3. Run the script: ./flacsplit.sh

Options

  • -f, --force: Force re-splitting even if tracks already exist

How It Works

  1. File Detection:

    • Locates a CUE sheet and the corresponding FLAC file in the current directory
    • Converts the CUE sheet from Windows-1251 to UTF-8 encoding
  2. Track Splitting:

    • Checks if tracks have already been split; if so, skips splitting unless --force is used
    • Uses shnsplit to separate the FLAC file into individual tracks
    • Names tracks using %n - %t format (track number - track title)
  3. Metadata Tagging:

    • Uses cuetag.sh to apply metadata (artist, album, track names, etc.) from the CUE file
  4. Cover Art Retrieval:

    • Creates a unique filename for the cover based on artist and album name
    • Searches for cover art from MusicBrainz using exact artist+album query
    • If not found, tries alternative MusicBrainz search methods
    • If still not found, attempts to retrieve cover from Last.fm
    • As a last resort, provides a Google Images search URL for manual download
  5. Cover Art Embedding:

    • If ffmpeg is available, uses it to embed cover art with proper metadata
    • Otherwise falls back to metaflac for basic cover art embedding

Examples

Basic usage:

./flacsplit.sh

Force re-splitting:

./flacsplit.sh --force

Troubleshooting

  • No cover found: If automatic cover search fails, the script will provide a Google Images search URL. Download the cover manually with the filename shown in the output.
  • Wrong cover: Delete the cover image and re-run the script, or find a cover manually.
  • Encoding issues: Make sure your CUE file is properly encoded (script attempts to convert from Windows-1251 to UTF-8).

Notes

  • The script creates temporary files that are cleaned up upon completion
  • Original FLAC file and CUE sheet are preserved
  • Cover art images are retained after script execution