-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrip-all-episodes
executable file
·62 lines (54 loc) · 1.57 KB
/
rip-all-episodes
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
#!/bin/bash -
# Rip All Episodes
# ================
#
# Run rip-episodes over several directories. Arguments will be passed to
# rip-episodes. The episode number and season will be determined by the directory name.
# E.g.,
#
# ├── XFILES_S02E01-4
# ├── XFILES_S02E05-8
# ├── XFILES_S02E13-16
# ├── XFILES_S02E17-20
# ├── XFILES_S02E21-24
# └── XFILES_S02E9-12
#
# rip-all-episodes -e XFILES -p 'The X-Files'
# will rip files to ./The X-Files/The X-Files-S02E01.mkv etc.
output="$HOME/Movies"
while getopts :e:o:p:yh opt; do
case "$opt" in
e) source="$OPTARG"
;;
o) output="${OPTARG%/}"
;;
p) prefix="$OPTARG"
;;
y) dry_run=true
;;
h) printf "Define a source directory prefix with -e and a file prefix with -p.\n"
printf "Dry-run the command with -y (or pass along to rip-episodes with -n).\n"
exit 2
;;
?) rest="${rest} -$OPTARG"
;;
esac
done
shift $((OPTIND-1))
_run() {
if [[ -n "$dry_run" ]]; then
echo "$@"
else
"$@"
fi
}
if [[ -z "$source" ]] || [[ -z "$prefix" ]]; then
printf "Must include a source directory prefix with -e and a file prefix with -p.\n"
exit 1
fi
shopt -s nocaseglob
for i in "${source%/}"*/; do
season=$(sed -E 's_.+[Ss]([0-9]+)[Ee].+/_\1_g' <<< "$i")
episode_list=$(sed -E 's_.+[Ee]([- 0-9]+)/_\1_g' <<< "$i")
_run rip-episodes -p "$prefix" -e "$i" -s "$season" -o "$output" $rest "$episode_list"
done