A bash tool for splitting single FLAC files with CUE sheets into individual, properly tagged tracks with album art.
| flacsplit.sh | ||
| LICENSE | ||
| README.md | ||
| README_EN.md | ||
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:
- MusicBrainz/CoverArtArchive (primary source)
- Last.fm (secondary source)
- 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')jqfor JSON parsingfilefor MIME type detectionffmpeg(recommended) ormetaflacfor embedding cover art
Install dependencies on macOS:
brew install shntool cuetools jq ffmpeg
On Debian/Ubuntu:
apt-get install shntool cuetools jq ffmpeg
Usage
- Place the script in a directory with a single FLAC file and its corresponding CUE sheet
- Make the script executable:
chmod +x flacsplit.sh - Run the script:
./flacsplit.sh
Options
-f, --force: Force re-splitting even if tracks already exist
How It Works
-
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
-
Track Splitting:
- Checks if tracks have already been split; if so, skips splitting unless
--forceis used - Uses
shnsplitto separate the FLAC file into individual tracks - Names tracks using
%n - %tformat (track number - track title)
- Checks if tracks have already been split; if so, skips splitting unless
-
Metadata Tagging:
- Uses
cuetag.shto apply metadata (artist, album, track names, etc.) from the CUE file
- Uses
-
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
-
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