summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Bruhin <git@the-compiler.org>2012-10-13 20:44:49 +0200
committerFlorian Bruhin <git@the-compiler.org>2012-10-13 20:44:49 +0200
commit5f9ac8c61bcbe64bad16ca33e4fe0511a38d0e1a (patch)
tree72f95027770ded3772f32fd25d8b2c4771fad530
downloaddrg2flac-5f9ac8c61bcbe64bad16ca33e4fe0511a38d0e1a.tar.gz
drg2flac-5f9ac8c61bcbe64bad16ca33e4fe0511a38d0e1a.zip
Initial commit
-rwxr-xr-xdrg2flac.sh153
1 files changed, 153 insertions, 0 deletions
diff --git a/drg2flac.sh b/drg2flac.sh
new file mode 100755
index 0000000..fa0e8d1
--- /dev/null
+++ b/drg2flac.sh
@@ -0,0 +1,153 @@
+#!/bin/bash
+# vim: set fileencoding=utf-8 ts=4 sts=4 sw=4 tw=80 expandtab :
+
+# Copyright (C) 2012 Florian Bruhin <drg2flac@the-compiler.org>
+
+# drg2flac 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.
+#
+# drg2flac 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 drg2flac If not, see <http://www.gnu.org/licenses/>.
+cleanup() {
+ [[ "$tmp" ]] && rm -rf "$tmp"
+}
+trap cleanup EXIT
+
+
+# Check if the tools we need exist
+for bin in convert drg2sbg sbagen flac tput; do
+ if ! which "$bin" &>/dev/null; then
+ echo "Error: the tool \"$bin\" is needed for this script to work, but"
+ echo "is not installed."
+ exit 1
+ fi
+done
+
+# Colors!
+cred="$(tput setaf 1)"
+cres="$(tput sgr0)"
+cgreen="$(tput setaf 2)"
+cblue="$(tput setaf 7)"
+cbold="$(tput bold)"
+
+
+usage() {
+ cat << EOT
+drg2flac - Convert I-Doser drg files to flac
+Copyright (C) 2012 Florian Bruhin <drg2flac@the-compiler.org>
+
+Usage: $0 [options] file [file ...]
+
+Options:
+ -h/--help Displays this help
+ -o/--output <file> Use <file> as output file (can only be used
+ when there is only one input file)
+ -O/--options <options> Options to pass to flac
+ -a/--artist <artist> Artist to set in the FLAC tags.
+ Defaults to "I-Doser"
+EOT
+}
+
+error() {
+ echo "${cred}An error occured while $2${cres}" >&2
+ echo "${cred}Skipping file $1${cres}" >&2
+}
+
+# Parse options
+while :; do
+ case $1 in
+ -h|--help)
+ usage
+ exit 0
+ ;;
+ -o|--output)
+ if [[ -z "$2" || "$2" == -* ]]; then
+ usage
+ exit 1
+ fi
+ outfile="$2"
+ shift 2
+ ;;
+ -O|--options)
+ flacopts="$2"
+ shift 2
+ ;;
+ -a|--artist)
+ if [[ -z "$2" || "$2" == -* ]]; then
+ usage
+ exit 1
+ fi
+ artist="$2"
+ shift 2
+ ;;
+ --) # end of options
+ shift
+ break
+ ;;
+ -*) # unknown option
+ usage
+ exit 1
+ ;;
+ *) # no more options
+ break
+ ;;
+ esac
+done
+if (($# == 0)); then
+ echo "${cred}Error:${cres} No input file given." >&2
+ echo
+ usage
+ exit 1
+fi
+if [[ "$outfile" && $# > 1 ]]; then
+ echo "${cred}Error:${cres} --outfile may only be specified with one input file." >&2
+ exit 1
+fi
+
+tmp=$(mktemp -d)
+
+# Convert
+for infile in "$@"; do
+ echo "${cbold}===== $infile =====${cres}"
+ echo
+ echo "${cblue}Getting metadata${cres}"
+
+ title=$(drg2sbg -r 2 "$infile")
+ (( $? != 0 )) && { error "$infile" "getting the title"; continue ;}
+
+ desc=$(drg2sbg -r 3 "$infile")
+ (( $? != 0 )) && { error "$infile" "getting the description"; continue ;}
+
+ drg2sbg -r 3 -o "$tmp/image" "$infile"
+ (( $? != 0 )) && { error "$infile" "getting the image"; continue ;}
+
+ echo "${cblue}Converting image${cres}"
+ convert "$tmp/image" "$tmp/image.png"
+ (( $? != 0 )) && { error "$infile" "converting the image"; continue ;}
+
+ echo "${cblue}Converting drg to sbg${cres}"
+ drg2sbg -o "$tmp/sbg" "$infile"
+ (( $? != 0 )) && { error "$infile" "converting drg to sbg"; continue ;}
+
+ echo "${cblue}Converting sbg to wav${cres}"
+ sbagen -W -o "$tmp/wav" "$tmp/sbg"
+ (( $? != 0 )) && { error "$infile" "converting sbg to wav"; continue ;}
+
+ echo "${cblue}Converting wav to flac${cres}"
+ [[ -z "$outfile" ]] && outfile="${infile%.*}.flac"
+ [[ -z "$artist" ]] && artist="I-Doser"
+ flacopts+=" --no-mid-side"
+ flac $flacopts -T "ARTIST=$artist" -T "TITLE=$title" \
+ -T ENCODING="converted by drg2flac using flac $flacopts" \
+ --picture="$tmp/image.png" -o "$outfile" "$infile"
+ (( $? != 0 )) && { error "$infile" "converting wav to flac"; continue ;}
+
+ echo "${cgreen}Done!${cres}"
+done