Skip to content

Instantly share code, notes, and snippets.

@defanator
Forked from lfilho/cuetag.sh
Created July 4, 2019 17:20
Show Gist options
  • Select an option

  • Save defanator/e7b9df936eea70a66675842c70bf5c83 to your computer and use it in GitHub Desktop.

Select an option

Save defanator/e7b9df936eea70a66675842c70bf5c83 to your computer and use it in GitHub Desktop.

Revisions

  1. @lfilho lfilho revised this gist May 30, 2015. 1 changed file with 5 additions and 4 deletions.
    9 changes: 5 additions & 4 deletions split-flac.sh
    Original file line number Diff line number Diff line change
    @@ -2,14 +2,15 @@
    brew install cuetools flac ffmpeg shntool

    # Split flac file by cue
    shnsplit -o flac -f file.cue file.flac
    shnsplit -o flac -t "%n - %t" -f file.cue file.flac
    rm file.flac

    # Download cuetag.sh from https://github.com/gumayunov/split-cue/blob/master/cuetag and fill meta-info for the resulting flac files
    # Or use the cuetag.sh below (copied from above link on 2015-05-30
    cuetag.sh file.cue split-track*.flac
    cuetag.sh file.cue *.flac

    # Convert to ALAC:
    # for f in split-track*.flac; do ffmpeg -i "$f" -acodec alac "${f%.flac}.m4a"; done
    # for f in *.flac; do ffmpeg -i "$f" -acodec alac "${f%.flac}.m4a"; done

    # Convert to MP3:
    for f in split-track*.flac; do ffmpeg -i "$f" -ab 320k -ac 2 -ar 48000 ${f%.*}.mp3; done
    for f in *.flac; do ffmpeg -i "$f" -ab 320k -ac 2 -ar 48000 "${f%.*}.mp3"; done
  2. @lfilho lfilho renamed this gist May 30, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. @lfilho lfilho created this gist May 30, 2015.
    170 changes: 170 additions & 0 deletions cuetag.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,170 @@
    #! /bin/sh

    # cuetag.sh - tag files based on cue/toc file information
    # uses cueprint output
    # usage: cuetag.sh <cuefile|tocfile> [file]...

    CUEPRINT=cueprint
    cue_file=""

    usage()
    {
    echo "usage: cuetag.sh <cuefile|tocfile> [file]..."
    }

    # Vorbis Comments
    # for FLAC and Ogg Vorbis files
    vorbis()
    {
    # FLAC tagging
    # --remove-vc-all overwrites existing comments
    METAFLAC="metaflac --remove-all-tags --import-tags-from=-"

    # Ogg Vorbis tagging
    # -w overwrites existing comments
    # -a appends to existing comments
    VORBISCOMMENT="vorbiscomment -w -c -"

    case "$2" in
    *.[Ff][Ll][Aa][Cc])
    VORBISTAG=$METAFLAC
    ;;
    *.[Oo][Gg][Gg])
    VORBISTAG=$VORBISCOMMENT
    ;;
    esac

    # space seperated list of recomended stardard field names
    # see http://www.xiph.org/ogg/vorbis/doc/v-comment.html
    # TRACKTOTAL is not in the Xiph recomendation, but is in common use

    fields='TITLE VERSION ALBUM TRACKNUMBER TRACKTOTAL ARTIST PERFORMER COPYRIGHT LICENSE ORGANIZATION DESCRIPTION GENRE DATE LOCATION CONTACT ISRC'

    # fields' corresponding cueprint conversion characters
    # seperate alternates with a space

    TITLE='%t'
    VERSION=''
    ALBUM='%T'
    TRACKNUMBER='%n'
    TRACKTOTAL='%N'
    ARTIST='%c %p'
    PERFORMER='%p'
    COPYRIGHT=''
    LICENSE=''
    ORGANIZATION=''
    DESCRIPTION='%m'
    GENRE='%g'
    DATE=''
    LOCATION=''
    CONTACT=''
    ISRC='%i %u'

    (for field in $fields; do
    value=""
    for conv in `eval echo \\$$field`; do
    value=`$CUEPRINT -n $1 -t "$conv\n" "$cue_file"`

    if [ -n "$value" ]; then
    echo "$field=$value"
    break
    fi
    done
    done) | $VORBISTAG "$2"
    }

    id3()
    {
    MP3INFO=mp3info

    # space seperated list of ID3 v1.1 tags
    # see http://id3lib.sourceforge.net/id3/idev1.html

    fields="TITLE ALBUM ARTIST YEAR COMMENT GENRE TRACKNUMBER"

    # fields' corresponding cueprint conversion characters
    # seperate alternates with a space

    TITLE='%t'
    ALBUM='%T'
    ARTIST='%p'
    YEAR=''
    COMMENT='%c'
    GENRE='%g'
    TRACKNUMBER='%n'

    for field in $fields; do
    value=""
    for conv in `eval echo \\$$field`; do
    value=`$CUEPRINT -n $1 -t "$conv\n" "$cue_file"`

    if [ -n "$value" ]; then
    break
    fi
    done

    if [ -n "$value" ]; then
    case $field in
    TITLE)
    $MP3INFO -t "$value" "$2"
    ;;
    ALBUM)
    $MP3INFO -l "$value" "$2"
    ;;
    ARTIST)
    $MP3INFO -a "$value" "$2"
    ;;
    YEAR)
    $MP3INFO -y "$value" "$2"
    ;;
    COMMENT)
    $MP3INFO -c "$value" "$2"
    ;;
    GENRE)
    $MP3INFO -g "$value" "$2"
    ;;
    TRACKNUMBER)
    $MP3INFO -n "$value" "$2"
    ;;
    esac
    fi
    done
    }

    main()
    {
    if [ $# -lt 1 ]; then
    usage
    exit
    fi

    cue_file=$1
    shift

    ntrack=`cueprint -d '%N' "$cue_file"`
    trackno=1

    if [ $# -ne $ntrack ]; then
    echo "warning: number of files does not match number of tracks"
    fi

    for file in "$@"; do
    case $file in
    *.[Ff][Ll][Aa][Cc])
    vorbis $trackno "$file"
    ;;
    *.[Oo][Gg][Gg])
    vorbis $trackno "$file"
    ;;
    *.[Mm][Pp]3)
    id3 $trackno "$file"
    ;;
    *)
    echo "$file: uknown file type"
    ;;
    esac
    trackno=$(($trackno + 1))
    done
    }

    main "$@"
    15 changes: 15 additions & 0 deletions split-flac
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    # Dependencies
    brew install cuetools flac ffmpeg shntool

    # Split flac file by cue
    shnsplit -o flac -f file.cue file.flac

    # Download cuetag.sh from https://github.com/gumayunov/split-cue/blob/master/cuetag and fill meta-info for the resulting flac files
    # Or use the cuetag.sh below (copied from above link on 2015-05-30
    cuetag.sh file.cue split-track*.flac

    # Convert to ALAC:
    # for f in split-track*.flac; do ffmpeg -i "$f" -acodec alac "${f%.flac}.m4a"; done

    # Convert to MP3:
    for f in split-track*.flac; do ffmpeg -i "$f" -ab 320k -ac 2 -ar 48000 ${f%.*}.mp3; done