-
Notifications
You must be signed in to change notification settings - Fork 1
/
amv
executable file
·60 lines (49 loc) · 1.22 KB
/
amv
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
#! /bin/sh
# Todo: handle artist dir as $1
MUSIC_DIR=$ORG_MEDIA/music
OUT="$MUSIC_DIR/_tomove-data"
U_OUT="$MUSIC_DIR"
if [ "$1" = "--help" ] || [ "$1" = "-h" ] || [ "$1" = "help" ] || [ -z "$1" ]; then cat << EOF
$ amv ALBUM
a[lbum]m[o]v[e]
Move an album to another dir, while creating the enclosing artist directory.
Parameters:
\$1: album dir
Flags:
-u: move out of unheard
Example:
$ amv "Clispe/Lord Willin'"
#=> moved to: $OUT/Clispe/Lord Willin'
$ amv -u .
#=> moved to: unheard
EOF
exit
fi
if pwd | grep -v music >/dev/null; then
printf "music isn't in your pwd, did you really want to run this? y/N: "
read ans
[ "$ans" != "y" ] && exit 1
fi
ALBUM=`realpath "$1" 2>/dev/null`
U=0
if [ "$1" = "-u" ]; then
ALBUM=`realpath "$2"`
U=1
elif [ "$2" = "-u" ]; then
ALBUM=`realpath "$1"`
U=1
fi
[ "$U" -eq 1 ] && OUT=$U_OUT
ARTIST=`basename "$(dirname "$ALBUM")"`
if [ "$ARTIST" = "music" ] || [ "$ARTIST" = "unheard" ]; then
OUT_DIR="$OUT"
else
OUT_DIR="$OUT/$ARTIST"
fi
mkdir -p "$OUT_DIR"
mv "$ALBUM" "$OUT_DIR"
echo "moved to $OUT_DIR"
{
rmdir "$ARTIST" 2>/dev/null || cd ..; rmdir "$ARTIST" 2>/dev/null || cd ..; rmdir "$ARTIST" 2>/dev/null
} && echo "Removed enclosing directory: $ARTIST"
true