-
Notifications
You must be signed in to change notification settings - Fork 0
/
wapaname
executable file
·115 lines (90 loc) · 2.28 KB
/
wapaname
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
112
113
114
115
#!/bin/sh
# wapaname
#
# Auto-rename TV episodes in current directory using tvnamer.
#
# Requires: tvnamer.
#
# This script is in the public domain and was originally written by
# Dennis Murczak <https://github.com/lortordermur/>
#### GLOBALS ####
configfile="$(echo ~)/.config/tvnamer/tvnamerrc"
confparm=
nameparm=
idparm=
#### FUNCTIONS ####
usage () {
echo "Usage: $(basename $0) [series_name] [tvdb_series_id]"
echo "
Auto-renames all TV episodes in the current directory using tvnamer. File
names have to already be in a Kodi-compatible sNNeNN, NNxNN or equivalent
format.
Tvnamer will ask a few interactive questions on launch in order to keep the
mess-up potential minimal.
If no parameters are given, the series name is derived from the directory
name. A single parameter is interpreted as a series name. If tvnamer is unable
to find a series or a specific dub but you know it has an entry in
thetvdb.com, you can provide the numeric series ID as a second parameter.
To see non-English dubs in the first place, you may in some cases have to
create a configuration file using 'tvnamer -s' and set the language code. This
file, provided it exists, is expected in the following location:
$configfile
"
exit 0
}
commandexists () {
command -v "$1" > /dev/null || { echo "Required command '$1' not found! $2" && exit 1; }
}
#### MAIN ####
commandexists "tvnamer" "Please install tvnamer."
case $1 in
"--help" | "-h" )
usage
;;
esac
# Parameter checkup
if [ -f $configfile ]; then
confparm="--config=$configfile"
fi
if [ $# -eq 0 ]; then
nameparm="--name="$(basename "$(pwd)")""
elif [ $# -eq 1 ]; then
nameparm="--name=\"$1\""
elif [ $# -eq 2 ]; then
nameparm="--name=\"$1\""
idparm="--series-id=$2"
else
echo "Invalid number of parameters! Try -h or --help."
echo
exit 1
fi
echo "Preparing to launch tvnamer for current dir. Continue [Y/n/?]?"
read -r ans
case $ans in
"y" | "Y" | "")
break
;;
"?")
usage
;;
*)
echo "Aborting."
echo
exit 0
;;
esac
tvnamer "$confparm" "$nameparm" "$idparm" .
# TODO: Look into tvnamer's exit status, or at least catch its exit messages.
case $? in
"0")
break;
;;
*)
echo "There was a problem with tvnamer. Aborting."
echo
exit 1
;;
esac
echo
echo "All done!"
echo