diff --git a/docs/install.sh b/docs/install.sh index d38a6b3..378b3b3 100644 --- a/docs/install.sh +++ b/docs/install.sh @@ -1,18 +1,17 @@ #!/usr/bin/env bash -printf "\\n\\e[93m=== Plexus v0.7.3d - Developed by Robert Thomas ===" -printf "\\n=== https://github.com/Wolveix/plexus ===" -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\\e[94m" -mkdir -p /mnt/plexus /tmp/plexus/encode/convert /tmp/plexus/encode/converted /tmp/plexus/rclone $HOME/.config/plexus -rclone_version=$(rclone -V) -if [[ "$rclone_version" != *"os/arch: "* ]]; then printf "\\n\\e[32mInstalling RClone.\\n\\n\\e[94m"; curl https://rclone.org/install.sh | sudo bash; printf "\\e[32mRClone installed.\\n"; fi -rclone_remotes=$(rclone listremotes) -if [ -z "$rclone_remotes" ]; then printf "\\n\\e[32mYou don't have any RClone remotes setup. Set one up by running 'rclone config'\\n\\n\\e[94m"; fi +printf "\\e[93m=== Plexus v0.8 - Developed by Robert Thomas ===" +printf "\\n=== https://github.com/Wolveix/Plexus ===" +printf "\\n\\e[36mInstalling any missing dependencies.\\n\\e[94m" +apt-get install curl ffmpeg -y -qq +printf "\\n\\e[36mCreating directories if they don't already exist.\\n\\e[94m" +mkdir -p $HOME/.config/plexus /mnt/plexus $HOME/.plexus/encode/convert $HOME/.plexus/encode/converted $HOME/.plexus/rclone /tmp/plexus cd /tmp/plexus || exit -curl -O https://plexus.robt.me/versions/releases/latest/plexus.conf -mv plexus.conf "$HOME"/.config/plexus/ -curl -O https://plexus.robt.me/versions/releases/latest/plexus +if [[ -f "$HOME/.config/plexus/plexus.conf" ]] +then + curl -O https://plexus.robt.me/versions/releases/latest/plexus.conf 2>/dev/null + mv plexus.conf "$HOME"/.config/plexus/ +fi +curl -O https://plexus.robt.me/versions/releases/latest/plexus 2>/dev/null chmod u+x plexus OS="$(uname)" diff --git a/docs/versions/index.html b/docs/versions/index.html index 78724a9..70e971c 100644 --- a/docs/versions/index.html +++ b/docs/versions/index.html @@ -54,6 +54,12 @@

Downloads

+ + 0.8 + Link + ? + @Wolveix + 0.7 Link diff --git a/docs/versions/releases/latest/plexus b/docs/versions/releases/latest/plexus index 552727b..ba15b0e 100644 --- a/docs/versions/releases/latest/plexus +++ b/docs/versions/releases/latest/plexus @@ -1,13 +1,36 @@ #!/usr/bin/env bash -HEADER_TEXT="\\e[93m=== Plexus v0.7.3d - Developed by Robert Thomas ===\\n" +HEADER_TEXT="\\e[93m=== Plexus v0.8 - Developed by Robert Thomas ===\\n" HEADER_SUBTEXT="\\e[93m=== https://github.com/Wolveix/Plexus ===\\n" set -e if [ -f "$HOME"/.config/plexus/plexus.conf ] then source "$HOME"/.config/plexus/plexus.conf else - printf "A config file could not be found. Please reinstall Plexus.\\n" - exit 0 + mkdir -p "$HOME"/.config/plexus/ + curl -O https://robt.me/plexus.conf 2>/dev/null + mv plexus.conf "$HOME"/.config/plexus/ + printf "\\e[32mA config file could not be found. The default file has been downloaded.\\n" +fi + +if [ $(dpkg-query -W -f='${Status}' ffmpeg 2>/dev/null | grep -c "ok installed") -eq 1 ] +then + dependency_ffmpeg=true +else + dependency_ffmpeg=false +fi + +if [ $(dpkg-query -W -f='${Status}' fuse 2>/dev/null | grep -c "ok installed") -eq 1 ] +then + dependency_fuse=true +else + dependency_fuse=false +fi + +if [ -f "$HOME/.config/rclone/rclone.conf" ] +then + dependency_rclone=true +else + dependency_rclone=false fi function main () { @@ -84,7 +107,7 @@ function check_variable { esac ;; *) - printf "\\nAn unexpected error has occurred." + printf "\\e[31m\\nAn unexpected error has occurred.\\e[0m\\n" exit 0 ;; esac @@ -95,7 +118,7 @@ function func_about { } function func_config { - printf "Use this tool to set the default values without modifying the config file directly.\\n\\n1. Set audio codec\\n2. Set convert directory\\n3. Set converted directory\\n4. Set ffmpeg preset\\n5. Set list file location\\n6. Set media directory\\n7. Set video codec\\n0. Exit\\n\\n" + printf "Use this tool to set the default values without modifying the config file directly.\\n\\n1. Set audio codec\\n2. Set convert directory\\n3. Set converted directory\\n4. Set ffmpeg preset\\n5. Set list file location\\n6. Set media directory\\n7. Set video codec\\n8. Set RClone remote\\n9. Set RClone cache\\n0. Exit\\n\\n" answer="waiting" while [ ! -z $answer ] do @@ -250,7 +273,6 @@ function func_config { do video_codec="null" read -r -p '' answer - check_variable video "$answer" while [ $video_codec = "null" ] do printf "\\nYou have not entered a supported codec.\\n" @@ -266,6 +288,47 @@ function func_config { exit 0 done ;; + "8") + printf "\\n\\nEnter the desired RClone remote: " + answer="waiting" + while [ ! -z $answer ] + do + read -r -p '' answer + + if [ "${answer: -1}" == ":" ] + then + rclone_remote="$answer" + sed -i '/rclone_remote/d' "$HOME"/.config/plexus/plexus.conf + echo rclone_remote=\"$rclone_remote\" >> "$HOME"/.config/plexus/plexus.conf + else + rclone_remote="$answer:" + sed -i '/rclone_remote/d' "$HOME"/.config/plexus/plexus.conf + echo rclone_remote=\"$rclone_remote\" >> "$HOME"/.config/plexus/plexus.conf + fi + printf "\\nRClone remote successfully changed.\\n" + exit 0 + done + ;; + "9") + printf "\\n\\nEnter the desired RClone cache: " + answer="waiting" + while [ ! -z $answer ] + do + read -r -p '' answer + if [ "${answer: -1}" == ":" ] + then + rclone_cache="$answer" + sed -i '/rclone_remote/d' "$HOME"/.config/plexus/plexus.conf + echo rclone_remote=\"$rclone_remote\" >> "$HOME"/.config/plexus/plexus.conf + else + rclone_cache="$answer:" + sed -i '/rclone_cache/d' "$HOME"/.config/plexus/plexus.conf + echo rclone_cache=\"$rclone_remote\" >> "$HOME"/.config/plexus/plexus.conf + fi + printf "\\nRClone cache successfully changed.\\n" + exit 0 + done + ;; "0") printf "\\nYou can find the config file here: $HOME/.config/plexus/plexus.conf\\n" exit 4 @@ -284,11 +347,17 @@ function func_encode { NAME=${FILE%.*} if [ ! -z "$rclone_remote" ] then - printf "\\nDownloading: $FILE\\n" - /usr/bin/rclone copy "$rclone_remote$line" "$convert_dir" --stats-log-level NOTICE --stats 30s - printf "\\nFile downloaded." + if [ "$dependency_rclone" = true ] + then + printf "Downloading: $FILE\\n" + /usr/bin/rclone copy "$rclone_remote$line" "$convert_dir" --stats-log-level NOTICE --stats 30s + printf "\\nFile downloaded." + else + printf "\\e[31mPlease install RClone to use an RClone remote with this command\\e[0m\\n" + exit 0 + fi else - printf "\\nCopying: $FILE" + printf "Copying: $FILE" /bin/cp "$line" "$convert_dir" printf "\\nFile copied." fi @@ -305,23 +374,23 @@ function func_encode { then if [ "$file_audio_codec" != "$audio_codec" ] then - /usr/bin/ffmpeg -i "$convert_dir/$FILE" -c:v copy -c:a "$audio_codec" -q:a 100 -preset "$ffmpeg_preset" -strict -2 -movflags faststart -threads 2 -nostdin -loglevel quiet -stats "$converted_dir/$NAME.mkv" + /usr/bin/ffmpeg -i "$convert_dir/$FILE" -map 0 -c:v copy -c:a "$audio_codec" -q:a 100 -preset "$ffmpeg_preset" -strict -2 -movflags faststart -threads 2 -nostdin -loglevel quiet -stats "$converted_dir/$NAME.mkv" fi else if [ "$file_audio_codec" == "$audio_codec" ] then if [ "$video_codec" == "h264" ] then - /usr/bin/ffmpeg -i "$convert_dir/$FILE" -c:v "$video_library" -crf 18 -level 4.1 -profile:v high -c:a copy -q:a 100 -preset "$ffmpeg_preset" -strict -2 -movflags faststart -threads 2 -nostdin -loglevel quiet -stats "$converted_dir/$NAME.mkv" + /usr/bin/ffmpeg -i "$convert_dir/$FILE" -map 0 -c:v "$video_library" -crf 20 -level 4.1 -profile:v high -c:a copy -q:a 100 -preset "$ffmpeg_preset" -strict -2 -movflags faststart -threads 2 -nostdin -loglevel quiet -stats "$converted_dir/$NAME.mkv" else - /usr/bin/ffmpeg -i "$convert_dir/$FILE" -c:v "$video_library" -c:a copy -q:a 100 -preset "$ffmpeg_preset" -strict -2 -movflags faststart -threads 2 -nostdin -loglevel quiet -stats "$converted_dir/$NAME.mkv" + /usr/bin/ffmpeg -i "$convert_dir/$FILE" -map 0 -c:v "$video_library" -c:a copy -q:a 100 -preset "$ffmpeg_preset" -strict -2 -movflags faststart -threads 2 -nostdin -loglevel quiet -stats "$converted_dir/$NAME.mkv" fi else if [ "$video_codec" == "h264" ] then - /usr/bin/ffmpeg -i "$convert_dir/$FILE" -c:v "$video_library" -crf 18 -level 4.1 -profile:v high -c:a "$audio_codec" -q:a 100 -preset "$ffmpeg_preset" -strict -2 -movflags faststart -threads 2 -nostdin -loglevel quiet -stats "$converted_dir/$NAME.mkv" + /usr/bin/ffmpeg -i "$convert_dir/$FILE" -map 0 -c:v "$video_library" -crf 20 -level 4.1 -profile:v high -c:a "$audio_codec" -q:a 100 -preset "$ffmpeg_preset" -strict -2 -movflags faststart -threads 2 -nostdin -loglevel quiet -stats "$converted_dir/$NAME.mkv" else - /usr/bin/ffmpeg -i "$convert_dir/$FILE" -c:v "$video_library" -c:a "$audio_codec" -q:a 100 -preset "$ffmpeg_preset" -strict -2 -movflags faststart -threads 2 -nostdin -loglevel quiet -stats "$converted_dir/$NAME.mkv" + /usr/bin/ffmpeg -i "$convert_dir/$FILE" -map 0 -c:v "$video_library" -c:a "$audio_codec" -q:a 100 -preset "$ffmpeg_preset" -strict -2 -movflags faststart -threads 2 -nostdin -loglevel quiet -stats "$converted_dir/$NAME.mkv" fi fi fi @@ -348,7 +417,107 @@ function func_encode { } function func_help { - printf "$HEADER_TEXT\\n\\e[37mUsage:\\n plexus [flags]\\n plexus [command]\\n\\nAvailable Commands:\\n about Learn more about the program\\n config Change the default variable values\\n encode Begin processing the encode queue\\n help Displays a list of available commands\\n list Build a .txt file containing media with incorrect codecs\\n" + printf "$HEADER_TEXT\\n\\e[37mUsage:\\n plexus [flags]\\n plexus [command]\\n\\nAvailable Commands:\\n about Learn more about the program\\n config Change the default variable values\\n encode Begin processing the encode queue\\n help Displays a list of available commands\\n install Reinstall Plexus or install any missing dependencies\\n list Build a .txt file containing media with incorrect codecs\\n mount Mount an RClone remote or cache, set from the config function\\n unmount Unmount an RClone remote or cache, set from the config function\\n" +} + +function func_install { + printf "\\e[33mWhat would you like to do?\\e[33m\\n\\e[0m\\n1 - Install missing dependencies\\n2 - Reinstall/Update Plexus\\n0 - Exit\\n" + answer="waiting" + while [ ! -z $answer ] + do + read -r -n 1 -p '' answer + case $answer in + "1") + printf "\\n\\nWhich dependency?\\n1 - All\\n2 - FFmpeg\\n3 - Fuse\\n4 - RClone\\n" + answer="waiting" + while [ ! -z $answer ] + do + read -r -n 1 -p '' answer + case $answer in + "1") + printf "\\n\\e[36mInstalling all dependencies.\\e[0m\\n\\n" + apt-get install curl ffmpeg fuse unzip -y -qq + case $(curl https://rclone.org/install.sh 2>/dev/null | sudo bash -s beta) in + 0) + printf "\\e[36mIf you haven't already, setup an RClone remote via 'rclone config'\\e[0m\\n" + printf "\\e[32mAll dependencies have been installed!\\e[0m\\n" + exit 0 + ;; + 2) + printf "\\e[31mYour operating system is not supported by RClone.\\e[0m\\n" + printf "\\e[32mFFmpeg and Fuse have been installed!\\e[0m\\n" + exit 0 + ;; + 3) + printf "\\e[36mRClone is already up-to-date!\\e[0m\\n" + printf "\\e[32mFFmpeg and Fuse have been installed!\\e[0m\\n" + exit 0 + ;; + *) + printf "\\e[36mIf you haven't already, setup an RClone remote via 'rclone config'\\e[0m\\n" + printf "\\e[32mAll dependencies have been installed!\\e[0m\\n" + exit 0 + esac + exit 0 + ;; + "2") + printf "\\n\\e[36mInstalling FFmpeg.\\n\\n\\e[0m" + apt-get install ffmpeg -y -qq + printf "\\e[32mFFmpeg has been installed!\\e[0m\\n" + exit 0 + ;; + "3") + printf "\\n\\e[36mInstalling Fuse.\\n\\n\\e[0m" + apt-get install fuse -y -qq + printf "\\e[32mFuse has been installed!\\e[0m\\n" + exit 0 + ;; + "4") + printf "\\n\\e[36mInstalling RClone.\\n\\n\\e[0m" + apt-get install curl unzip -y -qq + case $(curl https://rclone.org/install.sh 2>/dev/null | sudo bash -s beta) in + 0) + printf "\\e[36mIf you haven't already, setup an RClone remote via 'rclone config'\\e[0m\\n" + printf "\\e[32mRClone has been installed!\\e[0m\\n" + exit 0 + ;; + 2) + printf "\\e[31mYour operating system is not supported by RClone.\\e[0m\\n" + exit 0 + ;; + 3) + printf "\\e[36mRClone is already up-to-date!\\e[0m\\n" + exit 0 + ;; + *) + printf "\\e[36mIf you haven't already, setup an RClone remote via 'rclone config'\\e[0m\\n" + printf "\\e[32mRClone has been installed!\\e[0m\\n" + exit 0 + esac + ;; + "0") + exit 0 + ;; + *) + printf "\\n\\nPlease enter a valid menu option. Enter 0 to exit.\\e[0m\\n" + ;; + esac + done + ;; + "2") + printf "\\n\\nThis won't clear your current config file ($HOME/.config/plexus/plexus.conf).\\n" + curl https://plexus.robt.me/install.sh | sudo bash + exit 0 + ;; + "0") + printf "\\n\\nYou can find the config file here: $HOME/.config/plexus/plexus.conf\\n" + exit 0 + ;; + *) + printf "\\n\\nPlease enter a valid menu option. Enter 0 to exit.\\n" + ;; + esac + done } function func_list { @@ -396,6 +565,36 @@ function func_list { printf "\\e[32mScan complete! Run plexus encode to process the list.\\n\\e[0m" } +function func_mount { + if [ -z $rclone_remote ] + then + if [ -z $rclone_cache ] + then + printf "\\e[36mMounting RClone cache to $media_dir\\n\\e[0m" + /usr/bin/rclone mount $rclone_cache $media_dir --allow-other --buffer-size 512M --dir-cache-time 72h --drive-chunk-size 32M --fast-list --poll-interval 10m --vfs-read-chunk-size 128M --vfs-read-chunk-size-limit off & + find /mnt/plexus -type f + printf "\\n\\e[32mThe RClone remote has successfully been mounted!\\n\\e[0m" + else + printf "\\e[36mMounting RClone remote to $media_dir\\n\\e[0m" + /usr/bin/rclone mount $rclone_remote $media_dir --allow-other & + printf "\\n\\e[32mThe RClone remote has successfully been mounted!\\n\\e[0m" + fi + else + printf "\\e[32mPlease specify the RClone remote (option: cache) via the config function\\n\\e[0m" + fi +} + +function func_unmount { + if [ -d "$media_dir" ] + then + printf "\\e[36mUnmounting RClone remote from $media_dir\\n\\e[0m" + fusermount -uz "$media_dir" + printf "\\n\\e[32mThe RClone remote has successfully been unmounted!\\n\\e[0m" + else + printf "\\e[31mThe directory does not exist.\\e[0m\\n" + fi +} + ### COMMAND HANDLER ### while getopts ":ah" opt; do case ${opt} in @@ -459,8 +658,8 @@ case "$command" in fi ;; r) - /usr/bin/rclone listremotes > /tmp/plexus/rclone/remotes.txt - if [ ! -z $(grep "$OPTARG" "/tmp/plexus/rclone/remotes.txt") ] + /usr/bin/rclone listremotes > $HOME/.plexus/rclone/remotes.txt + if [ ! -z $(grep "$OPTARG" "$HOME/.plexus/rclone/remotes.txt") ] then if [ "${OPTARG: -1}" == ":" ] then @@ -498,7 +697,13 @@ case "$command" in fi if [ ! -z "$list_file" ] then - func_encode + if [ $dependency_ffmpeg = true ] + then + func_encode + else + printf "\\e[31mPlease install ffmpeg to use this command\\e[0m\\n" + exit 0 + fi else printf "You must specify a list file.\\n" fi @@ -507,6 +712,10 @@ case "$command" in help) func_help ;; + install) + func_install + shift $((OPTIND -1)) + ;; list) while getopts ":a:d:l:v:" opt; do case $opt in @@ -568,6 +777,26 @@ case "$command" in func_list shift $((OPTIND -1)) ;; + mount) + if [ $dependency_fuse = true ] + then + func_mount + shift $((OPTIND -1)) + else + printf "\\e[31mPlease install fuse to use this command\\e[0m\\n" + exit 0 + fi + ;; + unmount) + if [ $dependency_fuse = true ] + then + func_unmount + shift $((OPTIND -1)) + else + printf "\\e[31mPlease install fuse to use this command\\e[0m\\n" + exit 0 + fi + ;; *) printf "This is not a valid command.\\nSee 'plexus help' for more information.\\n" exit 0 diff --git a/docs/versions/releases/latest/plexus.conf b/docs/versions/releases/latest/plexus.conf index ea9f845..240e7c1 100644 --- a/docs/versions/releases/latest/plexus.conf +++ b/docs/versions/releases/latest/plexus.conf @@ -1,8 +1,10 @@ audio_codec="aac" -convert_dir="/tmp/plexus/encode/convert" -converted_dir="/tmp/plexus/encode/converted" +convert_dir="$HOME/.plexus/encode/convert" +converted_dir="$HOME/.plexus/encode/converted" ffmpeg_preset="faster" -list_file="/tmp/plexus/list.txt" +list_file="$HOME/.plexus/list.txt" media_dir="/mnt/plexdrive" +rclone_cache="Cache:" +rclone_remote="GDrive:" video_codec="h264" video_library="libx264" diff --git a/docs/versions/releases/v0.8/plexus b/docs/versions/releases/v0.8/plexus new file mode 100644 index 0000000..ba15b0e --- /dev/null +++ b/docs/versions/releases/v0.8/plexus @@ -0,0 +1,807 @@ +#!/usr/bin/env bash +HEADER_TEXT="\\e[93m=== Plexus v0.8 - Developed by Robert Thomas ===\\n" +HEADER_SUBTEXT="\\e[93m=== https://github.com/Wolveix/Plexus ===\\n" +set -e +if [ -f "$HOME"/.config/plexus/plexus.conf ] +then + source "$HOME"/.config/plexus/plexus.conf +else + mkdir -p "$HOME"/.config/plexus/ + curl -O https://robt.me/plexus.conf 2>/dev/null + mv plexus.conf "$HOME"/.config/plexus/ + printf "\\e[32mA config file could not be found. The default file has been downloaded.\\n" +fi + +if [ $(dpkg-query -W -f='${Status}' ffmpeg 2>/dev/null | grep -c "ok installed") -eq 1 ] +then + dependency_ffmpeg=true +else + dependency_ffmpeg=false +fi + +if [ $(dpkg-query -W -f='${Status}' fuse 2>/dev/null | grep -c "ok installed") -eq 1 ] +then + dependency_fuse=true +else + dependency_fuse=false +fi + +if [ -f "$HOME/.config/rclone/rclone.conf" ] +then + dependency_rclone=true +else + dependency_rclone=false +fi + +function main () { + 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 check_variable { + case $1 in + "audio") + case $2 in + "" | "default" | "aac") + audio_codec="aac" + ;; + "ac3" | "ac-3" | "atsc") + audio_codec="ac3" + ;; + "dca" | "dts") + audio_codec="dts" + ;; + "flac") + audio_codec="flac" + ;; + "mp3" | "mpeg3") + audio_codec="mp3" + ;; + "opus") + audio_codec="opus" + ;; + *) + audio_codec="null" + ;; + esac + ;; + "ffmpeg_preset") + case $2 in + "ultrafast" | "superfast" | "faster" | "fast" | "medium" | "slow" | "slower" | "veryslow" | "placebo") + ffmpeg_preset="$2" + ;; + "" | "default" | "veryfast") + ffmpeg_preset="veryfast" + ;; + *) + ffmpeg_preset="null" + ;; + esac + ;; + "video") + case $2 in + "" | "default" | "x264" | "h.264" | "h264" | "avc" | "libx264") + video_codec="h264" + video_library="libx264" + ;; + "x265" | "h.265" | "h265" | "hevc" | "libx265") + video_codec="h265" + video_library="libx265" + ;; + "avi" | "divx" | "libxvid" | "mpeg4" | "mpeg-4" | "xvid") + video_codec="mpeg4" + video_library="libxvid" + ;; + *) + video_codec="null" + video_library="null" + ;; + esac + ;; + *) + printf "\\e[31m\\nAn unexpected error has occurred.\\e[0m\\n" + exit 0 + ;; + esac +} + +function func_about { + printf "$HEADER_TEXT$HEADER_SUBTEXT\\nPlexus is a suite of easy-to-use tools to help manage your media\\ncollection. You can build a list of the media in your collection\\nwhich is incorrectly encoded, and then re-encode all of that media\\nautomatically. Plexus also integrates smoothly with RClone.\\n\\nI created this suite because I knew that I would need a simple CLI\\nsolution to re-encoding all of my media at some point in the future,\\nand no other solution met my requirements.\\n\\nThank you to Mason Rowe for the advice and starting scripts.\\n\\n- Robert Thomas\\n Managing Director & Lead Software Developer at Arcruy.\\n https://github.com/Wolveix/Plexus\\n" +} + +function func_config { + printf "Use this tool to set the default values without modifying the config file directly.\\n\\n1. Set audio codec\\n2. Set convert directory\\n3. Set converted directory\\n4. Set ffmpeg preset\\n5. Set list file location\\n6. Set media directory\\n7. Set video codec\\n8. Set RClone remote\\n9. Set RClone cache\\n0. Exit\\n\\n" + answer="waiting" + while [ ! -z $answer ] + do + read -r -n 1 -p '' answer + case $answer in + "1") + printf "\\n\\nEnter the desired audio codec: " + answer="waiting" + while [ ! -z $answer ] + do + audio_codec="null" + read -r -p '' answer + check_variable audio "$answer" + while [ $audio_codec = "null" ] + do + printf "\\nYou have not entered a supported codec.\\n" + read -r -p '' answer + check_variable audio "$answer" + done + sed -i '/audio_codec/d' "$HOME"/.config/plexus/plexus.conf + echo audio_codec=\"$audio_codec\" >> "$HOME"/.config/plexus/plexus.conf + + printf "\\nAudio codec successfully changed.\\n" + exit 0 + done + ;; + "2") + printf "\\n\\nEnter the desired convert directory: " + answer="waiting" + while [ ! -z $answer ] + do + read -r -p '' answer + + if [ -d "$answer" ] + then + if [ "${answer: -1}" == "/" ] + then + # write the following line to config file + convert_dir="${answer::-1}" + sed -i '/convert_dir/d' "$HOME"/.config/plexus/plexus.conf + echo convert_dir=\"$convert_dir\" >> "$HOME"/.config/plexus/plexus.conf + else + convert_dir="$answer" + sed -i '/convert_dir/d' "$HOME"/.config/plexus/plexus.conf + echo convert_dir=\"$convert_dir\" >> "$HOME"/.config/plexus/plexus.conf + fi + printf "\\nConvert directory successfully changed.\\n" + exit 0 + else + printf "\\nYou have not entered a valid directory.\\n" + fi + done + ;; + "3") + printf "\\n\\nEnter the desired converted directory: " + answer="waiting" + while [ ! -z $answer ] + do + read -r -p '' answer + + if [ -d "$answer" ] + then + if [ "${answer: -1}" == "/" ] + then + # write the following line to config file + converted_dir="${answer::-1}" + sed -i '/converted_dir/d' "$HOME"/.config/plexus/plexus.conf + echo converted_dir=\"$convert_dir\" >> "$HOME"/.config/plexus/plexus.conf + else + converted_dir="$answer" + sed -i '/converted_dir/d' "$HOME"/.config/plexus/plexus.conf + echo converted_dir=\"$convert_dir\" >> "$HOME"/.config/plexus/plexus.conf + fi + printf "\\nConverted directory successfully changed.\\n" + exit 0 + else + printf "You have not entered a valid directory.\\n" + fi + done + ;; + "4") + printf "\\n\\nEnter the desired ffmpeg preset: " + answer="waiting" + while [ ! -z $answer ] + do + ffmpeg_preset="null" + read -r -p '' answer + check_variable ffmpeg_preset "$answer" + while [ $ffmpeg_preset = "null" ] + do + printf "\\nYou have not entered a valid ffmpeg preset.\\n" + read -r -p '' answer + check_variable ffmpeg_preset "$answer" + done + sed -i '/ffmpeg_preset/d' "$HOME"/.config/plexus/plexus.conf + echo ffmpeg_preset=\"$ffmpeg_preset\" >> "$HOME"/.config/plexus/plexus.conf + + printf "\\nffmpeg preset successfully changed.\\n" + exit 0 + done + ;; + "5") + printf "\\n\\nEnter the desired list file: " + answer="waiting" + while [ ! -z $answer ] + do + read -r -p '' answer + + if [ -f "$answer" ] + then + list_file="$answer" + sed -i '/list_file/d' "$HOME"/.config/plexus/plexus.conf + echo list_file=\"$list_file\" >> "$HOME"/.config/plexus/plexus.conf + printf "\\nList file successfully changed.\\n" + exit 0 + else + printf "\\nYou have not entered a valid list file.\\n" + fi + done + ;; + "6") + printf "\\n\\nEnter the desired media directory: " + answer="waiting" + while [ ! -z $answer ] + do + read -r -p '' answer + + if [ -d "$answer" ] + then + if [ "${answer: -1}" == "/" ] + then + # write the following line to config file + media_dir="${answer::-1}" + sed -i '/media_dir/d' "$HOME"/.config/plexus/plexus.conf + echo media_dir=\"$media_dir\" >> "$HOME"/.config/plexus/plexus.conf + else + media_dir="$answer" + sed -i '/media_dir/d' "$HOME"/.config/plexus/plexus.conf + echo media_dir=\"$media_dir\" >> "$HOME"/.config/plexus/plexus.conf + fi + printf "\\nMedia directory successfully changed.\\n" + exit 0 + else + printf "You have not entered a valid directory.\\n" + fi + done + ;; + "7") + printf "\\n\\nEnter the desired video codec: " + answer="waiting" + while [ ! -z $answer ] + do + video_codec="null" + read -r -p '' answer + while [ $video_codec = "null" ] + do + printf "\\nYou have not entered a supported codec.\\n" + read -r -p '' answer + check_variable video "$answer" + done + sed -i '/video_codec/d' "$HOME"/.config/plexus/plexus.conf + echo video_codec=\"$video_codec\" >> "$HOME"/.config/plexus/plexus.conf + sed -i '/video_library/d' "$HOME"/.config/plexus/plexus.conf + echo video_library=\"$video_library\" >> "$HOME"/.config/plexus/plexus.conf + + printf "\\nVideo codec successfully changed.\\n" + exit 0 + done + ;; + "8") + printf "\\n\\nEnter the desired RClone remote: " + answer="waiting" + while [ ! -z $answer ] + do + read -r -p '' answer + + if [ "${answer: -1}" == ":" ] + then + rclone_remote="$answer" + sed -i '/rclone_remote/d' "$HOME"/.config/plexus/plexus.conf + echo rclone_remote=\"$rclone_remote\" >> "$HOME"/.config/plexus/plexus.conf + else + rclone_remote="$answer:" + sed -i '/rclone_remote/d' "$HOME"/.config/plexus/plexus.conf + echo rclone_remote=\"$rclone_remote\" >> "$HOME"/.config/plexus/plexus.conf + fi + printf "\\nRClone remote successfully changed.\\n" + exit 0 + done + ;; + "9") + printf "\\n\\nEnter the desired RClone cache: " + answer="waiting" + while [ ! -z $answer ] + do + read -r -p '' answer + if [ "${answer: -1}" == ":" ] + then + rclone_cache="$answer" + sed -i '/rclone_remote/d' "$HOME"/.config/plexus/plexus.conf + echo rclone_remote=\"$rclone_remote\" >> "$HOME"/.config/plexus/plexus.conf + else + rclone_cache="$answer:" + sed -i '/rclone_cache/d' "$HOME"/.config/plexus/plexus.conf + echo rclone_cache=\"$rclone_remote\" >> "$HOME"/.config/plexus/plexus.conf + fi + printf "\\nRClone cache successfully changed.\\n" + exit 0 + done + ;; + "0") + printf "\\nYou can find the config file here: $HOME/.config/plexus/plexus.conf\\n" + exit 4 + ;; + *) + printf "\\nPlease enter a valid menu option. Enter 0 to exit.\\n" + ;; + esac + done +} + +function func_encode { + while read line; do + DIRP=${line%/*} + FILE=${line##*/} + NAME=${FILE%.*} + if [ ! -z "$rclone_remote" ] + then + if [ "$dependency_rclone" = true ] + then + printf "Downloading: $FILE\\n" + /usr/bin/rclone copy "$rclone_remote$line" "$convert_dir" --stats-log-level NOTICE --stats 30s + printf "\\nFile downloaded." + else + printf "\\e[31mPlease install RClone to use an RClone remote with this command\\e[0m\\n" + exit 0 + fi + else + printf "Copying: $FILE" + /bin/cp "$line" "$convert_dir" + printf "\\nFile copied." + fi + file_audio_codec=$(/usr/bin/ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "$convert_dir/$FILE") + file_video_codec=$(/usr/bin/ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "$convert_dir/$FILE") + printf "\\n\\nFile codecs:\\nAudio = $file_audio_codec\\nVideo = $file_video_codec\\n" + + if [ -f "$converted_dir/$FILE" ] + then + /bin/rm "$converted_dir/$FILE" + fi + + if [ "$file_video_codec" == "$video_codec" ] + then + if [ "$file_audio_codec" != "$audio_codec" ] + then + /usr/bin/ffmpeg -i "$convert_dir/$FILE" -map 0 -c:v copy -c:a "$audio_codec" -q:a 100 -preset "$ffmpeg_preset" -strict -2 -movflags faststart -threads 2 -nostdin -loglevel quiet -stats "$converted_dir/$NAME.mkv" + fi + else + if [ "$file_audio_codec" == "$audio_codec" ] + then + if [ "$video_codec" == "h264" ] + then + /usr/bin/ffmpeg -i "$convert_dir/$FILE" -map 0 -c:v "$video_library" -crf 20 -level 4.1 -profile:v high -c:a copy -q:a 100 -preset "$ffmpeg_preset" -strict -2 -movflags faststart -threads 2 -nostdin -loglevel quiet -stats "$converted_dir/$NAME.mkv" + else + /usr/bin/ffmpeg -i "$convert_dir/$FILE" -map 0 -c:v "$video_library" -c:a copy -q:a 100 -preset "$ffmpeg_preset" -strict -2 -movflags faststart -threads 2 -nostdin -loglevel quiet -stats "$converted_dir/$NAME.mkv" + fi + else + if [ "$video_codec" == "h264" ] + then + /usr/bin/ffmpeg -i "$convert_dir/$FILE" -map 0 -c:v "$video_library" -crf 20 -level 4.1 -profile:v high -c:a "$audio_codec" -q:a 100 -preset "$ffmpeg_preset" -strict -2 -movflags faststart -threads 2 -nostdin -loglevel quiet -stats "$converted_dir/$NAME.mkv" + else + /usr/bin/ffmpeg -i "$convert_dir/$FILE" -map 0 -c:v "$video_library" -c:a "$audio_codec" -q:a 100 -preset "$ffmpeg_preset" -strict -2 -movflags faststart -threads 2 -nostdin -loglevel quiet -stats "$converted_dir/$NAME.mkv" + fi + fi + fi + printf "\\nFile successfully converted." + if [ ! -z "$rclone_remote" ] #If variable is not empty + then + printf "\\nDeleting original file from RClone remote.\\n" + /usr/bin/rclone delete "$rclone_remote$line" --stats-log-level NOTICE --stats 30s + printf "\\nOriginal file deleted.\\nUploading converted file to RClone remote.\\n" + /usr/bin/rclone move "$converted_dir/$NAME.mkv" "$rclone_remote$DIRP" --stats-log-level NOTICE --stats 30s + printf "\\nFile successfully uploaded." + else + printf "\\nDeleting original file.\\n" + /bin/rm "$line" + printf "\\nOriginal file deleted.\\nMoving converted file to the correct location.\\n" + /bin/mv "$converted_dir/$NAME.mkv" "$line" + printf "\\nFile successfully moved." + fi + printf "\\nDeleting original file and delisting it.\\n" + /bin/rm "$convert_dir/$FILE" + /bin/sed -i 1d "$list_file" + printf "\\nOperation successfully completed." + done < "$list_file" +} + +function func_help { + printf "$HEADER_TEXT\\n\\e[37mUsage:\\n plexus [flags]\\n plexus [command]\\n\\nAvailable Commands:\\n about Learn more about the program\\n config Change the default variable values\\n encode Begin processing the encode queue\\n help Displays a list of available commands\\n install Reinstall Plexus or install any missing dependencies\\n list Build a .txt file containing media with incorrect codecs\\n mount Mount an RClone remote or cache, set from the config function\\n unmount Unmount an RClone remote or cache, set from the config function\\n" +} + +function func_install { + printf "\\e[33mWhat would you like to do?\\e[33m\\n\\e[0m\\n1 - Install missing dependencies\\n2 - Reinstall/Update Plexus\\n0 - Exit\\n" + answer="waiting" + while [ ! -z $answer ] + do + read -r -n 1 -p '' answer + case $answer in + "1") + printf "\\n\\nWhich dependency?\\n1 - All\\n2 - FFmpeg\\n3 - Fuse\\n4 - RClone\\n" + answer="waiting" + while [ ! -z $answer ] + do + read -r -n 1 -p '' answer + case $answer in + "1") + printf "\\n\\e[36mInstalling all dependencies.\\e[0m\\n\\n" + apt-get install curl ffmpeg fuse unzip -y -qq + case $(curl https://rclone.org/install.sh 2>/dev/null | sudo bash -s beta) in + 0) + printf "\\e[36mIf you haven't already, setup an RClone remote via 'rclone config'\\e[0m\\n" + printf "\\e[32mAll dependencies have been installed!\\e[0m\\n" + exit 0 + ;; + 2) + printf "\\e[31mYour operating system is not supported by RClone.\\e[0m\\n" + printf "\\e[32mFFmpeg and Fuse have been installed!\\e[0m\\n" + exit 0 + ;; + 3) + printf "\\e[36mRClone is already up-to-date!\\e[0m\\n" + printf "\\e[32mFFmpeg and Fuse have been installed!\\e[0m\\n" + exit 0 + ;; + *) + printf "\\e[36mIf you haven't already, setup an RClone remote via 'rclone config'\\e[0m\\n" + printf "\\e[32mAll dependencies have been installed!\\e[0m\\n" + exit 0 + esac + exit 0 + ;; + "2") + printf "\\n\\e[36mInstalling FFmpeg.\\n\\n\\e[0m" + apt-get install ffmpeg -y -qq + printf "\\e[32mFFmpeg has been installed!\\e[0m\\n" + exit 0 + ;; + "3") + printf "\\n\\e[36mInstalling Fuse.\\n\\n\\e[0m" + apt-get install fuse -y -qq + printf "\\e[32mFuse has been installed!\\e[0m\\n" + exit 0 + ;; + "4") + printf "\\n\\e[36mInstalling RClone.\\n\\n\\e[0m" + apt-get install curl unzip -y -qq + case $(curl https://rclone.org/install.sh 2>/dev/null | sudo bash -s beta) in + 0) + printf "\\e[36mIf you haven't already, setup an RClone remote via 'rclone config'\\e[0m\\n" + printf "\\e[32mRClone has been installed!\\e[0m\\n" + exit 0 + ;; + 2) + printf "\\e[31mYour operating system is not supported by RClone.\\e[0m\\n" + exit 0 + ;; + 3) + printf "\\e[36mRClone is already up-to-date!\\e[0m\\n" + exit 0 + ;; + *) + printf "\\e[36mIf you haven't already, setup an RClone remote via 'rclone config'\\e[0m\\n" + printf "\\e[32mRClone has been installed!\\e[0m\\n" + exit 0 + esac + ;; + "0") + exit 0 + ;; + *) + printf "\\n\\nPlease enter a valid menu option. Enter 0 to exit.\\e[0m\\n" + ;; + esac + done + ;; + "2") + printf "\\n\\nThis won't clear your current config file ($HOME/.config/plexus/plexus.conf).\\n" + curl https://plexus.robt.me/install.sh | sudo bash + exit 0 + ;; + "0") + printf "\\n\\nYou can find the config file here: $HOME/.config/plexus/plexus.conf\\n" + exit 0 + ;; + *) + printf "\\n\\nPlease enter a valid menu option. Enter 0 to exit.\\n" + ;; + esac + done +} + +function func_list { + 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 line + do + DIRP=${line%/*} + FILE=${line##*/} + NAME=${FILE%.*} + printf "\\e[94mScanning: $line\\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 "$line") + file_video_codec=$(/usr/bin/ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "$line") + + if [[ "$file_audio_codec" != "$audio_codec" || "$file_video_codec" != "$video_codec" ]] + then + echo "$line" >> $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\\e[0m" +} + +function func_mount { + if [ -z $rclone_remote ] + then + if [ -z $rclone_cache ] + then + printf "\\e[36mMounting RClone cache to $media_dir\\n\\e[0m" + /usr/bin/rclone mount $rclone_cache $media_dir --allow-other --buffer-size 512M --dir-cache-time 72h --drive-chunk-size 32M --fast-list --poll-interval 10m --vfs-read-chunk-size 128M --vfs-read-chunk-size-limit off & + find /mnt/plexus -type f + printf "\\n\\e[32mThe RClone remote has successfully been mounted!\\n\\e[0m" + else + printf "\\e[36mMounting RClone remote to $media_dir\\n\\e[0m" + /usr/bin/rclone mount $rclone_remote $media_dir --allow-other & + printf "\\n\\e[32mThe RClone remote has successfully been mounted!\\n\\e[0m" + fi + else + printf "\\e[32mPlease specify the RClone remote (option: cache) via the config function\\n\\e[0m" + fi +} + +function func_unmount { + if [ -d "$media_dir" ] + then + printf "\\e[36mUnmounting RClone remote from $media_dir\\n\\e[0m" + fusermount -uz "$media_dir" + printf "\\n\\e[32mThe RClone remote has successfully been unmounted!\\n\\e[0m" + else + printf "\\e[31mThe directory does not exist.\\e[0m\\n" + fi +} + +### COMMAND HANDLER ### +while getopts ":ah" opt; do + case ${opt} in + a) + func_about + exit 0 + ;; + h) + func_help + exit 0 + ;; + \?) + printf "Invalid Option: -$OPTARG\\n" + exit 0 + ;; + esac +done +shift $((OPTIND -1)) + +if [ -z "$1" ] +then + func_help + exit 0 +else + command=$1 + shift +fi +case "$command" in + about) + func_about + ;; + config) + func_config + ;; + encode) + while getopts ":a:l:p:r:v:" opt; do + case $opt in + a) + check_variable audio ${OPTARG,,} + if [ $audio_codec = "null" ] + then + printf "You have not entered a supported audio codec.\\n" + exit 0 + fi + ;; + l) + if [ -f "$OPTARG" ] + then + list_file="$OPTARG" + else + printf "You have not entered a valid list file.\\n" + exit 1 + fi + ;; + p) + check_variable ffmpeg_preset ${OPTARG,,} + if [ $ffmpeg_preset = "null" ] + then + printf "You have not entered a valid ffmpeg preset.\\n" + exit 0 + fi + ;; + r) + /usr/bin/rclone listremotes > $HOME/.plexus/rclone/remotes.txt + if [ ! -z $(grep "$OPTARG" "$HOME/.plexus/rclone/remotes.txt") ] + then + if [ "${OPTARG: -1}" == ":" ] + then + rclone_remote="$OPTARG" + else + rclone_remote="$OPTARG:" + fi + else + printf "You have not entered a valid remote.\\n" + exit 0 + fi + ;; + v) + check_variable video ${OPTARG,,} + if [ $video_codec = "null" ] + then + printf "You have not entered a supported video codec.\\n" + exit 0 + fi + ;; + \?) + 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 encode -l /path/to/list.txt [flags]\\n\\nFlags:\\n -a Audio codec. Default = $audio_codec\\n -l List location. Default = $list_file\\n -p FFMpeg preset. Default = $ffmpeg_preset\\n -r RClone remote. Use this for RClone integration\\n -v Video codec. Default = $video_codec\\n" + exit 0 + fi + if [ ! -z "$list_file" ] + then + if [ $dependency_ffmpeg = true ] + then + func_encode + else + printf "\\e[31mPlease install ffmpeg to use this command\\e[0m\\n" + exit 0 + fi + else + printf "You must specify a list file.\\n" + fi + shift $((OPTIND -1)) + ;; + help) + func_help + ;; + install) + func_install + shift $((OPTIND -1)) + ;; + list) + while getopts ":a:d:l:v:" opt; do + case $opt in + a) + check_variable audio ${OPTARG,,} + if [ $audio_codec = "null" ] + then + printf "You have not entered a supported audio codec.\\n" + exit 0 + fi + ;; + 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) + check_variable video ${OPTARG,,} + if [ $video_codec = "null" ] + then + printf "You have not entered a supported video codec.\\n" + exit 0 + fi + ;; + \?) + printf "Invalid option: -$OPTARG.\\n" + exit 1 + ;; + :) + printf "Option -$OPTARG requires an argument.\\n" + exit 1 + ;; + esac + done + if [ $OPTIND -eq 1 ] + then + printf "\\e[39mUsage:\\n plexus list -d /path/to/media [flags]\\n\\nFlags:\\n -a Audio codec. Default = $audio_codec\\n -d Media directory. Default = $media_dir\\n -l List location. Default = $list_file\\n -v Video codec. Default = $video_codec\\n" + exit 0 + fi + func_list + shift $((OPTIND -1)) + ;; + mount) + if [ $dependency_fuse = true ] + then + func_mount + shift $((OPTIND -1)) + else + printf "\\e[31mPlease install fuse to use this command\\e[0m\\n" + exit 0 + fi + ;; + unmount) + if [ $dependency_fuse = true ] + then + func_unmount + shift $((OPTIND -1)) + else + printf "\\e[31mPlease install fuse to use this command\\e[0m\\n" + exit 0 + fi + ;; + *) + printf "This is not a valid command.\\nSee 'plexus help' for more information.\\n" + exit 0 + ;; +esac +### COMMAND HANDLER ### + +main "$@" diff --git a/docs/versions/releases/v0.8/plexus.conf b/docs/versions/releases/v0.8/plexus.conf new file mode 100644 index 0000000..240e7c1 --- /dev/null +++ b/docs/versions/releases/v0.8/plexus.conf @@ -0,0 +1,10 @@ +audio_codec="aac" +convert_dir="$HOME/.plexus/encode/convert" +converted_dir="$HOME/.plexus/encode/converted" +ffmpeg_preset="faster" +list_file="$HOME/.plexus/list.txt" +media_dir="/mnt/plexdrive" +rclone_cache="Cache:" +rclone_remote="GDrive:" +video_codec="h264" +video_library="libx264" diff --git a/plexus b/plexus index 552727b..ba15b0e 100644 --- a/plexus +++ b/plexus @@ -1,13 +1,36 @@ #!/usr/bin/env bash -HEADER_TEXT="\\e[93m=== Plexus v0.7.3d - Developed by Robert Thomas ===\\n" +HEADER_TEXT="\\e[93m=== Plexus v0.8 - Developed by Robert Thomas ===\\n" HEADER_SUBTEXT="\\e[93m=== https://github.com/Wolveix/Plexus ===\\n" set -e if [ -f "$HOME"/.config/plexus/plexus.conf ] then source "$HOME"/.config/plexus/plexus.conf else - printf "A config file could not be found. Please reinstall Plexus.\\n" - exit 0 + mkdir -p "$HOME"/.config/plexus/ + curl -O https://robt.me/plexus.conf 2>/dev/null + mv plexus.conf "$HOME"/.config/plexus/ + printf "\\e[32mA config file could not be found. The default file has been downloaded.\\n" +fi + +if [ $(dpkg-query -W -f='${Status}' ffmpeg 2>/dev/null | grep -c "ok installed") -eq 1 ] +then + dependency_ffmpeg=true +else + dependency_ffmpeg=false +fi + +if [ $(dpkg-query -W -f='${Status}' fuse 2>/dev/null | grep -c "ok installed") -eq 1 ] +then + dependency_fuse=true +else + dependency_fuse=false +fi + +if [ -f "$HOME/.config/rclone/rclone.conf" ] +then + dependency_rclone=true +else + dependency_rclone=false fi function main () { @@ -84,7 +107,7 @@ function check_variable { esac ;; *) - printf "\\nAn unexpected error has occurred." + printf "\\e[31m\\nAn unexpected error has occurred.\\e[0m\\n" exit 0 ;; esac @@ -95,7 +118,7 @@ function func_about { } function func_config { - printf "Use this tool to set the default values without modifying the config file directly.\\n\\n1. Set audio codec\\n2. Set convert directory\\n3. Set converted directory\\n4. Set ffmpeg preset\\n5. Set list file location\\n6. Set media directory\\n7. Set video codec\\n0. Exit\\n\\n" + printf "Use this tool to set the default values without modifying the config file directly.\\n\\n1. Set audio codec\\n2. Set convert directory\\n3. Set converted directory\\n4. Set ffmpeg preset\\n5. Set list file location\\n6. Set media directory\\n7. Set video codec\\n8. Set RClone remote\\n9. Set RClone cache\\n0. Exit\\n\\n" answer="waiting" while [ ! -z $answer ] do @@ -250,7 +273,6 @@ function func_config { do video_codec="null" read -r -p '' answer - check_variable video "$answer" while [ $video_codec = "null" ] do printf "\\nYou have not entered a supported codec.\\n" @@ -266,6 +288,47 @@ function func_config { exit 0 done ;; + "8") + printf "\\n\\nEnter the desired RClone remote: " + answer="waiting" + while [ ! -z $answer ] + do + read -r -p '' answer + + if [ "${answer: -1}" == ":" ] + then + rclone_remote="$answer" + sed -i '/rclone_remote/d' "$HOME"/.config/plexus/plexus.conf + echo rclone_remote=\"$rclone_remote\" >> "$HOME"/.config/plexus/plexus.conf + else + rclone_remote="$answer:" + sed -i '/rclone_remote/d' "$HOME"/.config/plexus/plexus.conf + echo rclone_remote=\"$rclone_remote\" >> "$HOME"/.config/plexus/plexus.conf + fi + printf "\\nRClone remote successfully changed.\\n" + exit 0 + done + ;; + "9") + printf "\\n\\nEnter the desired RClone cache: " + answer="waiting" + while [ ! -z $answer ] + do + read -r -p '' answer + if [ "${answer: -1}" == ":" ] + then + rclone_cache="$answer" + sed -i '/rclone_remote/d' "$HOME"/.config/plexus/plexus.conf + echo rclone_remote=\"$rclone_remote\" >> "$HOME"/.config/plexus/plexus.conf + else + rclone_cache="$answer:" + sed -i '/rclone_cache/d' "$HOME"/.config/plexus/plexus.conf + echo rclone_cache=\"$rclone_remote\" >> "$HOME"/.config/plexus/plexus.conf + fi + printf "\\nRClone cache successfully changed.\\n" + exit 0 + done + ;; "0") printf "\\nYou can find the config file here: $HOME/.config/plexus/plexus.conf\\n" exit 4 @@ -284,11 +347,17 @@ function func_encode { NAME=${FILE%.*} if [ ! -z "$rclone_remote" ] then - printf "\\nDownloading: $FILE\\n" - /usr/bin/rclone copy "$rclone_remote$line" "$convert_dir" --stats-log-level NOTICE --stats 30s - printf "\\nFile downloaded." + if [ "$dependency_rclone" = true ] + then + printf "Downloading: $FILE\\n" + /usr/bin/rclone copy "$rclone_remote$line" "$convert_dir" --stats-log-level NOTICE --stats 30s + printf "\\nFile downloaded." + else + printf "\\e[31mPlease install RClone to use an RClone remote with this command\\e[0m\\n" + exit 0 + fi else - printf "\\nCopying: $FILE" + printf "Copying: $FILE" /bin/cp "$line" "$convert_dir" printf "\\nFile copied." fi @@ -305,23 +374,23 @@ function func_encode { then if [ "$file_audio_codec" != "$audio_codec" ] then - /usr/bin/ffmpeg -i "$convert_dir/$FILE" -c:v copy -c:a "$audio_codec" -q:a 100 -preset "$ffmpeg_preset" -strict -2 -movflags faststart -threads 2 -nostdin -loglevel quiet -stats "$converted_dir/$NAME.mkv" + /usr/bin/ffmpeg -i "$convert_dir/$FILE" -map 0 -c:v copy -c:a "$audio_codec" -q:a 100 -preset "$ffmpeg_preset" -strict -2 -movflags faststart -threads 2 -nostdin -loglevel quiet -stats "$converted_dir/$NAME.mkv" fi else if [ "$file_audio_codec" == "$audio_codec" ] then if [ "$video_codec" == "h264" ] then - /usr/bin/ffmpeg -i "$convert_dir/$FILE" -c:v "$video_library" -crf 18 -level 4.1 -profile:v high -c:a copy -q:a 100 -preset "$ffmpeg_preset" -strict -2 -movflags faststart -threads 2 -nostdin -loglevel quiet -stats "$converted_dir/$NAME.mkv" + /usr/bin/ffmpeg -i "$convert_dir/$FILE" -map 0 -c:v "$video_library" -crf 20 -level 4.1 -profile:v high -c:a copy -q:a 100 -preset "$ffmpeg_preset" -strict -2 -movflags faststart -threads 2 -nostdin -loglevel quiet -stats "$converted_dir/$NAME.mkv" else - /usr/bin/ffmpeg -i "$convert_dir/$FILE" -c:v "$video_library" -c:a copy -q:a 100 -preset "$ffmpeg_preset" -strict -2 -movflags faststart -threads 2 -nostdin -loglevel quiet -stats "$converted_dir/$NAME.mkv" + /usr/bin/ffmpeg -i "$convert_dir/$FILE" -map 0 -c:v "$video_library" -c:a copy -q:a 100 -preset "$ffmpeg_preset" -strict -2 -movflags faststart -threads 2 -nostdin -loglevel quiet -stats "$converted_dir/$NAME.mkv" fi else if [ "$video_codec" == "h264" ] then - /usr/bin/ffmpeg -i "$convert_dir/$FILE" -c:v "$video_library" -crf 18 -level 4.1 -profile:v high -c:a "$audio_codec" -q:a 100 -preset "$ffmpeg_preset" -strict -2 -movflags faststart -threads 2 -nostdin -loglevel quiet -stats "$converted_dir/$NAME.mkv" + /usr/bin/ffmpeg -i "$convert_dir/$FILE" -map 0 -c:v "$video_library" -crf 20 -level 4.1 -profile:v high -c:a "$audio_codec" -q:a 100 -preset "$ffmpeg_preset" -strict -2 -movflags faststart -threads 2 -nostdin -loglevel quiet -stats "$converted_dir/$NAME.mkv" else - /usr/bin/ffmpeg -i "$convert_dir/$FILE" -c:v "$video_library" -c:a "$audio_codec" -q:a 100 -preset "$ffmpeg_preset" -strict -2 -movflags faststart -threads 2 -nostdin -loglevel quiet -stats "$converted_dir/$NAME.mkv" + /usr/bin/ffmpeg -i "$convert_dir/$FILE" -map 0 -c:v "$video_library" -c:a "$audio_codec" -q:a 100 -preset "$ffmpeg_preset" -strict -2 -movflags faststart -threads 2 -nostdin -loglevel quiet -stats "$converted_dir/$NAME.mkv" fi fi fi @@ -348,7 +417,107 @@ function func_encode { } function func_help { - printf "$HEADER_TEXT\\n\\e[37mUsage:\\n plexus [flags]\\n plexus [command]\\n\\nAvailable Commands:\\n about Learn more about the program\\n config Change the default variable values\\n encode Begin processing the encode queue\\n help Displays a list of available commands\\n list Build a .txt file containing media with incorrect codecs\\n" + printf "$HEADER_TEXT\\n\\e[37mUsage:\\n plexus [flags]\\n plexus [command]\\n\\nAvailable Commands:\\n about Learn more about the program\\n config Change the default variable values\\n encode Begin processing the encode queue\\n help Displays a list of available commands\\n install Reinstall Plexus or install any missing dependencies\\n list Build a .txt file containing media with incorrect codecs\\n mount Mount an RClone remote or cache, set from the config function\\n unmount Unmount an RClone remote or cache, set from the config function\\n" +} + +function func_install { + printf "\\e[33mWhat would you like to do?\\e[33m\\n\\e[0m\\n1 - Install missing dependencies\\n2 - Reinstall/Update Plexus\\n0 - Exit\\n" + answer="waiting" + while [ ! -z $answer ] + do + read -r -n 1 -p '' answer + case $answer in + "1") + printf "\\n\\nWhich dependency?\\n1 - All\\n2 - FFmpeg\\n3 - Fuse\\n4 - RClone\\n" + answer="waiting" + while [ ! -z $answer ] + do + read -r -n 1 -p '' answer + case $answer in + "1") + printf "\\n\\e[36mInstalling all dependencies.\\e[0m\\n\\n" + apt-get install curl ffmpeg fuse unzip -y -qq + case $(curl https://rclone.org/install.sh 2>/dev/null | sudo bash -s beta) in + 0) + printf "\\e[36mIf you haven't already, setup an RClone remote via 'rclone config'\\e[0m\\n" + printf "\\e[32mAll dependencies have been installed!\\e[0m\\n" + exit 0 + ;; + 2) + printf "\\e[31mYour operating system is not supported by RClone.\\e[0m\\n" + printf "\\e[32mFFmpeg and Fuse have been installed!\\e[0m\\n" + exit 0 + ;; + 3) + printf "\\e[36mRClone is already up-to-date!\\e[0m\\n" + printf "\\e[32mFFmpeg and Fuse have been installed!\\e[0m\\n" + exit 0 + ;; + *) + printf "\\e[36mIf you haven't already, setup an RClone remote via 'rclone config'\\e[0m\\n" + printf "\\e[32mAll dependencies have been installed!\\e[0m\\n" + exit 0 + esac + exit 0 + ;; + "2") + printf "\\n\\e[36mInstalling FFmpeg.\\n\\n\\e[0m" + apt-get install ffmpeg -y -qq + printf "\\e[32mFFmpeg has been installed!\\e[0m\\n" + exit 0 + ;; + "3") + printf "\\n\\e[36mInstalling Fuse.\\n\\n\\e[0m" + apt-get install fuse -y -qq + printf "\\e[32mFuse has been installed!\\e[0m\\n" + exit 0 + ;; + "4") + printf "\\n\\e[36mInstalling RClone.\\n\\n\\e[0m" + apt-get install curl unzip -y -qq + case $(curl https://rclone.org/install.sh 2>/dev/null | sudo bash -s beta) in + 0) + printf "\\e[36mIf you haven't already, setup an RClone remote via 'rclone config'\\e[0m\\n" + printf "\\e[32mRClone has been installed!\\e[0m\\n" + exit 0 + ;; + 2) + printf "\\e[31mYour operating system is not supported by RClone.\\e[0m\\n" + exit 0 + ;; + 3) + printf "\\e[36mRClone is already up-to-date!\\e[0m\\n" + exit 0 + ;; + *) + printf "\\e[36mIf you haven't already, setup an RClone remote via 'rclone config'\\e[0m\\n" + printf "\\e[32mRClone has been installed!\\e[0m\\n" + exit 0 + esac + ;; + "0") + exit 0 + ;; + *) + printf "\\n\\nPlease enter a valid menu option. Enter 0 to exit.\\e[0m\\n" + ;; + esac + done + ;; + "2") + printf "\\n\\nThis won't clear your current config file ($HOME/.config/plexus/plexus.conf).\\n" + curl https://plexus.robt.me/install.sh | sudo bash + exit 0 + ;; + "0") + printf "\\n\\nYou can find the config file here: $HOME/.config/plexus/plexus.conf\\n" + exit 0 + ;; + *) + printf "\\n\\nPlease enter a valid menu option. Enter 0 to exit.\\n" + ;; + esac + done } function func_list { @@ -396,6 +565,36 @@ function func_list { printf "\\e[32mScan complete! Run plexus encode to process the list.\\n\\e[0m" } +function func_mount { + if [ -z $rclone_remote ] + then + if [ -z $rclone_cache ] + then + printf "\\e[36mMounting RClone cache to $media_dir\\n\\e[0m" + /usr/bin/rclone mount $rclone_cache $media_dir --allow-other --buffer-size 512M --dir-cache-time 72h --drive-chunk-size 32M --fast-list --poll-interval 10m --vfs-read-chunk-size 128M --vfs-read-chunk-size-limit off & + find /mnt/plexus -type f + printf "\\n\\e[32mThe RClone remote has successfully been mounted!\\n\\e[0m" + else + printf "\\e[36mMounting RClone remote to $media_dir\\n\\e[0m" + /usr/bin/rclone mount $rclone_remote $media_dir --allow-other & + printf "\\n\\e[32mThe RClone remote has successfully been mounted!\\n\\e[0m" + fi + else + printf "\\e[32mPlease specify the RClone remote (option: cache) via the config function\\n\\e[0m" + fi +} + +function func_unmount { + if [ -d "$media_dir" ] + then + printf "\\e[36mUnmounting RClone remote from $media_dir\\n\\e[0m" + fusermount -uz "$media_dir" + printf "\\n\\e[32mThe RClone remote has successfully been unmounted!\\n\\e[0m" + else + printf "\\e[31mThe directory does not exist.\\e[0m\\n" + fi +} + ### COMMAND HANDLER ### while getopts ":ah" opt; do case ${opt} in @@ -459,8 +658,8 @@ case "$command" in fi ;; r) - /usr/bin/rclone listremotes > /tmp/plexus/rclone/remotes.txt - if [ ! -z $(grep "$OPTARG" "/tmp/plexus/rclone/remotes.txt") ] + /usr/bin/rclone listremotes > $HOME/.plexus/rclone/remotes.txt + if [ ! -z $(grep "$OPTARG" "$HOME/.plexus/rclone/remotes.txt") ] then if [ "${OPTARG: -1}" == ":" ] then @@ -498,7 +697,13 @@ case "$command" in fi if [ ! -z "$list_file" ] then - func_encode + if [ $dependency_ffmpeg = true ] + then + func_encode + else + printf "\\e[31mPlease install ffmpeg to use this command\\e[0m\\n" + exit 0 + fi else printf "You must specify a list file.\\n" fi @@ -507,6 +712,10 @@ case "$command" in help) func_help ;; + install) + func_install + shift $((OPTIND -1)) + ;; list) while getopts ":a:d:l:v:" opt; do case $opt in @@ -568,6 +777,26 @@ case "$command" in func_list shift $((OPTIND -1)) ;; + mount) + if [ $dependency_fuse = true ] + then + func_mount + shift $((OPTIND -1)) + else + printf "\\e[31mPlease install fuse to use this command\\e[0m\\n" + exit 0 + fi + ;; + unmount) + if [ $dependency_fuse = true ] + then + func_unmount + shift $((OPTIND -1)) + else + printf "\\e[31mPlease install fuse to use this command\\e[0m\\n" + exit 0 + fi + ;; *) printf "This is not a valid command.\\nSee 'plexus help' for more information.\\n" exit 0 diff --git a/plexus.conf b/plexus.conf index ea9f845..240e7c1 100644 --- a/plexus.conf +++ b/plexus.conf @@ -1,8 +1,10 @@ audio_codec="aac" -convert_dir="/tmp/plexus/encode/convert" -converted_dir="/tmp/plexus/encode/converted" +convert_dir="$HOME/.plexus/encode/convert" +converted_dir="$HOME/.plexus/encode/converted" ffmpeg_preset="faster" -list_file="/tmp/plexus/list.txt" +list_file="$HOME/.plexus/list.txt" media_dir="/mnt/plexdrive" +rclone_cache="Cache:" +rclone_remote="GDrive:" video_codec="h264" video_library="libx264"