aboutsummaryrefslogtreecommitdiffstats
path: root/cli
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2017-11-03 18:31:03 +0800
committerAaron LI <aly@aaronly.me>2017-11-03 18:31:03 +0800
commitbc87a53a283d7dec8c52cccf4689fb2d9765a277 (patch)
tree8a859562087f2999f901cce4eced0827c4a2b944 /cli
parentb50463d171ade46f549c5331e8ad317b410ac0f2 (diff)
downloadatoolbox-bc87a53a283d7dec8c52cccf4689fb2d9765a277.tar.bz2
Move several scripts from unix/ to cli/
Diffstat (limited to 'cli')
-rwxr-xr-xcli/ape2mp3.sh111
-rwxr-xr-xcli/cueape2flac.sh71
-rwxr-xr-xcli/eps2pdf.sh8
-rwxr-xr-xcli/jpg2pdf.sh36
-rwxr-xr-xcli/m4a2mp3.sh8
-rwxr-xr-xcli/wav2flac.sh97
6 files changed, 331 insertions, 0 deletions
diff --git a/cli/ape2mp3.sh b/cli/ape2mp3.sh
new file mode 100755
index 0000000..d9cf6d6
--- /dev/null
+++ b/cli/ape2mp3.sh
@@ -0,0 +1,111 @@
+#!/bin/sh
+
+### ###
+# For APE & CUE file --> Mp3 #
+# Version : 0.20 #
+# This script build high quality mp3 from APE. #
+# You just run it in the dir include APE & CUE file. #
+# #
+# Author : kevin.li823@gmail.com #
+### ###
+
+echo Lame is the best mp3 encoder!
+export APE_FILE=`ls *.[aA][pP][eE]`
+export CUE_FILE=`ls *.[cC][uU][eE]`
+export WAV_FILE=${APE_FILE%ape}wav
+export UTF_CUE_FILE='UTF.cue'
+
+ALBUM=
+CD_ACTOR=
+GENRE=
+DATE=2000
+ACTOR=
+TRACK=
+TITLE=
+
+# Tools have been Installed
+which dos2unix >/dev/null 2>&1 || (echo No dos2unix in System; exit )
+which mac >/dev/null 2>&1 || (echo No mac in System; exit )
+which bchunk >/dev/null 2>&1 || (echo No bchunk in System; exit )
+which iconv >/dev/null 2>&1 || (echo No iconv in System; exit )
+which lame >/dev/null 2>&1 || (echo No lame in System; exit )
+
+# DOS -> Unix
+dos2unix $CUE_FILE
+
+# GBK -> UTF8
+iconv -f gbk -t utf8 $CUE_FILE > $UTF_CUE_FILE
+
+# Monkey's Audio Codec, ape -> wav
+echo Decoding APE file, it may take a few minutes.
+echo Please wait...
+mac $APE_FILE $WAV_FILE -d
+echo "APE --> WAV Complete! "
+
+# Split wav with cue file
+echo "Start to split wav! "
+bchunk $WAV_FILE $CUE_FILE -w wav_
+echo "Splitting Done"
+
+# Scan Album's Information
+ALBUM=`grep 'TITLE' $CUE_FILE|sed -n '1p'|awk -F \" '{print $2}'|\
+ sed s/\ /_/g`
+UTF_ALBUM=`grep 'TITLE' $UTF_CUE_FILE|sed -n '1p'|awk -F \" '{print $2}'|\
+ sed s/\ /_/g`
+CD_ACTOR=`grep 'PERFORMER' $CUE_FILE|sed -n '1p'|awk -F \" '{print $2}'|\
+ sed s/\ /_/g`
+GENRE=`grep ^REM $CUE_FILE|awk '{print ($2, $3)}'|grep ^GENRE |sed -n '1p'|\
+ awk '{print $2}'|\sed s/\ /_/g`
+DATE=`grep ^REM $CUE_FILE|awk '{print ($2, $3)}'|grep ^DATE |sed -n '1p'|\
+ awk '{print $2}'|\sed s/\ /_/g`
+# Add Album's Information to CMD line
+[ -n $ALBUM ] && CD_INFO="--tl ${ALBUM} "
+[ -n $GENRE ] && CD_INFO="${CD_INFO}""--tg ${GENRE} "
+[ -n $DATE ] && CD_INFO="${CD_INFO}""--ty $i{DATE}"
+
+for i in `ls wav_*`
+do
+ # Scan Songs' Information
+ TRACK=`echo $i|sed s/wav_//g|sed s/.wav//g`
+ TITLE=`sed -n "/TRACK[\ \ ]"$TRACK"/,$"p $CUE_FILE|grep TITLE|\
+ sed -n '1p'|awk -F \" '{print $2}'|sed s/\ /_/g`
+ UTF_TITLE=`sed -n "/TRACK[\ \ ]"$TRACK"/,$"p $UTF_CUE_FILE|grep TITLE|\
+ sed -n '1p'|awk -F \" '{print $2}'|sed s/\ /_/g`
+ ACTOR=`sed -n "/TRACK[\ \ ]"$TRACK"/,$"p $CUE_FILE|grep PER|\
+ sed -n '1p'|awk -F \" '{print $2}'|sed s/\ /_/g`
+
+ # Add Actor to CMDline if possible
+ [ -z $ACTOR ] && ACTOR=$CD_ACTOR
+
+ # Add Songs' Information to CMD line
+ [ -n $TITLE ] && NAME=`echo $TRACK\_$UTF_TITLE.mp3`
+ [ -n $TRACK ] && LAME_INFO=" --tn $TRACK "
+ [ -n $TITLE ] && LAME_INFO="$LAME_INFO --tt $TITLE "
+ [ -n $ACTOR ] && LAME_INFO="$LAME_INFO --ta $ACTOR "
+ LAME_INFO="${LAME_INFO} --tc Made_by_Kevin_Li"
+
+ echo
+ echo "========== Now Laming $UTF_TITLE =========="
+
+ #lame -b 32 -m j -h -V 0 -B 320 -q 0 --noath -k --id3v2-only --tt\
+ # $TITLE --ta $ACTOR --tl $ALBUM --tc Made_by_Kevin_Li --tn\
+ # $TRACK $i $NAME
+
+ # Now Lame the Songs
+ lame -b 32 -m j -h -V 0 -B 320 -q 0 --noath -k --id3v2-only \
+ $CD_INFO $LAME_IMFO $i $NAME
+
+ LAME_INFO=
+
+ echo "========== Lame $UTF_TITLE Done! =========="
+ echo
+done
+
+# File Arrangement
+[ -n `ls *.mp3` ] && rm *.wav
+rm $UTF_CUE_FILE
+mkdir \[$ACTOR_$UTF_ALBUM\_MP3\]
+mv *.mp3 \[$ACTOR_$UTF_ALBUM\_MP3\]
+echo
+echo "===================== All Done! ======================="
+[/code]
diff --git a/cli/cueape2flac.sh b/cli/cueape2flac.sh
new file mode 100755
index 0000000..7022f04
--- /dev/null
+++ b/cli/cueape2flac.sh
@@ -0,0 +1,71 @@
+#!/bin/bash
+# PS4="##### "
+# convert APE with cue file to FLAC tracks
+
+selection=`zenity --title="请选择一个.ape文件和一个.cue文件" --file-selection --multiple`
+if [ -z "$selection" ]; then exit 0; fi
+if [[ "$selection" != *.ape\|*.cue && "$selection" != *.cue\|*.ape ]]; then exit 0; fi
+if [ `echo $selection | gawk -F "|" 'END {print NF}'` -ge 3 ]; then exit 0; fi
+
+arg1=${selection%|*}; arg2=${selection#*|}
+if [[ "$arg1" == *.ape ]];then file_ape=$arg1; file_cue=$arg2
+else file_ape=$arg2; file_cue=$arg1; fi
+
+i=0
+while [ -f "temp$i" ]; do
+i=$(($i+1))
+done
+> temp$i
+iconv -f gb18030 -t utf8 "$file_cue" > "temp$i" && mv "temp$i" "$file_cue"
+rm -f "temp$i"
+
+tracks=`gawk -vRS="TRACK" 'END {print NR-1}' "$file_cue"`
+#echo $tracks
+
+all_titles=`gawk -vRS='TRACK' -vFS='\n' \
+'{j=0;for(i=1;i<=NF;i++){if($i~/TITLE/){print $i;j=1}}};j==0 {print "TITLE \"#####\""}' "$file_cue" | \
+gawk -F "\"" 'NR>=2 {printf("%s|",$2)}'`
+
+j=1; while [ -n "$all_titles" ]; do
+title=${all_titles%%|*}
+artist=${all_artists%%|*}
+num=`printf "%0${#tracks}d" $j`
+rm -f "${num}.$title.flac"
+((j++))
+all_titles=${all_titles#*|}
+all_artists=${all_artists#*|}
+done
+
+shntool split -f "$file_cue" -t '%n.%t' -o flac "$file_ape" 2>&1 | \
+gawk -vvar=$tracks 'NR>=1 {print "#正在转换...";print (NR-1)*100/var};{fflush();}' | \
+zenity --title="进度" --text="正在转换..." --progress --auto-kill --auto-close
+
+all_titles=`gawk -vRS='TRACK' -vFS='\n' \
+'{j=0;for(i=1;i<=NF;i++){if($i~/TITLE/){print $i;j=1}}};j==0 {print "TITLE \"#####\""}' "$file_cue" | \
+gawk -F "\"" 'NR>=2 {printf("%s|",$2)}'`
+
+all_artists=`gawk -vRS='TRACK' -vFS='\n' \
+'{j=0;for(i=1;i<=NF;i++){if($i~/PERFORMER/){print $i;j=1}}};\
+j==0 {print "PERFORMER \"#####\""}' "$file_cue" | gawk -F "\"" 'NR>=2 {printf("%s|",$2)}'`
+
+album=`gawk -vRS='TRACK' -vFS='\n' \
+'{j=0;for(i=1;i<=NF;i++){if($i~/TITLE/){print $i;j=1}}};j==0 {print "TITLE \"#####\""}' "$file_cue" | \
+gawk -F "\"" 'NR==1 {printf("%s",$2)}'`
+
+j=1; while [ -n "$all_titles" ]; do
+title=${all_titles%%|*}
+artist=${all_artists%%|*}
+num=`printf "%0${#tracks}d" $j`
+if [ "$title" != "#####" ]; then metaflac --set-tag=TITLE="$title" "${num}.$title.flac"; fi
+if [ "$artist" != "#####" ]; then metaflac --set-tag=ARTIST="$artist" "${num}.$title.flac"; fi
+if [ "$album" != "#####" ]; then metaflac --set-tag=ALBUM="$album" "${num}.$title.flac"; fi
+metaflac --set-tag=TRACKNUMBER="$j" "${num}.$title.flac"
+#if [ "$title" != "#####" ]; then mv "${num}.$title.flac" "${num:1}.$title.flac"
+#else mv "${num}.$title.flac" "${num:1}.NoTitle.flac"; fi
+((j++))
+all_titles=${all_titles#*|}
+all_artists=${all_artists#*|}
+done
+
+zenity --info --text="结束。"
+exit 0
diff --git a/cli/eps2pdf.sh b/cli/eps2pdf.sh
new file mode 100755
index 0000000..b803732
--- /dev/null
+++ b/cli/eps2pdf.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+# convert from eps to pdf using gs
+
+GS="`which gs`"
+BASENAME="`basename $1 .eps`"
+${GS} -sDEVICE=pdfwrite -dNOPAUSE -dQUIET -sOutputFile=${BASENAME}.pdf - < $1
+
diff --git a/cli/jpg2pdf.sh b/cli/jpg2pdf.sh
new file mode 100755
index 0000000..ac992af
--- /dev/null
+++ b/cli/jpg2pdf.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+#
+#############################################################################
+#
+# Shellscript to convert a set of JPEG files to a multipage PDF.
+#
+# Requirements: (1) Ghostscript needs to be installed on the local system.
+# (2) ImageMagick needs to be installed on the local system.
+#
+# Usage: jpegs2pdf.sh output.pdf file1.jpeg [file2.jpeg [file2.jpeg [...]]]
+#
+# Copyright (c) 2007, <pipitas@gmail.com>
+# Use, distribute and modify without any restrictions.
+#
+# Versions:
+# v1.0.0, Jul 12 2007: initial version
+# v1.0.1, Jan 07 2011: set viewJPEG.ps path (self-compiled GS 9.02)
+#
+#############################################################################
+
+outfile=$1
+shift
+
+param=""
+for i in "$@" ; do
+ dimension=$(identify -format "%[fx:(w)] %[fx:(h)]" "${i}")
+ param="${param} <</PageSize [${dimension}]>> setpagedevice (${i}) viewJPEG showpage"
+done
+
+gs \
+ -sDEVICE=pdfwrite \
+ -dPDFSETTINGS=/prepress \
+ -o "$outfile" \
+ viewjpeg.ps \
+ -c "${param}"
+
diff --git a/cli/m4a2mp3.sh b/cli/m4a2mp3.sh
new file mode 100755
index 0000000..5d06cd9
--- /dev/null
+++ b/cli/m4a2mp3.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+bitrate=192
+
+for i in *.m4a; do
+ faad -o - "$i" | lame -h -b $bitrate - "${i%m4a}mp3"
+done
+
diff --git a/cli/wav2flac.sh b/cli/wav2flac.sh
new file mode 100755
index 0000000..9f86156
--- /dev/null
+++ b/cli/wav2flac.sh
@@ -0,0 +1,97 @@
+#!/bin/sh
+#
+# encode '.wav' to '.flac' with tags
+#
+# INFO_WAV_LIST format:
+# +--------------------------
+# |# ARTIST=artist
+# |# ALBUM=album
+# |# DATE=date (YYYY-MM-DD)
+# |# GENRE=genre
+# |
+# |[TRACKNUMBER] - TITLE.wav
+# |[TRACKNUMBER] - TITLE.wav
+# |...
+# +--------------------------
+#
+# Ref:
+# FLAC: https://xiph.org/flac/
+# VorbisComment: http://wiki.xiph.org/VorbisComment
+# Vorbis Comment Field Recommendations:
+# http://age.hobba.nl/audio/mirroredpages/ogg-tagging.html
+#
+#
+# 2014-01-24
+# LiweitiaNux
+#
+
+if ! which flac > /dev/null 2>&1; then
+ echo "ERROR: 'flac' not found!"
+ exit 1
+fi
+
+if [ $# -ne 1 ]; then
+ echo "Usage:"
+ echo " `basename $0` <info_wav_list>"
+ exit 2
+fi
+
+INFO="$1"
+
+## meta data
+# ARTIST
+if grep -iq '^#.*ARTIST' $INFO; then
+ ARTIST=`grep -i '^#.*ARTIST' $INFO | sed 's/^#.*ARTIST=//'`
+else
+ ARTIST=""
+fi
+# ALBUM
+if grep -iq '^#.*ALBUM' $INFO; then
+ ALBUM=`grep -i '^#.*ALBUM' $INFO | sed 's/^#.*ALBUM=//'`
+else
+ ALBUM=""
+fi
+# DATE
+if grep -iq '^#.*DATE' $INFO; then
+ DATE=`grep -i '^#.*DATE' $INFO | sed 's/^#.*DATE=//'`
+else
+ DATE=""
+fi
+# GENRE
+if grep -iq '^#.*GENRE' $INFO; then
+ GENRE=`grep -i '^#.*GENRE' $INFO | sed 's/^#.*GENRE=//'`
+else
+ GENRE=""
+fi
+# PUBLISHER
+if grep -iq '^#.*PUBLISHER' $INFO; then
+ PUBLISHER=`grep -i '^#.*PUBLISHER' $INFO | sed 's/^#.*PUBLISHER=//'`
+else
+ PUBLISHER=""
+fi
+
+echo "ARTIST: $ARTIST"
+echo "ALBUM: $ALBUM"
+echo "DATE: $DATE"
+echo "GENRE: $GENRE"
+echo "PUBLISHER: $PUBLISHER"
+
+## process wav file list
+grep '^[/a-zA-Z0-9].*' $INFO | while read f; do
+ file=`basename "$f"`
+ TRACKNUMBER=`echo "$file" | sed 's/\ -\ .*\.wav$//'`
+ TITLE=`echo "$file" | sed -e 's/^[0-9]*\ -\ //' -e 's/\.wav$//'`
+ echo "TRACKNUMBER: $TRACKNUMBER; TITLE: $TITLE ..."
+ # encode
+ flac -T "ARTIST=${ARTIST}" -T "TITLE=${TITLE}" \
+ -T "ALBUM=${ALBUM}" -T "DATE=${DATE}" \
+ -T "TRACKNUMBER=${TRACKNUMBER}" \
+ -T "GENRE=${GENRE}" -T "PUBLISHER=${PUBLISHER}" \
+ -s "${f}"
+ if [ $? -eq 0 ]; then
+ echo " OK"
+ else
+ echo " *** ERROR ***"
+ fi
+done
+