File: gtkpod-convert-common.sh

package info (click to toggle)
gtkpod 2.1.5-10
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 19,424 kB
  • sloc: ansic: 51,604; xml: 16,135; sh: 11,916; cpp: 7,545; perl: 1,449; makefile: 1,380; lex: 638; awk: 73; python: 35
file content (111 lines) | stat: -rwxr-xr-x 2,610 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/sh
# Script that converts a file into an mp3 or an m4a file
#
# USAGE:
#
# Called by convert-2mp3.sh, convert-2m4a.sh, convert-2mp4.sh.
#
# The following command line arguments are being used
#
#       -x      Print converted filename extension and exit
#       -f      Set converted filename
# 	-a	Artist tag
#	-A 	Album tag
#	-T	Track tag
#	-t	Title tag
#	-g	Genre tag
#	-y	Year tag
#	-c	Comment tag
#	-q	Quality (overwrites standard encoder options)
#               For mp3 files this could be "--vbr-new -V<number>".
#
# Return Codes:
#   0 ok
#   1 input file not found
#   2 output file cannot be created
#   3 cannot get info
#   4 cannot exec decoding
#   5 cannot exec encoding
#   6 conversion failed
#   7 unknown option

# Get parameters
while getopts q:a:A:T:t:g:c:y:f:x opt ; do
	case "$opt" in
	        x)      echo "$extension"; exit 0 ;;
	        f)      outfile="$OPTARG" ;;
		a)	artist="$OPTARG" ;;
		A)	album="$OPTARG" ;;
		T)	track="$OPTARG" ;;
		t)	title="$OPTARG" ;;
		g)	genre="$OPTARG" ;;
		y)	year="$OPTARG" ;;
		c)	comment="$OPTARG" ;;
		q)	ENCODER_OPTS="$OPTARG" ;;
	        ?)      exit 7 ;;
	esac
done
shift $(($OPTIND - 1))

infile="$1"
infile_extension=${infile##*.}

if [ "$outfile" = "" ]; then
    # Build output file
    outfile=`basename "$infile"`
    outfile=${outfile%.$infile_extension}
    tmp=${TMPDIR-/tmp}
    outfile="$tmp/$outfile.$extension"
fi

# Default values
[ -z "$comment" ] && comment="Encoded for gtkpod with $ENCODER"

LOG=`dirname "$outfile"`
LOG="$LOG/conversion.log"

echo "Converting \"$infile\" into \"$outfile\"" >> "$LOG"

# Checking input file
if [ "$infile" = "" ]; then
    exit 1
fi
if [ ! -f "$infile" ]; then
    exit 1
fi

# Checking output file
touch "$outfile" >> "$LOG" 2>&1
if [ "x$?" != "x0" ]; then
    exit 2
fi

# Check for the existence of encoder
encoder=`which $ENCODER` >> "$LOG" 2>&1
if [ -z "$encoder" ]; then
    exit 5
fi

# Determine decoder

# Convert the source extension to lowercase.
filetype=`echo ${infile_extension}| tr '[:upper:]' '[:lower:]'`
case "$filetype" in
	flac)	decoder="flac" ; options="-d -c --"  ;;
	oga|ogg|ogv|ogx)
	        # Quiet mode is needed to workaround a bug in oggdec
	        # 1.4 which prints the version banner to stdout, which
	        # then corrupts the decoded track.
		decoder="oggdec" ; options="--quiet --output - --" ;;
	m4a)	decoder="faad" ; options="-o -" ;;
	wav)	decoder="" ;;
	*)	decoder="ffmpeg" ;;
esac

# Check for the existence of decoder
if [ $decoder ]; then
    decoder=`which "$decoder"` >> "$LOG" 2>&1
    if [ -z "$decoder" ]; then
        exit 4
    fi
fi