forked from dannyti/seedbox-from-scratch
-
Notifications
You must be signed in to change notification settings - Fork 4
/
iso2mkv.sh
executable file
·159 lines (135 loc) · 4.07 KB
/
iso2mkv.sh
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/sh
# Hellish Tech
# No commercial usage without authorization
# License: Beerware 2017
# Author: Xyberviri
# Purpose: to make it easier to rip .iso files into .mkv files.
# If you find this script useful you can buy me a beer here: https://www.paypal.me/xyberviri
# wget https://pastebin.com/raw/SRHihAED -O- | tr -d '\r' >iso2mkv.sh;chmod +x iso2mkv.sh
# Usage info
show_help() {
cat << EOF
Usage: ${0##*/} [-hv] [-s STARTING TITLE] [-e ENDING TITLE] [-o OUTFILE OFFSET] [-f OUTFILE] [FILE]...
Export titles from FILE to OUTFILE, FILE should be a .iso format.
-h display this help and exit
-f OUTFILE name out output file, DEFAULTS to the input FILE.mkv
-s # starting title, DEFAULT 1
-e # ending title, DEFAULTs to last title
-o # offset the exported title to this, useful when dealing
with multi dvd seasons. This option also forces OUTFILE##.mkv behaviour.
-i inspect the .iso and lists title index, lengths and total title counts.
./iso2mkv.sh -e 4 -f SomeShowSeason1E dvd.iso
..exports titles 1 - 4 to files SomeShowSeason1E{01-04}.mkv
./iso2mkv.sh -s 5 -e 10 dvd.iso
..exports titles 5 - 10 to files dvd{05-10}.mkv
./iso2mkv.sh -e 10 -o 11 dvd2.iso
..exports titles 1 - 10 to files dvd2{11-20}.mkv
./iso2mkv.sh -e 1 dvd.iso
..exports titles 1 as dvd.mkv
This script requires handbrake, install with the following:
add-apt-repository ppa:stebbins/handbrake-releases
apt-get update
apt-get install handbrake-cli
Customize the export on the very last line of the script
Handbrake CLI here:
https://handbrake.fr/docs/en/1.0.0/cli/cli-guide.html
EOF
}
# Initialize our own variables:
output_file=""
verbose=0
offset=0
title_start=1
title_end=0
inspect=0
autonumber=0
OPTIND=1
# Resetting OPTIND is necessary if getopts was used previously in the script.
# It is a good idea to make OPTIND local if you process options in a function.
while getopts hvif:o:s:e: opt; do
case $opt in
h)
show_help
exit 0
;;
v) verbose=$((verbose+1))
;;
i) inspect=$((inspect+1))
;;
f) output_file=$OPTARG
;;
o) offset=$OPTARG
((autonumber++))
;;
s) title_start=$OPTARG
;;
e) title_end=$OPTARG
;;
*)
show_help >&2
exit 1
;;
esac
done
shift "$((OPTIND-1))" # Discard the options and sentinel --
#input file
FILE="$@"
if [ -f "$FILE" ]
then
printf 'iso2mkv: <%s>\n' "$FILE"
else
echo "File $FILE does not exist" >&2
exit 0
fi
#output filename
if [ -z $output_file ]; then
output_file="$(echo $FILE | sed 's=.*/==;s/.iso//I')"
fi
#count number of titles in iso
rawout=$(HandBrakeCLI --min-duration 0 -i $FILE -t 0 2>&1 >/dev/null)
count=$(echo $rawout | grep -Eao "\\+ title [0-9]+:" | wc -l)
title_list=$(echo $rawout | grep -Eao "\\+ duration: [0-9]+:[0-9]+:[0-9]+"| sed 's/+\sduration://g')
#inspect to spit out the title lengths so we know what titles we want to export.
if [ $inspect -gt 0 ]
then
tIndex=1
for title in $title_list; do
printf 'Title: %2s %s\n' "$tIndex" "$title"
((tIndex++))
done
exit 0
fi
#bound title end to max count
if [ $title_end -lt 1 ] || [ $title_end -gt $count ]
then
title_end=$count
fi
#bound title_start to title_end
if [ $title_start -gt $title_end ]
then
title_start=$title_end
fi
#set offset to 1 if we haven't overridden it.
if [ $offset -lt 1 ]
then
offset=$title_start
fi
#enable auto numbering if exporting more then 1 title
if [ $title_end -ne $title_start ]
then
((autonumber++))
fi
#set the file name
filename="${output_file}.mkv"
#loop from $title_start to $title_end
for i in $(seq $title_start $title_end)
do
#override filename because we have more then one title, or -o was used.
if [ $autonumber -gt 0 ]
then
filename="${output_file}$(printf "%02d" $offset).mkv"
((offset++))
fi
echo -e "\tExtracting title $i as '${filename}'\n"
HandBrakeCLI -i "$FILE" -t $i --preset Normal --output "${filename}"
done