#!/bin/bash skipfile () { echo echo "------------- FILE -------------" echo -en '\t\t' echo $1 echo "--------------------------------" echo "Press n to skip" echo "Press y to continue" echo "Press x/q to exit the script" read -n 1 -p "Input Selection:" "mainmenuinput" echo if [ "$mainmenuinput" = "n" ];then skip=1 elif [ "$mainmenuinput" = "y" ];then skip=0 elif [ "$mainmenuinput" = "x" ];then exit elif [ "$mainmenuinput" = "q" ];then exit else echo "You have entered an invallid selection!" echo "Please try again!" echo "" echo "Press any key to continue..." read -n 1 clear mainmenu fi } mainmenu () { #echo "-- $1" basename=$1 directory=$2 extension=$3 newname=$4 echo "Press y to accept format" #echo "Press e to accept and set extended" #echo "Press t to accept and set theatrical" echo "Press n to skip" echo "Press x/q to exit the script" read -n 1 -p "Input Selection:" "mainmenuinput" echo if [ "$mainmenuinput" = "y" ]; then mv "$directory/$basename.$extension" "$directory/$newname.$extension" #elif [ "$mainmenuinput" = "e" ]; then # echo "extended" #elif [ "$mainmenuinput" = "t" ]; then # echo "theatrical" elif [ "$mainmenuinput" = "n" ];then echo "Skipping - $filename" elif [ "$mainmenuinput" = "x" ];then exit elif [ "$mainmenuinput" = "q" ];then exit else echo "You have entered an invallid selection!" echo "Please try again!" echo "" echo "Press any key to continue..." read -n 1 clear mainmenu fi } convertsecs() { h=$(bc <<< "${1}/3600") m=$(bc <<< "(${1}%3600)/60") s=$(bc <<< "${1}%60") printf "%02dh %02dm %02ds" $h $m $s echo " - $(($h*60+$m))m" } path="../../Videos/Movies/" list="" IFS=$'\n' for filex in "`find ../../Videos/Movies/[A-Z]* -maxdepth 1 -type f -regex '.*/.*\.\(m4v\|avi\|mkv\|mp4\)'`"; do list=$filex done for file in $list; do filename=$(echo -e `basename "$file"`) bsn="${filename%.*}" extension="${filename##*.}" directory="${file%/*.*}" skipfile "$filename" if [[ $skip -eq 1 ]]; then echo "Skipping - $filename" skip=0 else json=$(ffprobe -v quiet -print_format json -show_format -show_streams "$directory/$filename") codexName=$(echo $json | jq -r '.streams[0].codec_name') audioChannel=$(echo $json | jq -r '.streams[1].channel_layout') audioCodec=$(echo $json | jq -r '.streams[1].codec_name') resolutionW=$(echo $json | jq -r '.streams[0].width') resolutionH=$(echo $json | jq -r '.streams[0].height') duration=$(echo $json | jq -r '.format.duration') resu=" " if [[ $resolutionW -gt 1500 ]]; then if [[ $resolutionW -gt 3000 ]]; then resu="2160p" fi if [[ $resolutionW -lt 2000 ]]; then resu="1080p" fi elif [[ $resolutionW -gt 1000 ]]; then resu="720p" elif [[ $resolutionW -gt 800 ]]; then resu="480p" elif [[ $resolutionW -gt 400 ]]; then resu="DVD-360p" elif [[ $resolutionW -gt 300 ]]; then resu="240p" fi formats=("352 x 240" "480 x 360" "858 x 480" "1280 x 720" "1920 x 1080" "3860 x 2160") resolutions=("240p" "DVD-360p" "480p" "720p" "1080p" "2160p") echo echo "------------ FORMAT ------------" for i in {0..5}; do if [ "$resu" = "${resolutions[$i]}" ];then echo "${resolutions[$i]} = ${formats[$i]} ------> $resolutionW x $resolutionH" else echo "${resolutions[$i]} = ${formats[$i]}" fi done newname=$(echo "$bsn - [$resu][$audioCodec $audioChannel][$codexName]") echo "------------ INFO --------------" echo -en '\t\t' echo $directory echo echo -en '\t\t' echo "[$resu][$audioCodec $audioChannel][$codexName]" echo echo -en '\t\t' convertsecs "${duration%.*}" echo echo -en '\t\t' echo "$newname.$extension" echo "--------------------------------" mainmenu "$bsn" "$directory" "$extension" "$newname" fi done exit