Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # cue2flacs
- # Copyright (C) 2012 Julian Hughes julianhughes<at>gmailDOTcom
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- #
- # DEPENDENCIES:
- # shntool ; cuetag ; flac ; iconv ; python-chardet
- # and any other codecs required: for a list of supported codecs see
- # the shntool manpage
- #
- function usage ()
- {
- printf "\n\nUSAGE:\
- \t$(basename "$0") /path/to/cue_file.cue\n
- \tUse find for recursion/multiple cue+image files:\n
- \tfind <path> -iname "*.cue" -execdir $(basename "$0") "{}" \+\n
- \tThe lossless file must be named exactly as stated in the cue\n\tfile.
- \n\t$(basename "$0") splits cue+lossless into individual flacs, named
- \tand tagged using the info in the cue.
- \tIf the cue sheet is non UTF-8 then a new UTF-8 cue is created.
- \tThis preserves diacritic marks and non-Latin characters.\n
- \t$(basename "$0") outputs to a new directory whose name is derived
- \tfrom the cue's first TITLE field. No existing files are deleted
- \toverwritten or modified by this script.
- \tFor a list of supported codecs see the shntool manpage.\n
- \tThere are no user options or settings.\n
- \tI didn't include error checking so if it fails uncomment
- \t'set -x' and have a look for yourself.\n\n"
- }
- if [ $# -lt 1 ]; then
- usage
- exit 1
- fi
- for i in "$@" ; do
- #find character encoding of cue. if not utf-8 then create new utf-8 cue
- UTFCUE="${i%.*}"_utf.cue
- CHARSET="$(chardet "$i" |cut -d ":" -f 2|cut -d "(" -f 1 )"
- if [ "$CHARSET" != utf-8 ]; then
- iconv -f "$CHARSET" -t utf8 "$i" -o "$UTFCUE"
- CUE="$UTFCUE"
- else
- CUE="$i"
- fi
- #get lossless image file name from $CUE
- IMG="$(dirname "$i")"/"$(grep FILE "$CUE"|awk -F "\"" '{print $2}')"
- #get album title from $CUE; remove unwanted characters.
- ALBUM="$(cueprint -d '%T\n' "$CUE")"
- ALBUM="$(echo $ALBUM |sed 's/[;]/-/g;s/[/]/-/g;s/[<]/-/g;s/[>]/-/g;s/[:]/-/g;s/[|]/-/g;s/[\]/-/g;s/[\]/-/g')"
- OUTDIR="$(dirname "$i")"/$ALBUM
- #quit if lossless image file doesn't exist
- if [ ! -e "$IMG" ]; then
- printf "\n\tSupported lossless file not found. Check that cue \
- file references a valid file\n\n"
- exit
- fi
- #create output directory
- if [ ! -d "$OUTDIR" ]; then
- mkdir "$OUTDIR"
- fi
- #split image and set file names from cue: 'number - title'
- shnsplit -d "$OUTDIR" -f "$CUE" -t "%n - %t" -o flac "$IMG"
- #remove unwanted pregap files (if any)
- if [ -e "$OUTDIR"/"00 - pregap.flac" ]; then
- rm "$OUTDIR"/"00 - pregap.flac"
- fi
- #write tags from cue to new files
- cuetag "$CUE" "$OUTDIR"/*.flac
- done
- exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement