This repository has been archived by the owner on Jun 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Movement to a full suite of tools. Mediainfo dependency removed.
- Loading branch information
Robert Thomas
committed
Jun 25, 2018
1 parent
651bcf7
commit 44ad193
Showing
4 changed files
with
195 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
#!/bin/bash | ||
HEADER_TEXT="\\e[93m=== Plexus v0.5 - Developed by Robert Thomas ===\\n" | ||
HEADER_SUBTEXT="\\e[93m=== https://github.com/Wolveix/plexus ===\\n" | ||
|
||
VERBOSE=6 | ||
declare -A LOG_LEVELS | ||
LOG_LEVELS=([0]="emerg" [1]="alert" [2]="crit" [3]="err" [4]="warning" [5]="notice" [6]="info" [7]="debug") | ||
function .log () { | ||
local LEVEL=${1} | ||
shift | ||
if [ ${VERBOSE} -ge ${LEVEL} ]; then | ||
echo "[${LOG_LEVELS[$LEVEL]}]" "$@" | ||
fi | ||
} | ||
|
||
function about { | ||
printf "$HEADER_TEXT$HEADER_SUBTEXT" | ||
printf "\\nI started working on this script when I realised that while" | ||
printf "\\nit may be a big job, I'm going to need to re-encode my media" | ||
printf "\\nat some point. So, not being too familiar with Bash/Shell," | ||
printf "\\nI reached out to a good friend on https://hostballs.com (Mason)" | ||
printf "\\nand asked him what he thought would be the best way to tackle" | ||
printf "\\nthis problem." | ||
printf "\\n\\nMason came back to me with a few untested scripts and so I got" | ||
printf "\\nto work! After a night of testing, I created a fairly optimized" | ||
printf "\\nscript which could create a list of media which didn't meet my" | ||
printf "\\nstandards, and then use a secondary script to process this list." | ||
printf "\\n\\nI know for a fact that a lot of people have sought ways to achieve" | ||
printf "\\nthis over the last few years, so I'm hoping that this software will" | ||
printf "\\nhelp someone :)" | ||
printf "\\n\\n- Robert Thomas (Wolveix)\\n" | ||
} | ||
|
||
function list { | ||
while getopts ":a:d:l:v:" opt; do | ||
case $opt in | ||
a) | ||
case $OPTARG in | ||
"" | "default" | "aac" | "AAC") | ||
audio_codec="aac" | ||
;; | ||
"ac3" | "AC3") | ||
audio_codec="ac3" | ||
;; | ||
*) | ||
printf "You have not entered a valid audio codec.\\n" | ||
exit 3 | ||
;; | ||
esac | ||
;; | ||
d) | ||
if [ -d "$OPTARG" ] | ||
then | ||
if [ "${OPTARG: -1}" == "/" ] | ||
then | ||
media_dir="${OPTARG::-1}" | ||
else | ||
media_dir="$OPTARG" | ||
fi | ||
else | ||
printf "You have not entered a valid directory.\\n" | ||
exit 1 | ||
fi | ||
;; | ||
l) | ||
list_file="$OPTARG" | ||
list_dir=$(dirname "${list_file}") | ||
|
||
if [ ! -d "$list_dir" ] | ||
then | ||
printf "You have not entered a valid list directory.\\n" | ||
exit 1 | ||
fi | ||
;; | ||
v) | ||
case $OPTARG in | ||
"" | "default" | "x264" | "X264" | "h.264" | "H.264" | "h264" | "H264" | "AVC") | ||
video_codec="h264" | ||
;; | ||
"x265" | "X265" | "hevc" | "HEVC") | ||
video_codec="h265" | ||
;; | ||
*) | ||
printf "You have not entered a valid video codec.\\n" | ||
exit 2 | ||
;; | ||
esac | ||
;; | ||
\?) | ||
echo "Invalid option: -$OPTARG." >&2 | ||
exit 1 | ||
;; | ||
:) | ||
echo "Option -$OPTARG requires an argument." >&2 | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
if [ $OPTIND -eq 1 ] | ||
then | ||
printf "\\e[39mUsage:\\n plexus list -d /path/to/media [flags]\\n\\nFlags:\\n" | ||
printf " -a Audio codec. Default = aac\\n" | ||
printf " -d Media directory. Default = /mnt/plexdrive\\n" | ||
printf " -l List location. Default = /tmp/plexus/list.txt\\n" | ||
printf " -v Video codec. Default = h264\\n" | ||
exit 0 | ||
fi | ||
|
||
if [ -z "$audio_codec" ]; then audio_codec="aac"; fi | ||
if [ -z "$list_file" ]; then list_file="/tmp/plexus/list.txt"; fi | ||
if [ -z "$media_dir" ]; then media_dir="/mnt/plexdrive"; fi | ||
if [ -z "$video_codec" ]; then video_codec="h264"; fi | ||
|
||
printf "\\e[32mAudio codec: $audio_codec\\nList file: $list_file\\nMedia directory: $media_dir\\nVideo codec: $video_codec\\n\\n" | ||
|
||
if [ -f $list_file ] | ||
then | ||
answer="waiting" | ||
while [ ! -z $answer ] | ||
do | ||
read -r -n 1 -p 'This will delete the current list file. Do you want to continue? ' answer | ||
|
||
case $answer in | ||
"Y" | "y") | ||
rm "$list_file" | ||
answer="" | ||
printf "\\n\\n" | ||
;; | ||
"N" | "n") | ||
printf "\\nYou can find the current list file here: $list_file\\n" | ||
exit 4 | ||
;; | ||
*) | ||
printf "\\nPlease enter yes or no.\\n" | ||
;; | ||
esac | ||
done | ||
fi | ||
|
||
printf "\\e[32mScanning directory...\\n" | ||
while IFS= read -r f | ||
do | ||
printf "\\e[94mLooking at: $f\\n" | ||
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") | ||
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") | ||
|
||
if [[ "$file_audio_codec" != "$audio_codec" || "$file_video_codec" != "$video_codec" ]] | ||
then | ||
echo "$f" >> $list_file | ||
fi | ||
done < <(find "$media_dir" -name '*.avi' -or -name '*.flv' -or -name '*.mkv' -or -name '*.mov' -or -name '*.mp4' -or -name '*.mpg' -or -name '*.wmv') | ||
printf "\\e[32mScan complete! Run plexus encode to process the list.\\n" | ||
} | ||
|
||
function encode { | ||
printf "$HEADER_TEXT" | ||
} | ||
|
||
function help { | ||
printf "$HEADER_TEXT" | ||
printf "\\n\\e[37mUsage:\\n plexus [flags]\\n plexus [command]\\n" | ||
printf "\\nAvailable Commands:\\n" | ||
printf " about Learn more about the program\\n" | ||
printf " build Build a .txt file containing media with incorrect codecs\\n" | ||
printf " encode Begin processing the encode queue\\n" | ||
printf " help Displays a list of available commands\\n" | ||
printf " install Install plex-encode\\n" | ||
} | ||
|
||
function install { | ||
printf "$HEADER_TEXT" | ||
printf "\\n\\e[32mInstalling missing dependencies.\\n\\n\\e[94m" | ||
apt-get install curl ffmpeg unzip -y | ||
printf "\\n\\e[32mCreating directories if they don't already exist.\\n\\n\\e[94m" | ||
mkdir -p /mnt/plex-encode /tmp/plex-encode /tmp/plex-encode/convert /tmp/plex-encode/converted | ||
printf "\\e[32mInstalling RClone.\\n\\n\\e[94m" | ||
curl https://rclone.org/install.sh | sudo bash | ||
printf "\\e[32mRClone installed.\\n" | ||
printf "\\n\\e[32mBegin RClone configuration (skip this if you already have a remote setup).\\n\\n\\e[94m" | ||
rclone config | ||
printf "\\n\\n\\e[32mInstall completed!\\n" | ||
printf "\\nPlease run 'plex-encode build' next.\\n" | ||
} | ||
|
||
"$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
printf "\n\e[93m=== Plexus v0.5 - Developed by Robert Thomas ===" | ||
printf "\n=== https://github.com/Wolveix/plexus ===" | ||
printf "\n\e[32mInstalling plexus...\n\e[94m" | ||
mv plexus/plexus /usr/local/bin/ | ||
printf "\n\e[32mPlexus has been successfully installed. Please run 'plexus install' to continue.\n\n" | ||
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
rm -rf $script_dir && cd |