-
Notifications
You must be signed in to change notification settings - Fork 0
/
dir2stick
85 lines (72 loc) · 2.41 KB
/
dir2stick
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
#!/usr/bin/env zsh
# Copyright 2015 Han Boetes <[email protected]>
# For license info see http://unlicense.org/
# I use this script to convert all types of music files to .mp3
# and upload them to my stick so I can listen music in my car.
# I just hacked it up in an hour or so so don't expect it
# to actually work.
setopt shwordsplit braceexpand
emulate sh
NULLCMD=:
wd=$PWD
# alias normalize=normalize-audio
for i in mpv mid3v2 normalize-audio lame; do
if ! which $i >& /dev/null; then
echo "$i is not installed. I need it. Go get it!"
end=true
fi
done
[ "$end" = true ] && exit 1
PLAYERMNT=/ssd/skytraxx/mp3
# PLAYERMNT=/mega/home/han/Desktop/stick
dotdot=${PWD%/*}
dotdot=${dotdot##*/}
TEMPDIR="$TMPDIR/${dotdot}_${PWD##*/}"
TARGET="$PLAYERMNT/${dotdot}_${PWD##*/}"
export LC_ALL=utf8
mkdir -p $TEMPDIR
until df $PLAYERMNT >& /dev/null; do
echo -n "$PLAYERMNT not yet mounted. Press any key to try again."
read -sk1 nop
done
i=0
convert=false
for file in *.flac *.ogg *.mpc; do
[[ $file == '*.'* ]] && continue
i=$(($i + 1))
echo "Converting $file to wav format"
# using `outfile' prevents quoting problems.
mpv -vo null -ao=pcm --ao-pcm-file="$TMPDIR/outfile$i" "$file" >& /dev/null
normalize-audio $TMPDIR/outfile$i
mv $TMPDIR/outfile$i "$TEMPDIR/${file%.*}.wav"
convert=true
done
cp *.mp3 $TEMPDIR > /dev/null 2>&1 || nothing=true
if [[ $convert = false ]] && [[ $nothing == true ]]; then
rmdir $TEMPDIR
echo "Nothing to do here!" >&2
exit 1
fi
cd $TEMPDIR
if [[ $convert == true ]]; then
# j=0
for file in *.wav; do
# ((j++))
(
artistname=$(echo $file|sed -e 's|\(.*\) - .* - .* - .*|\1|')
albumname=$(echo $file|sed -e 's|.* - \(.*\) - .* - .*|\1|')
tracknumber=$(echo $file|sed -e 's|.* - .* - \(.*\) - .*|\1|')
trackname=$(echo $file|sed -e 's|.* - .* - .* - \(.*\)\.wav|\1|')
lame -V3 -b 192 "$file" "${file%.wav}.mp3"
rm "$file"
# Set decent tags for the display.
mid3v2 -a "$artistname" -A "$albumname" -T "$tracknumber" -t "$trackname" "$_"
# Since pioneer sorts files on timestamp -- yes really -- set a
# timestamp which doesn't confuse the order.
# touch -t $(printf "010101%02i\n" $j) "${file%.wav}.mp3"
)&
done
fi
wait # for all conversion processes to finish.
cd $PLAYERMNT
mv $TEMPDIR $TARGET