1
+ #! /bin/bash
2
+ HEADER_TEXT=" \\ e[93m=== Plexus v0.5 - Developed by Robert Thomas ===\\ n"
3
+ HEADER_SUBTEXT=" \\ e[93m=== https://github.com/Wolveix/plexus ===\\ n"
4
+
5
+ VERBOSE=6
6
+ declare -A LOG_LEVELS
7
+ LOG_LEVELS=([0]=" emerg" [1]=" alert" [2]=" crit" [3]=" err" [4]=" warning" [5]=" notice" [6]=" info" [7]=" debug" )
8
+ function .log () {
9
+ local LEVEL=${1}
10
+ shift
11
+ if [ ${VERBOSE} -ge ${LEVEL} ]; then
12
+ echo " [${LOG_LEVELS[$LEVEL]} ]" " $@ "
13
+ fi
14
+ }
15
+
16
+ function about {
17
+ printf " $HEADER_TEXT$HEADER_SUBTEXT "
18
+ printf " \\ nI started working on this script when I realised that while"
19
+ printf " \\ nit may be a big job, I'm going to need to re-encode my media"
20
+ printf " \\ nat some point. So, not being too familiar with Bash/Shell,"
21
+ printf " \\ nI reached out to a good friend on https://hostballs.com (Mason)"
22
+ printf " \\ nand asked him what he thought would be the best way to tackle"
23
+ printf " \\ nthis problem."
24
+ printf " \\ n\\ nMason came back to me with a few untested scripts and so I got"
25
+ printf " \\ nto work! After a night of testing, I created a fairly optimized"
26
+ printf " \\ nscript which could create a list of media which didn't meet my"
27
+ printf " \\ nstandards, and then use a secondary script to process this list."
28
+ printf " \\ n\\ nI know for a fact that a lot of people have sought ways to achieve"
29
+ printf " \\ nthis over the last few years, so I'm hoping that this software will"
30
+ printf " \\ nhelp someone :)"
31
+ printf " \\ n\\ n- Robert Thomas (Wolveix)\\ n"
32
+ }
33
+
34
+ function list {
35
+ while getopts " :a:d:l:v:" opt; do
36
+ case $opt in
37
+ a)
38
+ case $OPTARG in
39
+ " " | " default" | " aac" | " AAC" )
40
+ audio_codec=" aac"
41
+ ;;
42
+ " ac3" | " AC3" )
43
+ audio_codec=" ac3"
44
+ ;;
45
+ * )
46
+ printf " You have not entered a valid audio codec.\\ n"
47
+ exit 3
48
+ ;;
49
+ esac
50
+ ;;
51
+ d)
52
+ if [ -d " $OPTARG " ]
53
+ then
54
+ if [ " ${OPTARG: -1} " == " /" ]
55
+ then
56
+ media_dir=" ${OPTARG::- 1} "
57
+ else
58
+ media_dir=" $OPTARG "
59
+ fi
60
+ else
61
+ printf " You have not entered a valid directory.\\ n"
62
+ exit 1
63
+ fi
64
+ ;;
65
+ l)
66
+ list_file=" $OPTARG "
67
+ list_dir=$( dirname " ${list_file} " )
68
+
69
+ if [ ! -d " $list_dir " ]
70
+ then
71
+ printf " You have not entered a valid list directory.\\ n"
72
+ exit 1
73
+ fi
74
+ ;;
75
+ v)
76
+ case $OPTARG in
77
+ " " | " default" | " x264" | " X264" | " h.264" | " H.264" | " h264" | " H264" | " AVC" )
78
+ video_codec=" h264"
79
+ ;;
80
+ " x265" | " X265" | " hevc" | " HEVC" )
81
+ video_codec=" h265"
82
+ ;;
83
+ * )
84
+ printf " You have not entered a valid video codec.\\ n"
85
+ exit 2
86
+ ;;
87
+ esac
88
+ ;;
89
+ \? )
90
+ echo " Invalid option: -$OPTARG ." >&2
91
+ exit 1
92
+ ;;
93
+ :)
94
+ echo " Option -$OPTARG requires an argument." >&2
95
+ exit 1
96
+ ;;
97
+ esac
98
+ done
99
+
100
+ if [ $OPTIND -eq 1 ]
101
+ then
102
+ printf " \\ e[39mUsage:\\ n plexus list -d /path/to/media [flags]\\ n\\ nFlags:\\ n"
103
+ printf " -a Audio codec. Default = aac\\ n"
104
+ printf " -d Media directory. Default = /mnt/plexdrive\\ n"
105
+ printf " -l List location. Default = /tmp/plexus/list.txt\\ n"
106
+ printf " -v Video codec. Default = h264\\ n"
107
+ exit 0
108
+ fi
109
+
110
+ if [ -z " $audio_codec " ]; then audio_codec=" aac" ; fi
111
+ if [ -z " $list_file " ]; then list_file=" /tmp/plexus/list.txt" ; fi
112
+ if [ -z " $media_dir " ]; then media_dir=" /mnt/plexdrive" ; fi
113
+ if [ -z " $video_codec " ]; then video_codec=" h264" ; fi
114
+
115
+ printf " \\ e[32mAudio codec: $audio_codec \\ nList file: $list_file \\ nMedia directory: $media_dir \\ nVideo codec: $video_codec \\ n\\ n"
116
+
117
+ if [ -f $list_file ]
118
+ then
119
+ answer=" waiting"
120
+ while [ ! -z $answer ]
121
+ do
122
+ read -r -n 1 -p ' This will delete the current list file. Do you want to continue? ' answer
123
+
124
+ case $answer in
125
+ " Y" | " y" )
126
+ rm " $list_file "
127
+ answer=" "
128
+ printf " \\ n\\ n"
129
+ ;;
130
+ " N" | " n" )
131
+ printf " \\ nYou can find the current list file here: $list_file \\ n"
132
+ exit 4
133
+ ;;
134
+ * )
135
+ printf " \\ nPlease enter yes or no.\\ n"
136
+ ;;
137
+ esac
138
+ done
139
+ fi
140
+
141
+ printf " \\ e[32mScanning directory...\\ n"
142
+ while IFS= read -r f
143
+ do
144
+ printf " \\ e[94mLooking at: $f \\ n"
145
+ file_audio_codec=$( /usr/bin/ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 " $f " )
146
+ file_video_codec=$( /usr/bin/ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 " $f " )
147
+
148
+ if [[ " $file_audio_codec " != " $audio_codec " || " $file_video_codec " != " $video_codec " ]]
149
+ then
150
+ echo " $f " >> $list_file
151
+ fi
152
+ done < <( find " $media_dir " -name ' *.avi' -or -name ' *.flv' -or -name ' *.mkv' -or -name ' *.mov' -or -name ' *.mp4' -or -name ' *.mpg' -or -name ' *.wmv' )
153
+ printf " \\ e[32mScan complete! Run plexus encode to process the list.\\ n"
154
+ }
155
+
156
+ function encode {
157
+ printf " $HEADER_TEXT "
158
+ }
159
+
160
+ function help {
161
+ printf " $HEADER_TEXT "
162
+ printf " \\ n\\ e[37mUsage:\\ n plexus [flags]\\ n plexus [command]\\ n"
163
+ printf " \\ nAvailable Commands:\\ n"
164
+ printf " about Learn more about the program\\ n"
165
+ printf " build Build a .txt file containing media with incorrect codecs\\ n"
166
+ printf " encode Begin processing the encode queue\\ n"
167
+ printf " help Displays a list of available commands\\ n"
168
+ printf " install Install plex-encode\\ n"
169
+ }
170
+
171
+ function install {
172
+ printf " $HEADER_TEXT "
173
+ printf " \\ n\\ e[32mInstalling missing dependencies.\\ n\\ n\\ e[94m"
174
+ apt-get install curl ffmpeg unzip -y
175
+ printf " \\ n\\ e[32mCreating directories if they don't already exist.\\ n\\ n\\ e[94m"
176
+ mkdir -p /mnt/plex-encode /tmp/plex-encode /tmp/plex-encode/convert /tmp/plex-encode/converted
177
+ printf " \\ e[32mInstalling RClone.\\ n\\ n\\ e[94m"
178
+ curl https://rclone.org/install.sh | sudo bash
179
+ printf " \\ e[32mRClone installed.\\ n"
180
+ printf " \\ n\\ e[32mBegin RClone configuration (skip this if you already have a remote setup).\\ n\\ n\\ e[94m"
181
+ rclone config
182
+ printf " \\ n\\ n\\ e[32mInstall completed!\\ n"
183
+ printf " \\ nPlease run 'plex-encode build' next.\\ n"
184
+ }
185
+
186
+ " $@ "
0 commit comments