-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtitles.sh
140 lines (102 loc) · 3.66 KB
/
titles.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
#!/bin/bash
#
# Copyright (c) 2017 Marc Young
#
# encode for playback on Roku or Chromcast
IAM=$(whoami)
INFO_SRC="/media/$IAM"
DVD_NAME=$(ls $INFO_SRC)
VOB=$INFO_SRC/$DVD_NAME/VIDEO_TS/VIDEO_TS.VOB
INPUT=/dev/sr0
mediainfo="mediainfo"
handbrake_options="--markers --large-file --encoder x264 --encopts vbv-maxrate=25000:vbv-bufsize=31250:ratetol=inf --crop 0:0:0:0 --strict-anamorphic"
width="$(mediainfo --Inform='Video;%Width%' "$VOB")"
height="$(mediainfo --Inform='Video;%Height%' "$VOB")"
if (($width > 1280)) || (($height > 720)); then
max_bitrate="5000"
elif (($width > 720)) || (($height > 576)); then
max_bitrate="4000"
else
max_bitrate="1800"
fi
min_bitrate="$((max_bitrate / 2))"
bitrate="$(mediainfo --Inform='Video;%BitRate%' "$input")"
if [ ! "$bitrate" ]; then
bitrate="$(mediainfo --Inform='General;%OverallBitRate%' "$input")"
bitrate="$(((bitrate / 10) * 9))"
fi
if [ "$bitrate" ]; then
bitrate="$(((bitrate / 5) * 4))"
bitrate="$((bitrate / 1000))"
bitrate="$(((bitrate / 100) * 100))"
if (($bitrate > $max_bitrate)); then
bitrate="$max_bitrate"
elif (($bitrate < $min_bitrate)); then
bitrate="$min_bitrate"
fi
else
bitrate="$min_bitrate"
fi
echo $bitrate
handbrake_options="$handbrake_options --vb $bitrate"
frame_rate="$(mediainfo --Inform='Video;%FrameRate_Original%' "$VOB")"
if [ ! "$frame_rate" ]; then
frame_rate="$(mediainfo --Inform='Video;%FrameRate%' "$VOB")"
fi
frame_rate_file="$(basename "$VOB")"
frame_rate_file="${frame_rate_file%\.[^.]*}.txt"
if [ -f "$frame_rate_file" ]; then
handbrake_options="$handbrake_options --rate $(cat "$frame_rate_file")"
elif [ "$frame_rate" == '29.970' ]; then
handbrake_options="$handbrake_options --rate 23.976"
else
handbrake_options="$handbrake_options --rate 30 --pfr"
fi
channels="$(mediainfo --Inform='Audio;%Channels%' "$VOB" | sed 's/[^0-9].*$//')"
if (($channels > 2)); then
handbrake_options="$handbrake_options --aencoder ca_aac,copy:ac3"
elif [ "$(mediainfo --Inform='General;%Audio_Format_List%' "$VOB" | sed 's| /.*||')" == 'AAC' ]; then
handbrake_options="$handbrake_options --aencoder copy:aac"
fi
if [ "$frame_rate" == '29.970' ]; then
handbrake_options="$handbrake_options --detelecine"
fi
echo $handbrake_options
echo "What is the name of the show?"
read show_name
if [ ! -d "$show_name" ]; then
mkdir $show_name
fi
echo "What season is it?"
read season
echo "What episode is it?"
read episode
lsdvd > dvdinfo
sed -i '/Disc Title:/d' dvdinfo
sed -i '/Longest track:/d' dvdinfo
sequence=$(wc -l < dvdinfo)
for i in `seq $sequence`; do
line=$(awk 'NR=='$i dvdinfo)
if echo $line | grep -Eq 'Length: 00:0'
then
echo 'Crap'
else
echo "great"
title=$(echo $line | awk '{print $2}' | sed 's/^0*//' | tr -dc '[:alnum:]\n\r')
HandBrakeCLI --input /dev/dvd --title $title $handbrake_options --output $show_name/$show_name"_s"$season"_e"$episode.mp4 -s 1;
episode=$((episode+1))
fi
done
eject
#while read line; do
#HandBrakeCLI --input /dev/dvd --title $title --preset Normal --output $show_name/$show_name"_s"$season"_e"$episode.mp4
#episode=$((episode+1))
#echo $title
# HandBrakeCLI --input /dev/dvd --title $i --preset Normal --output $show_name/$show_name"_s"$season"_e"$i.mp4 -s 1
#done < dvdinfo.txt
#cat dvdinfo.txt | while read line
#do
# title=$(echo $line | awk '{print $2}' | sed 's/^0*//' | tr -dc '[:alnum:]\n\r')
# HandBrakeCLI --input /dev/dvd --title $title --preset Normal --output $show_name/$show_name"_s"$season"_e"$title.mp4 -s 1
#done
#for i in `seq `$sequence; do HandBrakeCLI --input /dev/dvd --title $i --preset Normal --output $show_name/$show_name"_s"$season"_e"$i.mp4 -s 1; done