Better indent in source code

This commit is contained in:
q3aql 2021-03-28 01:56:41 +01:00
parent d13e30f881
commit 5247cac8a3
14 changed files with 4677 additions and 4677 deletions

View File

@ -22,33 +22,33 @@ function convertCygwin() {
echo "${wordToConvert}" > ${CygPathSedFile} echo "${wordToConvert}" > ${CygPathSedFile}
# Apply changes # Apply changes
sed -i 's/\\/\//g' "${CygPathSedFile}" &> /dev/null sed -i 's/\\/\//g' "${CygPathSedFile}" &> /dev/null
sed -i 's/A:/\/cygdrive\/a/g' "${CygPathSedFile}" &> /dev/null sed -i 's/A:/\/cygdrive\/a/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/B:/\/cygdrive\/b/g' "${CygPathSedFile}" &> /dev/null sed -i 's/B:/\/cygdrive\/b/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/C:/\/cygdrive\/c/g' "${CygPathSedFile}" &> /dev/null sed -i 's/C:/\/cygdrive\/c/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/D:/\/cygdrive\/d/g' "${CygPathSedFile}" &> /dev/null sed -i 's/D:/\/cygdrive\/d/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/E:/\/cygdrive\/e/g' "${CygPathSedFile}" &> /dev/null sed -i 's/E:/\/cygdrive\/e/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/F:/\/cygdrive\/f/g' "${CygPathSedFile}" &> /dev/null sed -i 's/F:/\/cygdrive\/f/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/G:/\/cygdrive\/g/g' "${CygPathSedFile}" &> /dev/null sed -i 's/G:/\/cygdrive\/g/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/H:/\/cygdrive\/h/g' "${CygPathSedFile}" &> /dev/null sed -i 's/H:/\/cygdrive\/h/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/I:/\/cygdrive\/i/g' "${CygPathSedFile}" &> /dev/null sed -i 's/I:/\/cygdrive\/i/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/J:/\/cygdrive\/j/g' "${CygPathSedFile}" &> /dev/null sed -i 's/J:/\/cygdrive\/j/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/K:/\/cygdrive\/k/g' "${CygPathSedFile}" &> /dev/null sed -i 's/K:/\/cygdrive\/k/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/L:/\/cygdrive\/l/g' "${CygPathSedFile}" &> /dev/null sed -i 's/L:/\/cygdrive\/l/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/M:/\/cygdrive\/m/g' "${CygPathSedFile}" &> /dev/null sed -i 's/M:/\/cygdrive\/m/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/N:/\/cygdrive\/n/g' "${CygPathSedFile}" &> /dev/null sed -i 's/N:/\/cygdrive\/n/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/O:/\/cygdrive\/o/g' "${CygPathSedFile}" &> /dev/null sed -i 's/O:/\/cygdrive\/o/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/P:/\/cygdrive\/p/g' "${CygPathSedFile}" &> /dev/null sed -i 's/P:/\/cygdrive\/p/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/Q:/\/cygdrive\/q/g' "${CygPathSedFile}" &> /dev/null sed -i 's/Q:/\/cygdrive\/q/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/R:/\/cygdrive\/r/g' "${CygPathSedFile}" &> /dev/null sed -i 's/R:/\/cygdrive\/r/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/S:/\/cygdrive\/s/g' "${CygPathSedFile}" &> /dev/null sed -i 's/S:/\/cygdrive\/s/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/T:/\/cygdrive\/t/g' "${CygPathSedFile}" &> /dev/null sed -i 's/T:/\/cygdrive\/t/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/U:/\/cygdrive\/u/g' "${CygPathSedFile}" &> /dev/null sed -i 's/U:/\/cygdrive\/u/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/V:/\/cygdrive\/v/g' "${CygPathSedFile}" &> /dev/null sed -i 's/V:/\/cygdrive\/v/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/W:/\/cygdrive\/w/g' "${CygPathSedFile}" &> /dev/null sed -i 's/W:/\/cygdrive\/w/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/X:/\/cygdrive\/x/g' "${CygPathSedFile}" &> /dev/null sed -i 's/X:/\/cygdrive\/x/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/Y:/\/cygdrive\/y/g' "${CygPathSedFile}" &> /dev/null sed -i 's/Y:/\/cygdrive\/y/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/Z:/\/cygdrive\/z/g' "${CygPathSedFile}" &> /dev/null sed -i 's/Z:/\/cygdrive\/z/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/\/ / /g' "${CygPathSedFile}" &> /dev/null sed -i 's/\/ / /g' "${CygPathSedFile}" &> /dev/null
# Show file without extension # Show file without extension
wordToConvert=$(cat ${CygPathSedFile}) wordToConvert=$(cat ${CygPathSedFile})
echo "\"${wordToConvert}\"" echo "\"${wordToConvert}\""
@ -62,33 +62,33 @@ function convertWindows() {
mkdir -p ${CygPathTempFolder} && chmod 777 -R ${CygPathTempFolder} 2> /dev/null mkdir -p ${CygPathTempFolder} && chmod 777 -R ${CygPathTempFolder} 2> /dev/null
echo "${wordToConvert}" > ${CygPathSedFile} echo "${wordToConvert}" > ${CygPathSedFile}
# Apply changes # Apply changes
sed -i 's/\/cygdrive\/a/A:/g' "${CygPathSedFile}" &> /dev/null sed -i 's/\/cygdrive\/a/A:/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/\/cygdrive\/b/B:/g' "${CygPathSedFile}" &> /dev/null sed -i 's/\/cygdrive\/b/B:/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/\/cygdrive\/c/C:/g' "${CygPathSedFile}" &> /dev/null sed -i 's/\/cygdrive\/c/C:/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/\/cygdrive\/d/D:/g' "${CygPathSedFile}" &> /dev/null sed -i 's/\/cygdrive\/d/D:/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/\/cygdrive\/e/E:/g' "${CygPathSedFile}" &> /dev/null sed -i 's/\/cygdrive\/e/E:/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/\/cygdrive\/f/F:/g' "${CygPathSedFile}" &> /dev/null sed -i 's/\/cygdrive\/f/F:/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/\/cygdrive\/g/G:/g' "${CygPathSedFile}" &> /dev/null sed -i 's/\/cygdrive\/g/G:/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/\/cygdrive\/h/H:/g' "${CygPathSedFile}" &> /dev/null sed -i 's/\/cygdrive\/h/H:/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/\/cygdrive\/i/I:/g' "${CygPathSedFile}" &> /dev/null sed -i 's/\/cygdrive\/i/I:/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/\/cygdrive\/j/J:/g' "${CygPathSedFile}" &> /dev/null sed -i 's/\/cygdrive\/j/J:/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/\/cygdrive\/k/K:/g' "${CygPathSedFile}" &> /dev/null sed -i 's/\/cygdrive\/k/K:/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/\/cygdrive\/l/L:/g' "${CygPathSedFile}" &> /dev/null sed -i 's/\/cygdrive\/l/L:/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/\/cygdrive\/m/M:/g' "${CygPathSedFile}" &> /dev/null sed -i 's/\/cygdrive\/m/M:/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/\/cygdrive\/n/N:/g' "${CygPathSedFile}" &> /dev/null sed -i 's/\/cygdrive\/n/N:/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/\/cygdrive\/o/O:/g' "${CygPathSedFile}" &> /dev/null sed -i 's/\/cygdrive\/o/O:/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/\/cygdrive\/p/P:/g' "${CygPathSedFile}" &> /dev/null sed -i 's/\/cygdrive\/p/P:/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/\/cygdrive\/q/Q:/g' "${CygPathSedFile}" &> /dev/null sed -i 's/\/cygdrive\/q/Q:/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/\/cygdrive\/r/R:/g' "${CygPathSedFile}" &> /dev/null sed -i 's/\/cygdrive\/r/R:/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/\/cygdrive\/s/S:/g' "${CygPathSedFile}" &> /dev/null sed -i 's/\/cygdrive\/s/S:/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/\/cygdrive\/t/T:/g' "${CygPathSedFile}" &> /dev/null sed -i 's/\/cygdrive\/t/T:/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/\/cygdrive\/u/U:/g' "${CygPathSedFile}" &> /dev/null sed -i 's/\/cygdrive\/u/U:/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/\/cygdrive\/v/V:/g' "${CygPathSedFile}" &> /dev/null sed -i 's/\/cygdrive\/v/V:/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/\/cygdrive\/w/W:/g' "${CygPathSedFile}" &> /dev/null sed -i 's/\/cygdrive\/w/W:/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/\/cygdrive\/y/Y:/g' "${CygPathSedFile}" &> /dev/null sed -i 's/\/cygdrive\/y/Y:/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/\/cygdrive\/z/Z:/g' "${CygPathSedFile}" &> /dev/null sed -i 's/\/cygdrive\/z/Z:/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/\//\\/g' "${CygPathSedFile}" &> /dev/null sed -i 's/\//\\/g' "${CygPathSedFile}" &> /dev/null
sed -i 's/\\ / /g' "${CygPathSedFile}" &> /dev/null sed -i 's/\\ / /g' "${CygPathSedFile}" &> /dev/null
# Show file without extension # Show file without extension
wordToConvert=$(cat ${CygPathSedFile}) wordToConvert=$(cat ${CygPathSedFile})
echo "\"${wordToConvert}\"" echo "\"${wordToConvert}\""
@ -100,40 +100,40 @@ if [ -z "${1}" ] ; then
echo "* cygwin-path v${VERSION} (${M_DATE})" echo "* cygwin-path v${VERSION} (${M_DATE})"
echo "" echo ""
echo "* Convert Windows paths in Cywin paths & vice versa" echo "* Convert Windows paths in Cywin paths & vice versa"
echo "" echo ""
echo "+ Sintax: " echo "+ Sintax: "
echo "" echo ""
echo " $ cygwin-path -c \"<Windows path>\" --> Convert Windows path to Cygwin path" echo " $ cygwin-path -c \"<Windows path>\" --> Convert Windows path to Cygwin path"
echo " $ cygwin-path -w \"<Cygwin path>\" --> Convert Cygwin path to Windows path" echo " $ cygwin-path -w \"<Cygwin path>\" --> Convert Cygwin path to Windows path"
echo "" echo ""
echo "+ Examples: " echo "+ Examples: "
echo "" echo ""
echo " $ cygwin-path -c \"C:\\Users\\test\Desktop\\my-notes.txt\"" echo " $ cygwin-path -c \"C:\\Users\\test\Desktop\\my-notes.txt\""
echo " $ cygwin-path -w \"/cygdrive/c/Users/test/Desktop/my-notes.txt\"" echo " $ cygwin-path -w \"/cygdrive/c/Users/test/Desktop/my-notes.txt\""
echo "" echo ""
exit exit
else else
if [ "${1}" == "-c" ] ; then if [ "${1}" == "-c" ] ; then
convertCygwin "${2}" convertCygwin "${2}"
elif [ "${1}" == "-w" ] ; then elif [ "${1}" == "-w" ] ; then
convertWindows "${2}" convertWindows "${2}"
else else
# Show help if sintax is wrong # Show help if sintax is wrong
echo "" echo ""
echo "* cygwin-path v${VERSION} (${M_DATE})" echo "* cygwin-path v${VERSION} (${M_DATE})"
echo "" echo ""
echo "* Convert Windows paths in Cywin paths & vice versa" echo "* Convert Windows paths in Cywin paths & vice versa"
echo "" echo ""
echo "+ Sintax: " echo "+ Sintax: "
echo "" echo ""
echo " $ cygwin-path -c \"<Windows path>\" --> Convert Windows path to Cygwin path" echo " $ cygwin-path -c \"<Windows path>\" --> Convert Windows path to Cygwin path"
echo " $ cygwin-path -w \"<Cygwin path>\" --> Convert Cygwin path to Windows path" echo " $ cygwin-path -w \"<Cygwin path>\" --> Convert Cygwin path to Windows path"
echo "" echo ""
echo "+ Examples: " echo "+ Examples: "
echo "" echo ""
echo " $ cygwin-path -c \"C:\\Users\\test\Desktop\\my-notes.txt\"" echo " $ cygwin-path -c \"C:\\Users\\test\Desktop\\my-notes.txt\""
echo " $ cygwin-path -w \"/cygdrive/c/Users/test/Desktop/my-notes.txt\"" echo " $ cygwin-path -w \"/cygdrive/c/Users/test/Desktop/my-notes.txt\""
echo "" echo ""
exit exit
fi fi
fi fi

View File

@ -41,96 +41,96 @@ fi
ffmpeg_test=$(ffmpeg --help 2>&1) ffmpeg_test=$(ffmpeg --help 2>&1)
error_ffmpeg=$? error_ffmpeg=$?
if [ ${error_ffmpeg} -ne 0 ] ; then if [ ${error_ffmpeg} -ne 0 ] ; then
echo "" echo ""
echo "* ks-crop (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-crop (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "+ The 'ffmpeg' tool is not installed!" echo "+ The 'ffmpeg' tool is not installed!"
echo "" echo ""
exit exit
fi fi
# Function to remove extension from file # Function to remove extension from file
# Syntax: removeExtension "<text>" # Syntax: removeExtension "<text>"
function removeExtension() { function removeExtension() {
wordToConvert=${1} wordToConvert=${1}
ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt" ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt"
mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null
echo "${wordToConvert}" > ${ksToolsSedFile} echo "${wordToConvert}" > ${ksToolsSedFile}
# Remove extensions # Remove extensions
sed -i 's/.avi//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.avi//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mp4//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mp4//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mkv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mkv//g' "${ksToolsSedFile}" &> /dev/null
sed -i "s/.mov//g" "${ksToolsSedFile}" &> /dev/null sed -i "s/.mov//g" "${ksToolsSedFile}" &> /dev/null
sed -i 's/.vob//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.vob//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mpg//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mpg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mpeg//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mpeg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.wmv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.wmv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.ogv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.ogv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.webm//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.webm//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.flv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.flv//g' "${ksToolsSedFile}" &> /dev/null
# Show file without extension # Show file without extension
wordToConvert=$(cat ${ksToolsSedFile}) wordToConvert=$(cat ${ksToolsSedFile})
echo ${wordToConvert} echo ${wordToConvert}
} }
# Function to show files with spaces. # Function to show files with spaces.
# Syntax: showFileWithSpace <file number> # Syntax: showFileWithSpace <file number>
function showFileWithSpace() { function showFileWithSpace() {
echo "${1}" > ${dirTemp}/name.tmp echo "${1}" > ${dirTemp}/name.tmp
sed -i 's/_/ /g' ${dirTemp}/name.tmp sed -i 's/_/ /g' ${dirTemp}/name.tmp
DisplayName=$(cat ${dirTemp}/name.tmp) DisplayName=$(cat ${dirTemp}/name.tmp)
rm -rf ${dirTemp}/name.tmp rm -rf ${dirTemp}/name.tmp
echo ${DisplayName} echo ${DisplayName}
} }
# Function to show menu again when syntax is wrong # Function to show menu again when syntax is wrong
function show_menu() { function show_menu() {
echo "" echo ""
echo "* ks-crop (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-crop (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "- Crop or change aspect ratio of a video" echo "- Crop or change aspect ratio of a video"
echo "" echo ""
echo "+ Config:" echo "+ Config:"
echo "" echo ""
echo " - Resolutions: " echo " - Resolutions: "
echo " + ${to4_3} (4:3)" echo " + ${to4_3} (4:3)"
echo " + ${to16_9} (16:9)" echo " + ${to16_9} (16:9)"
echo " + ${to5_4} (5:4)" echo " + ${to5_4} (5:4)"
echo " + ${toImax} (IMAX)" echo " + ${toImax} (IMAX)"
echo " - Video codec: ${vcodec}" echo " - Video codec: ${vcodec}"
echo " - Bitrate video: ${b_vcodec}" echo " - Bitrate video: ${b_vcodec}"
echo " - Preset: ${v_preset}" echo " - Preset: ${v_preset}"
echo " - Audio codec: ${acodec}" echo " - Audio codec: ${acodec}"
echo " - Default Audio: ${default_lang_audio}" echo " - Default Audio: ${default_lang_audio}"
echo " - Container: ${v_ext}" echo " - Container: ${v_ext}"
echo "" echo ""
echo "+ Syntax: " echo "+ Syntax: "
echo "" echo ""
echo " $ ks-crop -16:9-crop <video-file> --> Crop from 4:3/IMAX to 16:9 (1.77:1)" echo " $ ks-crop -16:9-crop <video-file> --> Crop from 4:3/IMAX to 16:9 (1.77:1)"
echo " $ ks-crop -4:3-crop <video-file> --> Crop from 16:9 to 4:3 (1.33:1)" echo " $ ks-crop -4:3-crop <video-file> --> Crop from 16:9 to 4:3 (1.33:1)"
echo " $ ks-crop -5:4-crop <video-file> --> Crop from 16:9 to 5:4 (1.25:1)" echo " $ ks-crop -5:4-crop <video-file> --> Crop from 16:9 to 5:4 (1.25:1)"
echo " $ ks-crop -imax-crop <video-file> --> Crop from 16:9 to IMAX (1.43:1)" echo " $ ks-crop -imax-crop <video-file> --> Crop from 16:9 to IMAX (1.43:1)"
echo "" echo ""
echo " $ ks-crop -16:9-aspect <video-file> --> Change aspect to 16:9 (stretched)" echo " $ ks-crop -16:9-aspect <video-file> --> Change aspect to 16:9 (stretched)"
echo " $ ks-crop -4:3-aspect <video-file> --> Change aspect to 4:3 (stretched)" echo " $ ks-crop -4:3-aspect <video-file> --> Change aspect to 4:3 (stretched)"
echo " $ ks-crop -5:4-aspect <video-file> --> Change aspect to 5:4 (stretched)" echo " $ ks-crop -5:4-aspect <video-file> --> Change aspect to 5:4 (stretched)"
echo "" echo ""
echo " + Examples: " echo " + Examples: "
echo " ks-crop -16:9-crop /data/movies/Example.mkv" echo " ks-crop -16:9-crop /data/movies/Example.mkv"
echo " ks-crop -4:3-aspect /data/movies/Video.avi" echo " ks-crop -4:3-aspect /data/movies/Video.avi"
echo "" echo ""
exit exit
} }
# Function to show error reading file # Function to show error reading file
# Syntax: errorReadingFile <file> # Syntax: errorReadingFile <file>
function errorReadingFile() { function errorReadingFile() {
echo "" echo ""
echo "* ks-crop (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-crop (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "* The file '${1}' does not exist!" echo "* The file '${1}' does not exist!"
echo "" echo ""
exit exit
} }
# Conversion parameters # Conversion parameters
@ -143,33 +143,33 @@ codec_hevc=$(${p_ffmpeg} "${2}" 2>&1 | grep Stream | tr -s " " | grep "Video:" |
yuv420p10le=$(${p_ffmpeg} "${2}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | grep "yuv420p10le") yuv420p10le=$(${p_ffmpeg} "${2}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | grep "yuv420p10le")
codec_h265_hevc="${codec_h265}${codec_hevc}${yuv420p10le}" codec_h265_hevc="${codec_h265}${codec_hevc}${yuv420p10le}"
if [ -z "${codec_h265_hevc}" ] ; then if [ -z "${codec_h265_hevc}" ] ; then
p_conversion="-c:v ${vcodec} -profile:v high -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec}" p_conversion="-c:v ${vcodec} -profile:v high -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec}"
else else
p_conversion="-c:v ${vcodec} -profile:v high -pix_fmt yuv420p -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec}" p_conversion="-c:v ${vcodec} -profile:v high -pix_fmt yuv420p -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec}"
fi fi
# Show menu with bad syntax # Show menu with bad syntax
if [ "${1}" == "-16:9-crop" ] ; then if [ "${1}" == "-16:9-crop" ] ; then
echo > /dev/null echo > /dev/null
elif [ "${1}" == "-4:3-crop" ] ; then elif [ "${1}" == "-4:3-crop" ] ; then
echo > /dev/null echo > /dev/null
elif [ "${1}" == "-5:4-crop" ] ; then elif [ "${1}" == "-5:4-crop" ] ; then
echo > /dev/null echo > /dev/null
elif [ "${1}" == "-imax-crop" ] ; then elif [ "${1}" == "-imax-crop" ] ; then
echo > /dev/null echo > /dev/null
elif [ "${1}" == "-16:9-aspect" ] ; then elif [ "${1}" == "-16:9-aspect" ] ; then
echo > /dev/null echo > /dev/null
elif [ "${1}" == "-4:3-aspect" ] ; then elif [ "${1}" == "-4:3-aspect" ] ; then
echo > /dev/null echo > /dev/null
elif [ "${1}" == "-5:4-aspect" ] ; then elif [ "${1}" == "-5:4-aspect" ] ; then
echo > /dev/null echo > /dev/null
else else
show_menu show_menu
fi fi
if [ -f "${2}" ] ; then if [ -f "${2}" ] ; then
echo "detected" > /dev/null echo "detected" > /dev/null
else else
errorReadingFile "${2}" errorReadingFile "${2}"
fi fi
# Detect resolution of video file # Detect resolution of video file
@ -187,345 +187,345 @@ expr ${calculate_crop} + 1 &> /tmp/ks-tools.error
ih_error="$?" ih_error="$?"
if [ ${ih_error} -eq 0 ] ; then if [ ${ih_error} -eq 0 ] ; then
ih_size="${calculate_crop}" ih_size="${calculate_crop}"
else else
ih_size="0" ih_size="0"
fi fi
# Function to crop videos # Function to crop videos
function crop_video() { function crop_video() {
echo "" echo ""
echo "* Information of ${inputFile}:" echo "* Information of ${inputFile}:"
echo "" echo ""
echo "+ Video Tracks:" echo "+ Video Tracks:"
${p_ffmpeg} "${inputFile}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | cut -d "," -f 1 ${p_ffmpeg} "${inputFile}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | cut -d "," -f 1
echo "" echo ""
echo "+ Audio Tracks:" echo "+ Audio Tracks:"
${p_ffmpeg} "${inputFile}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d "," -f 1 ${p_ffmpeg} "${inputFile}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d "," -f 1
echo "" echo ""
# Check de video track by default # Check de video track by default
video_default=$(${p_ffmpeg} "${inputFile}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1) video_default=$(${p_ffmpeg} "${inputFile}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
if [ -z "${video_default}" ] ; then if [ -z "${video_default}" ] ; then
video_default="0:0" video_default="0:0"
else else
video_default_patch=$(echo ${video_default} | cut -c4) video_default_patch=$(echo ${video_default} | cut -c4)
if [ "${video_default_patch}" == ":" ] ; then if [ "${video_default_patch}" == ":" ] ; then
video_default=$(echo ${video_default} | cut -c1-3) video_default=$(echo ${video_default} | cut -c1-3)
else else
video_default="${video_default}" video_default="${video_default}"
fi fi
fi fi
# Ask for video # Ask for video
echo -n "* (Default: ${video_default}) Type the number of video track: " ; read video_track echo -n "* (Default: ${video_default}) Type the number of video track: " ; read video_track
if [ -z "${video_track}" ] ; then if [ -z "${video_track}" ] ; then
video_track="${video_default}" video_track="${video_default}"
else else
video_track="${video_track}" video_track="${video_track}"
fi fi
# Check the audio track by default # Check the audio track by default
audio_default=$(${p_ffmpeg} "${inputFile}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "(${default_lang_audio})" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1) audio_default=$(${p_ffmpeg} "${inputFile}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "(${default_lang_audio})" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
if [ -z "${audio_default}" ] ; then if [ -z "${audio_default}" ] ; then
audio_default=$(${p_ffmpeg} "${inputFile}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1) audio_default=$(${p_ffmpeg} "${inputFile}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
if [ -z "${audio_default}" ] ; then if [ -z "${audio_default}" ] ; then
audio_default="0:1" audio_default="0:1"
else else
audio_default_patch=$(echo ${audio_default} | cut -c4) audio_default_patch=$(echo ${audio_default} | cut -c4)
if [ "${audio_default_patch}" == ":" ] ; then if [ "${audio_default_patch}" == ":" ] ; then
audio_default=$(echo ${audio_default} | cut -c1-3) audio_default=$(echo ${audio_default} | cut -c1-3)
else else
audio_default="${audio_default}" audio_default="${audio_default}"
fi fi
fi fi
else else
audio_default_patch=$(echo ${audio_default} | cut -c4) audio_default_patch=$(echo ${audio_default} | cut -c4)
if [ "${audio_default_patch}" == ":" ] ; then if [ "${audio_default_patch}" == ":" ] ; then
audio_default=$(echo ${audio_default} | cut -c1-3) audio_default=$(echo ${audio_default} | cut -c1-3)
else else
audio_default="${audio_default}" audio_default="${audio_default}"
fi fi
fi fi
# Ask for audio # Ask for audio
echo -n "* (Default: ${audio_default}) Type the number of audio track: " ; read audio_track echo -n "* (Default: ${audio_default}) Type the number of audio track: " ; read audio_track
if [ -z "${audio_track}" ] ; then if [ -z "${audio_track}" ] ; then
audio_track="${audio_default}" audio_track="${audio_default}"
else else
audio_track="${audio_track}" audio_track="${audio_track}"
fi fi
# Ask for bitrate video # Ask for bitrate video
bitrate_default="${b_vcodec}" bitrate_default="${b_vcodec}"
echo -n "* (Default: ${b_vcodec}) Type the bitrate (${vcodec}): " ; read bitrate_video echo -n "* (Default: ${b_vcodec}) Type the bitrate (${vcodec}): " ; read bitrate_video
if [ -z "${bitrate_video}" ] ; then if [ -z "${bitrate_video}" ] ; then
b_vcodec="${bitrate_default}" b_vcodec="${bitrate_default}"
else else
b_vcodec="${bitrate_video}" b_vcodec="${bitrate_video}"
fi fi
# Reload p_conversion variable # Reload p_conversion variable
if [ -z "${codec_h265_hevc}" ] ; then if [ -z "${codec_h265_hevc}" ] ; then
p_conversion="-c:v ${vcodec} -profile:v high -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec}" p_conversion="-c:v ${vcodec} -profile:v high -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec}"
else else
p_conversion="-c:v ${vcodec} -profile:v high -pix_fmt yuv420p -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec}" p_conversion="-c:v ${vcodec} -profile:v high -pix_fmt yuv420p -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec}"
fi fi
# Ask for patched # Ask for patched
echo -n "* (Default: n) Do you want apply '-max_muxing_queue_size 9999' patch? (y/n): " ; read patch_thread echo -n "* (Default: n) Do you want apply '-max_muxing_queue_size 9999' patch? (y/n): " ; read patch_thread
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
patch_thread="y" patch_thread="y"
else else
patch_thread="n" patch_thread="n"
fi fi
# Check diferent modes # Check diferent modes
if [ "${modeCrop}" == "16:9-crop" ] ; then if [ "${modeCrop}" == "16:9-crop" ] ; then
inputFileOut=$(removeExtension ${inputFile}) inputFileOut=$(removeExtension ${inputFile})
# Show commands for conversion # Show commands for conversion
echo "" echo ""
echo "* COMMAND THAT WILL BE EXECUTED:" echo "* COMMAND THAT WILL BE EXECUTED:"
echo "" echo ""
inputFileSave="${inputFile}" inputFileSave="${inputFile}"
ih_sizeSave="${ih_size}" ih_sizeSave="${ih_size}"
if [ ${ih_size} -eq 0 ] ; then if [ ${ih_size} -eq 0 ] ; then
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
echo " # Error detecting file resolution. The generic solution is applied (slower)" echo " # Error detecting file resolution. The generic solution is applied (slower)"
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -s 1920x1440 ${p_conversion} ${p_ffmpeg_patched} \"${inputFileOut}-resize.${v_ext}\"" echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -s 1920x1440 ${p_conversion} ${p_ffmpeg_patched} \"${inputFileOut}-resize.${v_ext}\""
echo "" echo ""
inputFile="${inputFileOut}-resize.${v_ext}" inputFile="${inputFileOut}-resize.${v_ext}"
ih_size="360" ih_size="360"
else else
echo " # Error detecting file resolution. The generic solution is applied (slower)" echo " # Error detecting file resolution. The generic solution is applied (slower)"
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -s 1920x1440 ${p_conversion} \"${inputFileOut}-resize.${v_ext}\"" echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -s 1920x1440 ${p_conversion} \"${inputFileOut}-resize.${v_ext}\""
echo "" echo ""
inputFile="${inputFileOut}-resize.${v_ext}" inputFile="${inputFileOut}-resize.${v_ext}"
ih_size="360" ih_size="360"
fi fi
else else
echo " # File detected with resolution" ${resolution_detected} "(ih ${ih_size})" echo " # File detected with resolution" ${resolution_detected} "(ih ${ih_size})"
fi fi
echo " # Crop '${inputFile}' from 4:3/IMAX to 16:9 (1.77:1)" echo " # Crop '${inputFile}' from 4:3/IMAX to 16:9 (1.77:1)"
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v \"crop=iw:ih-${ih_size}\" -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} \"${inputFileOut}-crop.${v_ext}\"" echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v \"crop=iw:ih-${ih_size}\" -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} \"${inputFileOut}-crop.${v_ext}\""
else else
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v \"crop=iw:ih-${ih_size}\" -s ${resolution} ${p_conversion} \"${inputFileOut}-crop.${v_ext}\"" echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v \"crop=iw:ih-${ih_size}\" -s ${resolution} ${p_conversion} \"${inputFileOut}-crop.${v_ext}\""
fi fi
# Execute commands for conversion # Execute commands for conversion
echo "" echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit exit
else else
inputFile="${inputFileSave}" inputFile="${inputFileSave}"
ih_size="${ih_sizeSave}" ih_size="${ih_sizeSave}"
inputFileOut=$(removeExtension ${inputFile}) inputFileOut=$(removeExtension ${inputFile})
if [ ${ih_size} -eq 0 ] ; then if [ ${ih_size} -eq 0 ] ; then
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -s 1920x1440 ${p_conversion} ${p_ffmpeg_patched} "${inputFileOut}-resize.${v_ext}" ${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -s 1920x1440 ${p_conversion} ${p_ffmpeg_patched} "${inputFileOut}-resize.${v_ext}"
inputFile="${inputFileOut}-resize.${v_ext}" inputFile="${inputFileOut}-resize.${v_ext}"
ih_size="360" ih_size="360"
else else
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -s 1920x1440 ${p_conversion} "${inputFileOut}-resize.${v_ext}" ${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -s 1920x1440 ${p_conversion} "${inputFileOut}-resize.${v_ext}"
inputFile="${inputFileOut}-resize.${v_ext}" inputFile="${inputFileOut}-resize.${v_ext}"
ih_size="360" ih_size="360"
fi fi
fi fi
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v "crop=iw:ih-${ih_size}" -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} "${inputFileOut}-crop.${v_ext}" ${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v "crop=iw:ih-${ih_size}" -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} "${inputFileOut}-crop.${v_ext}"
else else
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v "crop=iw:ih-${ih_size}" -s ${resolution} ${p_conversion} "${inputFileOut}-crop.${v_ext}" ${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v "crop=iw:ih-${ih_size}" -s ${resolution} ${p_conversion} "${inputFileOut}-crop.${v_ext}"
fi fi
fi fi
elif [ "${modeCrop}" == "4:3-crop" ] ; then elif [ "${modeCrop}" == "4:3-crop" ] ; then
inputFileOut=$(removeExtension ${inputFile}) inputFileOut=$(removeExtension ${inputFile})
# Show commands for conversion # Show commands for conversion
echo "" echo ""
echo "* COMMAND THAT WILL BE EXECUTED:" echo "* COMMAND THAT WILL BE EXECUTED:"
echo "" echo ""
echo " # File detected with resolution" ${resolution_detected} echo " # File detected with resolution" ${resolution_detected}
echo " # Crop '${inputFile}' from 16:9 to 4:3 (1.33:1)" echo " # Crop '${inputFile}' from 16:9 to 4:3 (1.33:1)"
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v \"crop=ih/3*4:ih\" -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} \"${inputFileOut}-crop.${v_ext}\"" echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v \"crop=ih/3*4:ih\" -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} \"${inputFileOut}-crop.${v_ext}\""
else else
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v \"crop=ih/3*4:ih\" -s ${resolution} ${p_conversion} \"${inputFileOut}-crop.${v_ext}\"" echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v \"crop=ih/3*4:ih\" -s ${resolution} ${p_conversion} \"${inputFileOut}-crop.${v_ext}\""
fi fi
# Execute commands for conversion # Execute commands for conversion
echo "" echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit exit
else else
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v "crop=ih/3*4:ih" -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} "${inputFileOut}-crop.${v_ext}" ${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v "crop=ih/3*4:ih" -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} "${inputFileOut}-crop.${v_ext}"
else else
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v "crop=ih/3*4:ih" -s ${resolution} ${p_conversion} "${inputFileOut}-crop.${v_ext}" ${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v "crop=ih/3*4:ih" -s ${resolution} ${p_conversion} "${inputFileOut}-crop.${v_ext}"
fi fi
fi fi
elif [ "${modeCrop}" == "5:4-crop" ] ; then elif [ "${modeCrop}" == "5:4-crop" ] ; then
inputFileOut=$(removeExtension ${inputFile}) inputFileOut=$(removeExtension ${inputFile})
# Show commands for conversion # Show commands for conversion
echo "" echo ""
echo "* COMMAND THAT WILL BE EXECUTED:" echo "* COMMAND THAT WILL BE EXECUTED:"
echo "" echo ""
echo " # File detected with resolution" ${resolution_detected} echo " # File detected with resolution" ${resolution_detected}
echo " # Crop '${inputFile}' from 16:9 to 5:4 (1.25:1)" echo " # Crop '${inputFile}' from 16:9 to 5:4 (1.25:1)"
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v \"crop=ih/4*5:ih\" -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} \"${inputFileOut}-crop.${v_ext}\"" echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v \"crop=ih/4*5:ih\" -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} \"${inputFileOut}-crop.${v_ext}\""
else else
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v \"crop=ih/4*5:ih\" -s ${resolution} ${p_conversion} \"${inputFileOut}-crop.${v_ext}\"" echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v \"crop=ih/4*5:ih\" -s ${resolution} ${p_conversion} \"${inputFileOut}-crop.${v_ext}\""
fi fi
# Execute commands for conversion # Execute commands for conversion
echo "" echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit exit
else else
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v "crop=ih/4*5:ih" -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} "${inputFileOut}-crop.${v_ext}" ${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v "crop=ih/4*5:ih" -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} "${inputFileOut}-crop.${v_ext}"
else else
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v "crop=ih/4*5:ih" -s ${resolution} ${p_conversion} "${inputFileOut}-crop.${v_ext}" ${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v "crop=ih/4*5:ih" -s ${resolution} ${p_conversion} "${inputFileOut}-crop.${v_ext}"
fi fi
fi fi
elif [ "${modeCrop}" == "imax-crop" ] ; then elif [ "${modeCrop}" == "imax-crop" ] ; then
inputFileOut=$(removeExtension ${inputFile}) inputFileOut=$(removeExtension ${inputFile})
# Show commands for conversion # Show commands for conversion
echo "" echo ""
echo "* COMMAND THAT WILL BE EXECUTED:" echo "* COMMAND THAT WILL BE EXECUTED:"
echo "" echo ""
echo " # File detected with resolution" ${resolution_detected} echo " # File detected with resolution" ${resolution_detected}
echo " # Crop '${inputFile}' from 16:9 to IMAX (1.43:1)" echo " # Crop '${inputFile}' from 16:9 to IMAX (1.43:1)"
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v \"crop=ih/2.79*4:ih\" -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} \"${inputFileOut}-crop.${v_ext}\"" echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v \"crop=ih/2.79*4:ih\" -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} \"${inputFileOut}-crop.${v_ext}\""
else else
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v \"crop=ih/2.79*4:ih\" -s ${resolution} ${p_conversion} \"${inputFileOut}-crop.${v_ext}\"" echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v \"crop=ih/2.79*4:ih\" -s ${resolution} ${p_conversion} \"${inputFileOut}-crop.${v_ext}\""
fi fi
# Execute commands for conversion # Execute commands for conversion
echo "" echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit exit
else else
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v "crop=ih/2.79*4:ih" -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} "${inputFileOut}-crop.${v_ext}" ${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v "crop=ih/2.79*4:ih" -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} "${inputFileOut}-crop.${v_ext}"
else else
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v "crop=ih/2.79*4:ih" -s ${resolution} ${p_conversion} "${inputFileOut}-crop.${v_ext}" ${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -filter:v "crop=ih/2.79*4:ih" -s ${resolution} ${p_conversion} "${inputFileOut}-crop.${v_ext}"
fi fi
fi fi
elif [ "${modeCrop}" == "16:9-aspect" ] ; then elif [ "${modeCrop}" == "16:9-aspect" ] ; then
inputFileOut=$(removeExtension ${inputFile}) inputFileOut=$(removeExtension ${inputFile})
# Show commands for conversion # Show commands for conversion
echo "" echo ""
echo "* COMMAND THAT WILL BE EXECUTED:" echo "* COMMAND THAT WILL BE EXECUTED:"
echo "" echo ""
echo " # File detected with resolution" ${resolution_detected} echo " # File detected with resolution" ${resolution_detected}
echo " # Change '${inputFile}' aspect to 16:9 (stretched)" echo " # Change '${inputFile}' aspect to 16:9 (stretched)"
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 16:9 -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} \"${inputFileOut}-aspect.${v_ext}\"" echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 16:9 -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} \"${inputFileOut}-aspect.${v_ext}\""
else else
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 16:9 -s ${resolution} ${p_conversion} \"${inputFileOut}-aspect.${v_ext}\"" echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 16:9 -s ${resolution} ${p_conversion} \"${inputFileOut}-aspect.${v_ext}\""
fi fi
# Execute commands for conversion # Execute commands for conversion
echo "" echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit exit
else else
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 16:9 -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} "${inputFileOut}-aspect.${v_ext}" ${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 16:9 -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} "${inputFileOut}-aspect.${v_ext}"
else else
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 16:9 -s ${resolution} ${p_conversion} "${inputFileOut}-aspect.${v_ext}" ${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 16:9 -s ${resolution} ${p_conversion} "${inputFileOut}-aspect.${v_ext}"
fi fi
fi fi
elif [ "${modeCrop}" == "4:3-aspect" ] ; then elif [ "${modeCrop}" == "4:3-aspect" ] ; then
inputFileOut=$(removeExtension ${inputFile}) inputFileOut=$(removeExtension ${inputFile})
# Show commands for conversion # Show commands for conversion
echo "" echo ""
echo "* COMMAND THAT WILL BE EXECUTED:" echo "* COMMAND THAT WILL BE EXECUTED:"
echo "" echo ""
echo " # File detected with resolution" ${resolution_detected} echo " # File detected with resolution" ${resolution_detected}
echo " # Change '${inputFile}' aspect to 4:3 (stretched)" echo " # Change '${inputFile}' aspect to 4:3 (stretched)"
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 4:3 -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} \"${inputFileOut}-aspect.${v_ext}\"" echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 4:3 -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} \"${inputFileOut}-aspect.${v_ext}\""
else else
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 4:3 -s ${resolution} ${p_conversion} \"${inputFileOut}-aspect.${v_ext}\"" echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 4:3 -s ${resolution} ${p_conversion} \"${inputFileOut}-aspect.${v_ext}\""
fi fi
# Execute commands for conversion # Execute commands for conversion
echo "" echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit exit
else else
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 4:3 -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} "${inputFileOut}-aspect.${v_ext}" ${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 4:3 -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} "${inputFileOut}-aspect.${v_ext}"
else else
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 4:3 -s ${resolution} ${p_conversion} "${inputFileOut}-aspect.${v_ext}" ${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 4:3 -s ${resolution} ${p_conversion} "${inputFileOut}-aspect.${v_ext}"
fi fi
fi fi
elif [ "${modeCrop}" == "5:4-aspect" ] ; then elif [ "${modeCrop}" == "5:4-aspect" ] ; then
inputFileOut=$(removeExtension ${inputFile}) inputFileOut=$(removeExtension ${inputFile})
# Show commands for conversion # Show commands for conversion
echo "" echo ""
echo "* COMMAND THAT WILL BE EXECUTED:" echo "* COMMAND THAT WILL BE EXECUTED:"
echo "" echo ""
echo " # File detected with resolution" ${resolution_detected} echo " # File detected with resolution" ${resolution_detected}
echo " # Change '${inputFile}' aspect to 5:4 (stretched)" echo " # Change '${inputFile}' aspect to 5:4 (stretched)"
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 5:4 -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} \"${inputFileOut}-aspect.${v_ext}\"" echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 5:4 -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} \"${inputFileOut}-aspect.${v_ext}\""
else else
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 5:4 -s ${resolution} ${p_conversion} \"${inputFileOut}-aspect.${v_ext}\"" echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 5:4 -s ${resolution} ${p_conversion} \"${inputFileOut}-aspect.${v_ext}\""
fi fi
# Execute commands for conversion # Execute commands for conversion
echo "" echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit exit
else else
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 5:4 -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} "${inputFileOut}-aspect.${v_ext}" ${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 5:4 -s ${resolution} ${p_conversion} ${p_ffmpeg_patched} "${inputFileOut}-aspect.${v_ext}"
else else
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 5:4 -s ${resolution} ${p_conversion} "${inputFileOut}-aspect.${v_ext}" ${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 5:4 -s ${resolution} ${p_conversion} "${inputFileOut}-aspect.${v_ext}"
fi fi
fi fi
else else
show_menu show_menu
fi fi
} }
# Syntax: ks-crop <option> </absolute/path/video.mkv> # Syntax: ks-crop <option> </absolute/path/video.mkv>
if [ -z "${1}" ] ; then if [ -z "${1}" ] ; then
show_menu show_menu
exit exit
fi fi
if [ -f "${2}" ] ; then if [ -f "${2}" ] ; then
echo "detected" > /dev/null echo "detected" > /dev/null
else else
errorReadingFile "${2}" errorReadingFile "${2}"
fi fi
# Define variables for crop_video function # Define variables for crop_video function
if [ "${1}" == "-16:9-crop" ] ; then if [ "${1}" == "-16:9-crop" ] ; then
modeCrop="16:9-crop" modeCrop="16:9-crop"
resolution="${to16_9}" resolution="${to16_9}"
crop_video crop_video
elif [ "${1}" == "-4:3-crop" ] ; then elif [ "${1}" == "-4:3-crop" ] ; then
modeCrop="4:3-crop" modeCrop="4:3-crop"
resolution="${to4_3}" resolution="${to4_3}"
crop_video crop_video
elif [ "${1}" == "-5:4-crop" ] ; then elif [ "${1}" == "-5:4-crop" ] ; then
modeCrop="5:4-crop" modeCrop="5:4-crop"
resolution="${to5_4}" resolution="${to5_4}"
crop_video crop_video
elif [ "${1}" == "-imax-crop" ] ; then elif [ "${1}" == "-imax-crop" ] ; then
modeCrop="imax-crop" modeCrop="imax-crop"
resolution="${toImax}" resolution="${toImax}"
crop_video crop_video
elif [ "${1}" == "-16:9-aspect" ] ; then elif [ "${1}" == "-16:9-aspect" ] ; then
modeCrop="16:9-aspect" modeCrop="16:9-aspect"
resolution="${to16_9}" resolution="${to16_9}"
crop_video crop_video
elif [ "${1}" == "-4:3-aspect" ] ; then elif [ "${1}" == "-4:3-aspect" ] ; then
modeCrop="4:3-aspect" modeCrop="4:3-aspect"
resolution="${to4_3}" resolution="${to4_3}"
crop_video crop_video
elif [ "${1}" == "-5:4-aspect" ] ; then elif [ "${1}" == "-5:4-aspect" ] ; then
modeCrop="5:4-aspect" modeCrop="5:4-aspect"
resolution="${to5_4}" resolution="${to5_4}"
crop_video crop_video
else else
show_menu show_menu
fi fi

2132
src/ks-mix

File diff suppressed because it is too large Load Diff

View File

@ -30,121 +30,121 @@ fi
ffmpeg_test=$(ffmpeg --help 2>&1) ffmpeg_test=$(ffmpeg --help 2>&1)
error_ffmpeg=$? error_ffmpeg=$?
if [ ${error_ffmpeg} -ne 0 ] ; then if [ ${error_ffmpeg} -ne 0 ] ; then
echo "" echo ""
echo "* ks-mp3 (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-mp3 (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "+ The 'ffmpeg' tool is not installed!" echo "+ The 'ffmpeg' tool is not installed!"
echo "" echo ""
exit exit
fi fi
# Funcion to show the name of file/folder from full path # Funcion to show the name of file/folder from full path
# Syntax: extractFolderOrFile <full/path/file.txt> # Syntax: extractFolderOrFile <full/path/file.txt>
function extractFolderOrFile() { function extractFolderOrFile() {
pathToExtract="${1}/" pathToExtract="${1}/"
findFolder=0 findFolder=0
count=1 count=1
nameFolder=$(echo ${pathToExtract} | cut -d "/" -f ${count}) nameFolder=$(echo ${pathToExtract} | cut -d "/" -f ${count})
count=$(expr $count + 1) count=$(expr $count + 1)
while [ ${findFolder} -eq 0 ] ; do while [ ${findFolder} -eq 0 ] ; do
nameFolderTemp=$(echo ${pathToExtract} | cut -d "/" -f ${count}) nameFolderTemp=$(echo ${pathToExtract} | cut -d "/" -f ${count})
if [ -z "${nameFolderTemp}" ] ; then if [ -z "${nameFolderTemp}" ] ; then
findFolder=1 findFolder=1
else else
nameFolder="${nameFolderTemp}" nameFolder="${nameFolderTemp}"
count=$(expr $count + 1) count=$(expr $count + 1)
fi fi
done done
echo "${nameFolder}" echo "${nameFolder}"
} }
# Function to remove extension from file # Function to remove extension from file
# Syntax: removeExtension "<text>" # Syntax: removeExtension "<text>"
function removeExtension() { function removeExtension() {
wordToConvert=${1} wordToConvert=${1}
ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt" ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt"
mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null
echo "${wordToConvert}" > ${ksToolsSedFile} echo "${wordToConvert}" > ${ksToolsSedFile}
# Remove extensions # Remove extensions
sed -i 's/.avi//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.avi//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mp4//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mp4//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mkv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mkv//g' "${ksToolsSedFile}" &> /dev/null
sed -i "s/.mov//g" "${ksToolsSedFile}" &> /dev/null sed -i "s/.mov//g" "${ksToolsSedFile}" &> /dev/null
sed -i 's/.vob//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.vob//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mpg//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mpg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mpeg//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mpeg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.wmv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.wmv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.ogv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.ogv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.webm//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.webm//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.flv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.flv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mp3//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mp3//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mp2//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mp2//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.oga//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.oga//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.ogg//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.ogg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.ac3//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.ac3//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.aac//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.aac//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.flac//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.flac//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.wav//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.wav//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.opus//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.opus//g' "${ksToolsSedFile}" &> /dev/null
# Show file without extension # Show file without extension
wordToConvert=$(cat ${ksToolsSedFile}) wordToConvert=$(cat ${ksToolsSedFile})
echo ${wordToConvert} echo ${wordToConvert}
} }
# Function to show files with spaces. # Function to show files with spaces.
# Syntax: showFileWithSpace <file number> # Syntax: showFileWithSpace <file number>
function showFileWithSpace() { function showFileWithSpace() {
echo "${1}" > ${dirTemp}/name.tmp echo "${1}" > ${dirTemp}/name.tmp
sed -i 's/_/ /g' ${dirTemp}/name.tmp sed -i 's/_/ /g' ${dirTemp}/name.tmp
DisplayName=$(cat ${dirTemp}/name.tmp) DisplayName=$(cat ${dirTemp}/name.tmp)
rm -rf ${dirTemp}/name.tmp rm -rf ${dirTemp}/name.tmp
cutDisplayName=$(echo ${DisplayName} | cut -c1) cutDisplayName=$(echo ${DisplayName} | cut -c1)
if [ "${cutDisplayName}" == "-" ] ; then if [ "${cutDisplayName}" == "-" ] ; then
DisplayName=$(echo ${DisplayName} | cut -c2-100) DisplayName=$(echo ${DisplayName} | cut -c2-100)
else else
cutDisplayName=$(echo ${DisplayName} | cut -c2) cutDisplayName=$(echo ${DisplayName} | cut -c2)
if [ "${cutDisplayName}" == "-" ] ; then if [ "${cutDisplayName}" == "-" ] ; then
DisplayName=$(echo ${DisplayName} | cut -c3-100) DisplayName=$(echo ${DisplayName} | cut -c3-100)
else else
cutDisplayName=$(echo ${DisplayName} | cut -c3) cutDisplayName=$(echo ${DisplayName} | cut -c3)
if [ "${cutDisplayName}" == "-" ] ; then if [ "${cutDisplayName}" == "-" ] ; then
DisplayName=$(echo ${DisplayName} | cut -c4-100) DisplayName=$(echo ${DisplayName} | cut -c4-100)
fi fi
fi fi
fi fi
echo ${DisplayName} echo ${DisplayName}
} }
# Syntax: ks-mp3 </absolute/path/song.ogg> </path/prefix_name> # Syntax: ks-mp3 </absolute/path/song.ogg> </path/prefix_name>
if [ -z "${1}" ] ; then if [ -z "${1}" ] ; then
echo "" echo ""
echo "* ks-mp3 (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-mp3 (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "- Convert video/audio file(s) to MP3 (Audio) Format" echo "- Convert video/audio file(s) to MP3 (Audio) Format"
echo "" echo ""
echo "+ Config:" echo "+ Config:"
echo "" echo ""
echo " - Audio codec: ${acodec}" echo " - Audio codec: ${acodec}"
echo " - Bitrate audio: ${b_acodec}" echo " - Bitrate audio: ${b_acodec}"
echo " - Container: ${v_ext}" echo " - Container: ${v_ext}"
echo "" echo ""
echo "+ Syntax: " echo "+ Syntax: "
echo "" echo ""
echo " $ ks-mp3 </absolute/path/song.ogg> </path/prefix_name>" echo " $ ks-mp3 </absolute/path/song.ogg> </path/prefix_name>"
echo "" echo ""
echo " + Example: ks-mp3 /data/songs/Example.ogg /data/converted/Example" echo " + Example: ks-mp3 /data/songs/Example.ogg /data/converted/Example"
echo "" echo ""
exit exit
fi fi
if [ -f "${1}" ] ; then if [ -f "${1}" ] ; then
echo "detected" > /dev/null echo "detected" > /dev/null
else else
echo "" echo ""
echo "* ks-mp3 (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-mp3 (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "* The file '${1}' does not exist!" echo "* The file '${1}' does not exist!"
echo "" echo ""
exit exit
fi fi
# Conversion parameters # Conversion parameters
@ -153,132 +153,132 @@ p_ffmpeg="ffmpeg -i"
# Init conversion file # Init conversion file
current_date=$(date +%Y) current_date=$(date +%Y)
if [ -z "${2}" ] ; then if [ -z "${2}" ] ; then
echo "" echo ""
echo "* ks-mp3 (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-mp3 (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "- Convert video/audio file(s) to MP3 (Audio) Format" echo "- Convert video/audio file(s) to MP3 (Audio) Format"
echo "" echo ""
echo "+ Config:" echo "+ Config:"
echo "" echo ""
echo " - Audio codec: ${acodec}" echo " - Audio codec: ${acodec}"
echo " - Bitrate audio: ${b_acodec}" echo " - Bitrate audio: ${b_acodec}"
echo " - Container: ${v_ext}" echo " - Container: ${v_ext}"
echo "" echo ""
echo "+ Syntax: " echo "+ Syntax: "
echo "" echo ""
echo " $ ks-mp3 </absolute/path/song.ogg> </path/prefix_name>" echo " $ ks-mp3 </absolute/path/song.ogg> </path/prefix_name>"
echo "" echo ""
echo " + Example: ks-mp3 /data/songs/Example.ogg /data/converted/Example" echo " + Example: ks-mp3 /data/songs/Example.ogg /data/converted/Example"
echo "" echo ""
exit exit
else else
echo "" echo ""
echo "* Information of ${1}:" echo "* Information of ${1}:"
echo "" echo ""
echo "+ Audio Tracks:" echo "+ Audio Tracks:"
${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d "," -f 1 ${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d "," -f 1
echo "" echo ""
# Check the audio track by default # Check the audio track by default
audio_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "(${default_lang_audio})" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1) audio_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "(${default_lang_audio})" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
if [ -z "${audio_default}" ] ; then if [ -z "${audio_default}" ] ; then
audio_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1) audio_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
if [ -z "${audio_default}" ] ; then if [ -z "${audio_default}" ] ; then
audio_default="0:1" audio_default="0:1"
else else
audio_default_patch=$(echo ${audio_default} | cut -c4) audio_default_patch=$(echo ${audio_default} | cut -c4)
if [ "${audio_default_patch}" == ":" ] ; then if [ "${audio_default_patch}" == ":" ] ; then
audio_default=$(echo ${audio_default} | cut -c1-3) audio_default=$(echo ${audio_default} | cut -c1-3)
else else
audio_default="${audio_default}" audio_default="${audio_default}"
fi fi
fi fi
else else
audio_default_patch=$(echo ${audio_default} | cut -c4) audio_default_patch=$(echo ${audio_default} | cut -c4)
if [ "${audio_default_patch}" == ":" ] ; then if [ "${audio_default_patch}" == ":" ] ; then
audio_default=$(echo ${audio_default} | cut -c1-3) audio_default=$(echo ${audio_default} | cut -c1-3)
else else
audio_default="${audio_default}" audio_default="${audio_default}"
fi fi
fi fi
# Ask for audio # Ask for audio
echo -n "* (Default: ${audio_default}) Type the number of audio track: " ; read audio_track echo -n "* (Default: ${audio_default}) Type the number of audio track: " ; read audio_track
if [ -z "${audio_track}" ] ; then if [ -z "${audio_track}" ] ; then
audio_track="${audio_default}" audio_track="${audio_default}"
else else
audio_track="${audio_track}" audio_track="${audio_track}"
fi fi
# Ask for METADATA # Ask for METADATA
echo "" echo ""
echo "* METADATA configuration:" echo "* METADATA configuration:"
echo "" echo ""
# Prepare name title by default # Prepare name title by default
FullPath="${1}" FullPath="${1}"
name_title_default=$(extractFolderOrFile "${FullPath}") name_title_default=$(extractFolderOrFile "${FullPath}")
name_title_default=$(removeExtension "${name_title_default}") name_title_default=$(removeExtension "${name_title_default}")
name_title_default=$(showFileWithSpace "${name_title_default}") name_title_default=$(showFileWithSpace "${name_title_default}")
# Ask name title, year and genre # Ask name title, year and genre
echo -n "* (Default: ${name_title_default}) Type name of title: " ; read name_title echo -n "* (Default: ${name_title_default}) Type name of title: " ; read name_title
if [ -z "${name_title}" ] ; then if [ -z "${name_title}" ] ; then
name_title="${name_title_default}" name_title="${name_title_default}"
else else
name_title="${name_title}" name_title="${name_title}"
fi fi
echo -n "* (Default: Album-Disc) Type name of album: " ; read album_file echo -n "* (Default: Album-Disc) Type name of album: " ; read album_file
if [ -z "${album_file}" ] ; then if [ -z "${album_file}" ] ; then
album_title="Album-Disc" album_title="Album-Disc"
else else
album_title="${album_file}" album_title="${album_file}"
fi fi
echo -n "* (Default: 01) Type number of track: " ; read track_file echo -n "* (Default: 01) Type number of track: " ; read track_file
if [ -z "${track_file}" ] ; then if [ -z "${track_file}" ] ; then
track_num="01" track_num="01"
else else
track_num="${track_file}" track_num="${track_file}"
fi fi
echo -n "* (Default: Artist) Type name of artist: " ; read artist_file echo -n "* (Default: Artist) Type name of artist: " ; read artist_file
if [ -z "${artist_file}" ] ; then if [ -z "${artist_file}" ] ; then
artist_title="Artist" artist_title="Artist"
else else
artist_title="${artist_file}" artist_title="${artist_file}"
fi fi
echo -n "* (Default: ${current_date}) Type the year: " ; read year_file echo -n "* (Default: ${current_date}) Type the year: " ; read year_file
if [ -z "${year_file}" ] ; then if [ -z "${year_file}" ] ; then
year_num="${current_date}" year_num="${current_date}"
else else
year_num="${year_file}" year_num="${year_file}"
fi fi
echo -n "* (Default: Pop) Type the genre: " ; read genre_file echo -n "* (Default: Pop) Type the genre: " ; read genre_file
if [ -z "${genre_file}" ] ; then if [ -z "${genre_file}" ] ; then
genre_file="Pop" genre_file="Pop"
else else
genre_file="${genre_file}" genre_file="${genre_file}"
fi fi
# Check audio 5.1 or 7.1 # Check audio 5.1 or 7.1
audio_5_7_1=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "${audio_track}" | grep -i "5.1") audio_5_7_1=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "${audio_track}" | grep -i "5.1")
audio_5_7_1_2=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "${audio_track}" | grep -i "7.1") audio_5_7_1_2=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "${audio_track}" | grep -i "7.1")
audio_5_7_1="${audio_5_7_1}${audio_5_7_1_2}" audio_5_7_1="${audio_5_7_1}${audio_5_7_1_2}"
if [ -z "${audio_5_7_1}" ] ; then if [ -z "${audio_5_7_1}" ] ; then
stereo_params="-ac 2" stereo_params="-ac 2"
else else
stereo_params="-ac 2 -clev 3dB -slev -6dB" stereo_params="-ac 2 -clev 3dB -slev -6dB"
fi fi
# Show commands for conversion # Show commands for conversion
echo "" echo ""
echo "* COMMANDS THAT WILL BE EXECUTED:" echo "* COMMANDS THAT WILL BE EXECUTED:"
echo "" echo ""
echo " # Convert the file '${1}' to MP3 Audio" echo " # Convert the file '${1}' to MP3 Audio"
echo " ${p_ffmpeg} \"${1}\" -map ${audio_track} -c:a ${acodec} -b:a ${b_acodec} ${stereo_params} -metadata title=\"${name_title}\" -metadata date=\"${year_num}\" -metadata genre=\"${genre_file}\" -metadata album=\"${album_title}\" -metadata artist=\"${artist_title}\" -metadata track=\"${track_num}\" \"${2}.${v_ext}\"" echo " ${p_ffmpeg} \"${1}\" -map ${audio_track} -c:a ${acodec} -b:a ${b_acodec} ${stereo_params} -metadata title=\"${name_title}\" -metadata date=\"${year_num}\" -metadata genre=\"${genre_file}\" -metadata album=\"${album_title}\" -metadata artist=\"${artist_title}\" -metadata track=\"${track_num}\" \"${2}.${v_ext}\""
# Execute commands for conversion # Execute commands for conversion
echo "" echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit exit
else else
${p_ffmpeg} "${1}" -map ${audio_track} -c:a ${acodec} -b:a ${b_acodec} ${stereo_params} -metadata title="${name_title}" -metadata date="${year_num}" -metadata genre="${genre_file}" -metadata album="${album_title}" -metadata artist="${artist_title}" -metadata track="${track_num}" "${2}.${v_ext}" ${p_ffmpeg} "${1}" -map ${audio_track} -c:a ${acodec} -b:a ${b_acodec} ${stereo_params} -metadata title="${name_title}" -metadata date="${year_num}" -metadata genre="${genre_file}" -metadata album="${album_title}" -metadata artist="${artist_title}" -metadata track="${track_num}" "${2}.${v_ext}"
fi fi
fi fi

View File

@ -37,123 +37,123 @@ fi
ffmpeg_test=$(ffmpeg --help 2>&1) ffmpeg_test=$(ffmpeg --help 2>&1)
error_ffmpeg=$? error_ffmpeg=$?
if [ ${error_ffmpeg} -ne 0 ] ; then if [ ${error_ffmpeg} -ne 0 ] ; then
echo "" echo ""
echo "* ks-mp3-album (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-mp3-album (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "+ The 'ffmpeg' tool is not installed!" echo "+ The 'ffmpeg' tool is not installed!"
echo "" echo ""
exit exit
fi fi
# Funcion to show the name of file/folder from full path # Funcion to show the name of file/folder from full path
# Syntax: extractFolderOrFile <full/path/file.txt> # Syntax: extractFolderOrFile <full/path/file.txt>
function extractFolderOrFile() { function extractFolderOrFile() {
pathToExtract="${1}/" pathToExtract="${1}/"
findFolder=0 findFolder=0
count=1 count=1
nameFolder=$(echo ${pathToExtract} | cut -d "/" -f ${count}) nameFolder=$(echo ${pathToExtract} | cut -d "/" -f ${count})
count=$(expr $count + 1) count=$(expr $count + 1)
while [ ${findFolder} -eq 0 ] ; do while [ ${findFolder} -eq 0 ] ; do
nameFolderTemp=$(echo ${pathToExtract} | cut -d "/" -f ${count}) nameFolderTemp=$(echo ${pathToExtract} | cut -d "/" -f ${count})
if [ -z "${nameFolderTemp}" ] ; then if [ -z "${nameFolderTemp}" ] ; then
findFolder=1 findFolder=1
else else
nameFolder="${nameFolderTemp}" nameFolder="${nameFolderTemp}"
count=$(expr $count + 1) count=$(expr $count + 1)
fi fi
done done
echo "${nameFolder}" echo "${nameFolder}"
} }
# Function to show files with spaces. # Function to show files with spaces.
# Syntax: showFileWithSpace <file number> # Syntax: showFileWithSpace <file number>
function showFileWithSpace() { function showFileWithSpace() {
echo "${1}" > ${dirTemp}/name.tmp echo "${1}" > ${dirTemp}/name.tmp
sed -i 's/_/ /g' ${dirTemp}/name.tmp sed -i 's/_/ /g' ${dirTemp}/name.tmp
DisplayName=$(cat ${dirTemp}/name.tmp) DisplayName=$(cat ${dirTemp}/name.tmp)
rm -rf ${dirTemp}/name.tmp rm -rf ${dirTemp}/name.tmp
cutDisplayName=$(echo ${DisplayName} | cut -c1) cutDisplayName=$(echo ${DisplayName} | cut -c1)
if [ "${cutDisplayName}" == "-" ] ; then if [ "${cutDisplayName}" == "-" ] ; then
DisplayName=$(echo ${DisplayName} | cut -c2-100) DisplayName=$(echo ${DisplayName} | cut -c2-100)
else else
cutDisplayName=$(echo ${DisplayName} | cut -c2) cutDisplayName=$(echo ${DisplayName} | cut -c2)
if [ "${cutDisplayName}" == "-" ] ; then if [ "${cutDisplayName}" == "-" ] ; then
DisplayName=$(echo ${DisplayName} | cut -c3-100) DisplayName=$(echo ${DisplayName} | cut -c3-100)
else else
cutDisplayName=$(echo ${DisplayName} | cut -c3) cutDisplayName=$(echo ${DisplayName} | cut -c3)
if [ "${cutDisplayName}" == "-" ] ; then if [ "${cutDisplayName}" == "-" ] ; then
DisplayName=$(echo ${DisplayName} | cut -c4-100) DisplayName=$(echo ${DisplayName} | cut -c4-100)
fi fi
fi fi
fi fi
echo ${DisplayName} echo ${DisplayName}
} }
# Function to remove extension from file # Function to remove extension from file
# Syntax: removeExtension "<text>" # Syntax: removeExtension "<text>"
function removeExtension() { function removeExtension() {
wordToConvert=${1} wordToConvert=${1}
ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt" ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt"
mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null
echo "${wordToConvert}" > ${ksToolsSedFile} echo "${wordToConvert}" > ${ksToolsSedFile}
# Remove extensions # Remove extensions
sed -i 's/.avi//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.avi//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mp4//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mp4//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mkv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mkv//g' "${ksToolsSedFile}" &> /dev/null
sed -i "s/.mov//g" "${ksToolsSedFile}" &> /dev/null sed -i "s/.mov//g" "${ksToolsSedFile}" &> /dev/null
sed -i 's/.vob//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.vob//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mpg//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mpg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mpeg//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mpeg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.wmv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.wmv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.ogv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.ogv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.webm//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.webm//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.flv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.flv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mp3//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mp3//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mp2//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mp2//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.oga//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.oga//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.ogg//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.ogg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.ac3//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.ac3//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.aac//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.aac//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.flac//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.flac//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.wav//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.wav//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.opus//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.opus//g' "${ksToolsSedFile}" &> /dev/null
# Show file without extension # Show file without extension
wordToConvert=$(cat ${ksToolsSedFile}) wordToConvert=$(cat ${ksToolsSedFile})
echo ${wordToConvert} echo ${wordToConvert}
} }
# Syntax: ks-mp3-album </absolute/path/album/ # Syntax: ks-mp3-album </absolute/path/album/
if [ -z "${1}" ] ; then if [ -z "${1}" ] ; then
echo "" echo ""
echo "* ks-mp3-album (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-mp3-album (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "- Convert folder album to MP3 Audio Format" echo "- Convert folder album to MP3 Audio Format"
echo "" echo ""
echo "+ Config:" echo "+ Config:"
echo "" echo ""
echo " - Audio codec: ${acodec}" echo " - Audio codec: ${acodec}"
echo " - Bitrate audio: ${b_acodec}" echo " - Bitrate audio: ${b_acodec}"
echo " - Container: ${v_ext}" echo " - Container: ${v_ext}"
echo "" echo ""
echo "+ Syntax: " echo "+ Syntax: "
echo "" echo ""
echo " $ ks-mp3-album </absolute/path/album>" echo " $ ks-mp3-album </absolute/path/album>"
echo "" echo ""
echo " + Example: ks-mp3-album /data/albums/matrix-soundtrack" echo " + Example: ks-mp3-album /data/albums/matrix-soundtrack"
echo "" echo ""
exit exit
fi fi
# Check if folder exist # Check if folder exist
if [ -d "${1}" ] ; then if [ -d "${1}" ] ; then
echo null > /dev/null echo null > /dev/null
else else
echo "" echo ""
echo "* ks-mp3-album (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-mp3-album (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "+ The folder '${1}' does not exist!" echo "+ The folder '${1}' does not exist!"
echo "" echo ""
exit exit
fi fi
# Scan videos/audio files format # Scan videos/audio files format
@ -167,14 +167,14 @@ echo -n "* Scanning ${1} " && sleep 4
echo "" echo ""
rm -rf ${tempFile} && touch ${tempFile} rm -rf ${tempFile} && touch ${tempFile}
for format in ${formatFiles} ; do for format in ${formatFiles} ; do
find "${1}"/*.${format} &> ${tempFileTest} find "${1}"/*.${format} &> ${tempFileTest}
if [ $? -ne 0 ] ; then if [ $? -ne 0 ] ; then
echo "null" > /dev/null echo "null" > /dev/null
else else
echo "+ Video file(s) in .${format} found!" echo "+ Video file(s) in .${format} found!"
cd "${1}" && ls -1 *.${format} &>> ${tempFile} cd "${1}" && ls -1 *.${format} &>> ${tempFile}
fail=0 fail=0
fi fi
done done
# Set the global metadata album # Set the global metadata album
@ -184,129 +184,129 @@ echo "* Common METADATA configuration:"
echo "" echo ""
echo -n "* (Default: Album-Disc) Type name of album: " ; read album_file echo -n "* (Default: Album-Disc) Type name of album: " ; read album_file
if [ -z "${album_file}" ] ; then if [ -z "${album_file}" ] ; then
album_title="Album-Disc" album_title="Album-Disc"
else else
album_title="${album_file}" album_title="${album_file}"
fi fi
echo -n "* (Default: ${current_date}) Type the year of album: " ; read year_file echo -n "* (Default: ${current_date}) Type the year of album: " ; read year_file
if [ -z "${year_file}" ] ; then if [ -z "${year_file}" ] ; then
year_num="${current_date}" year_num="${current_date}"
else else
year_num="${year_file}" year_num="${year_file}"
fi fi
echo -n "* (Default: Pop) Type the genre of album: " ; read genre_file echo -n "* (Default: Pop) Type the genre of album: " ; read genre_file
if [ -z "${genre_file}" ] ; then if [ -z "${genre_file}" ] ; then
genre_file="Pop" genre_file="Pop"
else else
genre_file="${genre_file}" genre_file="${genre_file}"
fi fi
# Init the conversion files # Init the conversion files
convert_files=1 convert_files=1
num_files=$(cat ${tempFile} | wc -l) num_files=$(cat ${tempFile} | wc -l)
if [ ${num_files} -eq 0 ] ; then if [ ${num_files} -eq 0 ] ; then
echo "" echo ""
echo "+ No video/audio file(s) found in folder '${1}" echo "+ No video/audio file(s) found in folder '${1}"
echo "" echo ""
exit exit
else else
echo "" echo ""
echo "* List of files:" echo "* List of files:"
echo "" echo ""
while [ ${convert_files} -le ${num_files} ] ; do while [ ${convert_files} -le ${num_files} ] ; do
show_file=$(cat ${tempFile} | head -${convert_files} | tail -1) show_file=$(cat ${tempFile} | head -${convert_files} | tail -1)
echo " + ${show_file}" echo " + ${show_file}"
convert_files=$(expr ${convert_files} + 1) convert_files=$(expr ${convert_files} + 1)
done done
echo "" echo ""
echo "* The output folder will be '${1}/to-mp3'" echo "* The output folder will be '${1}/to-mp3'"
# Execute commands for conversion # Execute commands for conversion
echo "" echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit exit
else else
convert_files=1 convert_files=1
cd "${1}" && mkdir -p to-mp3 && rm -rf to-mp3/* cd "${1}" && mkdir -p to-mp3 && rm -rf to-mp3/*
while [ ${convert_files} -le ${num_files} ] ; do while [ ${convert_files} -le ${num_files} ] ; do
show_file=$(cat ${tempFile} | head -${convert_files} | tail -1) show_file=$(cat ${tempFile} | head -${convert_files} | tail -1)
fname=$(echo "${show_file}" | cut -d "." -f 1) fname=$(echo "${show_file}" | cut -d "." -f 1)
name_title_default=$(removeExtension "${show_file}") name_title_default=$(removeExtension "${show_file}")
name_title_default=$(showFileWithSpace "${name_title_default}") name_title_default=$(showFileWithSpace "${name_title_default}")
echo "" echo ""
echo "* METADATA for '${show_file}'" echo "* METADATA for '${show_file}'"
echo "" echo ""
echo " - Album: ${album_title}" echo " - Album: ${album_title}"
echo " - Year: ${year_num}" echo " - Year: ${year_num}"
echo " - Genre: ${genre_file}" echo " - Genre: ${genre_file}"
echo "" echo ""
echo "* Information of '${show_file}':" echo "* Information of '${show_file}':"
echo "" echo ""
echo "+ Audio Tracks:" echo "+ Audio Tracks:"
echo "" echo ""
ffmpeg -i "${show_file}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d "," -f 1 ffmpeg -i "${show_file}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d "," -f 1
echo "" echo ""
# Check the audio track by default # Check the audio track by default
audio_default=$(ffmpeg -i "${show_file}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "(${default_lang_audio})" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1) audio_default=$(ffmpeg -i "${show_file}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "(${default_lang_audio})" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
if [ -z "${audio_default}" ] ; then if [ -z "${audio_default}" ] ; then
audio_default=$(ffmpeg -i "${show_file}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1) audio_default=$(ffmpeg -i "${show_file}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
if [ -z "${audio_default}" ] ; then if [ -z "${audio_default}" ] ; then
audio_default="0:1" audio_default="0:1"
else else
audio_default_patch=$(echo ${audio_default} | cut -c4) audio_default_patch=$(echo ${audio_default} | cut -c4)
if [ "${audio_default_patch}" == ":" ] ; then if [ "${audio_default_patch}" == ":" ] ; then
audio_default=$(echo ${audio_default} | cut -c1-3) audio_default=$(echo ${audio_default} | cut -c1-3)
else else
audio_default="${audio_default}" audio_default="${audio_default}"
fi fi
fi fi
else else
audio_default_patch=$(echo ${audio_default} | cut -c4) audio_default_patch=$(echo ${audio_default} | cut -c4)
if [ "${audio_default_patch}" == ":" ] ; then if [ "${audio_default_patch}" == ":" ] ; then
audio_default=$(echo ${audio_default} | cut -c1-3) audio_default=$(echo ${audio_default} | cut -c1-3)
else else
audio_default="${audio_default}" audio_default="${audio_default}"
fi fi
fi fi
# Ask for audio # Ask for audio
echo -n "* (Default: ${audio_default}) Type the number of audio track: " ; read audio_track echo -n "* (Default: ${audio_default}) Type the number of audio track: " ; read audio_track
if [ -z "${audio_track}" ] ; then if [ -z "${audio_track}" ] ; then
audio_track="${audio_default}" audio_track="${audio_default}"
else else
audio_track="${audio_track}" audio_track="${audio_track}"
fi fi
echo -n "* (Default: ${name_title_default}) Type name of title: " ; read name_title echo -n "* (Default: ${name_title_default}) Type name of title: " ; read name_title
if [ -z "${name_title}" ] ; then if [ -z "${name_title}" ] ; then
name_title="${name_title_default}" name_title="${name_title_default}"
else else
name_title="${name_title}" name_title="${name_title}"
fi fi
echo -n "* (Default: ${track_init}) Type number of track: " ; read track_file echo -n "* (Default: ${track_init}) Type number of track: " ; read track_file
if [ -z "${track_file}" ] ; then if [ -z "${track_file}" ] ; then
track_num="${track_init}" track_num="${track_init}"
else else
track_num="${track_file}" track_num="${track_file}"
fi fi
echo -n "* (Default: ${artist_init}) Type name of artist: " ; read artist_file echo -n "* (Default: ${artist_init}) Type name of artist: " ; read artist_file
if [ -z "${artist_file}" ] ; then if [ -z "${artist_file}" ] ; then
artist_title="${artist_init}" artist_title="${artist_init}"
else else
artist_title="${artist_file}" artist_title="${artist_file}"
artist_init="${artist_file}" artist_init="${artist_file}"
fi fi
# Check audio 5.1 or 7.1 # Check audio 5.1 or 7.1
audio_5_7_1=$(${p_ffmpeg} "${show_file}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "${audio_track}" | grep -i "5.1") audio_5_7_1=$(${p_ffmpeg} "${show_file}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "${audio_track}" | grep -i "5.1")
audio_5_7_1_2=$(${p_ffmpeg} "${show_file}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "${audio_track}" | grep -i "7.1") audio_5_7_1_2=$(${p_ffmpeg} "${show_file}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "${audio_track}" | grep -i "7.1")
audio_5_7_1="${audio_5_7_1}${audio_5_7_1_2}" audio_5_7_1="${audio_5_7_1}${audio_5_7_1_2}"
if [ -z "${audio_5_7_1}" ] ; then if [ -z "${audio_5_7_1}" ] ; then
stereo_params="-ac 2" stereo_params="-ac 2"
else else
stereo_params="-ac 2 -clev 3dB -slev -6dB" stereo_params="-ac 2 -clev 3dB -slev -6dB"
fi fi
ffmpeg -i "${show_file}" -map ${audio_track} -c:a ${acodec} -b:a ${b_acodec} ${stereo_params} -metadata title="${name_title}" -metadata date="${year_num}" -metadata genre="${genre_file}" -metadata album="${album_title}" -metadata artist="${artist_title}" -metadata track="${track_num}" "to-mp3/${fname}.${v_ext}" ffmpeg -i "${show_file}" -map ${audio_track} -c:a ${acodec} -b:a ${b_acodec} ${stereo_params} -metadata title="${name_title}" -metadata date="${year_num}" -metadata genre="${genre_file}" -metadata album="${album_title}" -metadata artist="${artist_title}" -metadata track="${track_num}" "to-mp3/${fname}.${v_ext}"
# Increment variables # Increment variables
convert_files=$(expr ${convert_files} + 1) convert_files=$(expr ${convert_files} + 1)
track_init=$(expr ${track_num} + 1) track_init=$(expr ${track_num} + 1)
done done
fi fi
fi fi

View File

@ -37,104 +37,104 @@ fi
ffmpeg_test=$(ffmpeg --help 2>&1) ffmpeg_test=$(ffmpeg --help 2>&1)
error_ffmpeg=$? error_ffmpeg=$?
if [ ${error_ffmpeg} -ne 0 ] ; then if [ ${error_ffmpeg} -ne 0 ] ; then
echo "" echo ""
echo "* ks-mp4 (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-mp4 (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "+ The 'ffmpeg' tool is not installed!" echo "+ The 'ffmpeg' tool is not installed!"
echo "" echo ""
exit exit
fi fi
# Funcion to show the name of file/folder from full path # Funcion to show the name of file/folder from full path
# Syntax: extractFolderOrFile <full/path/file.txt> # Syntax: extractFolderOrFile <full/path/file.txt>
function extractFolderOrFile() { function extractFolderOrFile() {
pathToExtract="${1}/" pathToExtract="${1}/"
findFolder=0 findFolder=0
count=1 count=1
nameFolder=$(echo ${pathToExtract} | cut -d "/" -f ${count}) nameFolder=$(echo ${pathToExtract} | cut -d "/" -f ${count})
count=$(expr $count + 1) count=$(expr $count + 1)
while [ ${findFolder} -eq 0 ] ; do while [ ${findFolder} -eq 0 ] ; do
nameFolderTemp=$(echo ${pathToExtract} | cut -d "/" -f ${count}) nameFolderTemp=$(echo ${pathToExtract} | cut -d "/" -f ${count})
if [ -z "${nameFolderTemp}" ] ; then if [ -z "${nameFolderTemp}" ] ; then
findFolder=1 findFolder=1
else else
nameFolder="${nameFolderTemp}" nameFolder="${nameFolderTemp}"
count=$(expr $count + 1) count=$(expr $count + 1)
fi fi
done done
echo "${nameFolder}" echo "${nameFolder}"
} }
# Function to remove extension from file # Function to remove extension from file
# Syntax: removeExtension "<text>" # Syntax: removeExtension "<text>"
function removeExtension() { function removeExtension() {
wordToConvert=${1} wordToConvert=${1}
ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt" ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt"
mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null
echo "${wordToConvert}" > ${ksToolsSedFile} echo "${wordToConvert}" > ${ksToolsSedFile}
# Remove extensions # Remove extensions
sed -i 's/.avi//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.avi//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mp4//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mp4//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mkv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mkv//g' "${ksToolsSedFile}" &> /dev/null
sed -i "s/.mov//g" "${ksToolsSedFile}" &> /dev/null sed -i "s/.mov//g" "${ksToolsSedFile}" &> /dev/null
sed -i 's/.vob//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.vob//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mpg//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mpg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mpeg//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mpeg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.wmv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.wmv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.ogv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.ogv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.webm//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.webm//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.flv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.flv//g' "${ksToolsSedFile}" &> /dev/null
# Show file without extension # Show file without extension
wordToConvert=$(cat ${ksToolsSedFile}) wordToConvert=$(cat ${ksToolsSedFile})
echo ${wordToConvert} echo ${wordToConvert}
} }
# Function to show files with spaces. # Function to show files with spaces.
# Syntax: showFileWithSpace <file number> # Syntax: showFileWithSpace <file number>
function showFileWithSpace() { function showFileWithSpace() {
echo "${1}" > ${dirTemp}/name.tmp echo "${1}" > ${dirTemp}/name.tmp
sed -i 's/_/ /g' ${dirTemp}/name.tmp sed -i 's/_/ /g' ${dirTemp}/name.tmp
DisplayName=$(cat ${dirTemp}/name.tmp) DisplayName=$(cat ${dirTemp}/name.tmp)
rm -rf ${dirTemp}/name.tmp rm -rf ${dirTemp}/name.tmp
echo ${DisplayName} echo ${DisplayName}
} }
# Syntax: ks-mp4 </absolute/path/video.mkv> </path/prefix_name> # Syntax: ks-mp4 </absolute/path/video.mkv> </path/prefix_name>
if [ -z "${1}" ] ; then if [ -z "${1}" ] ; then
echo "" echo ""
echo "* ks-mp4 (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-mp4 (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "- Convert video file(s) to compact and efficient MP4" echo "- Convert video file(s) to compact and efficient MP4"
echo "" echo ""
echo "+ Config:" echo "+ Config:"
echo "" echo ""
echo " - Resolution: ${rel_size}" echo " - Resolution: ${rel_size}"
echo " - Video codec: ${vcodec}" echo " - Video codec: ${vcodec}"
echo " - Bitrate video: ${b_vcodec}" echo " - Bitrate video: ${b_vcodec}"
echo " - Preset: ${v_preset}" echo " - Preset: ${v_preset}"
echo " - Audio codec: ${acodec} (stereo)" echo " - Audio codec: ${acodec} (stereo)"
echo " - Bitrate audio: ${b_acodec}" echo " - Bitrate audio: ${b_acodec}"
echo " - Default Audio: ${default_lang_audio}" echo " - Default Audio: ${default_lang_audio}"
echo " - Default Subtitle: ${default_lang_subt} (forced)" echo " - Default Subtitle: ${default_lang_subt} (forced)"
echo " - Container: ${v_ext}" echo " - Container: ${v_ext}"
echo "" echo ""
echo "+ Syntax: " echo "+ Syntax: "
echo "" echo ""
echo " $ ks-mp4 </absolute/path/video.mkv> </path/prefix_name>" echo " $ ks-mp4 </absolute/path/video.mkv> </path/prefix_name>"
echo "" echo ""
echo " + Example: ks-mp4 /data/movies/Example.mkv /data/converted/Example" echo " + Example: ks-mp4 /data/movies/Example.mkv /data/converted/Example"
echo "" echo ""
exit exit
fi fi
if [ -f "${1}" ] ; then if [ -f "${1}" ] ; then
echo "detected" > /dev/null echo "detected" > /dev/null
else else
echo "" echo ""
echo "* ks-mp4 (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-mp4 (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "* The file '${1}' does not exist!" echo "* The file '${1}' does not exist!"
echo "" echo ""
exit exit
fi fi
# Conversion parameters # Conversion parameters
@ -147,239 +147,239 @@ codec_hevc=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Video:" |
yuv420p10le=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | grep "yuv420p10le") yuv420p10le=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | grep "yuv420p10le")
codec_h265_hevc="${codec_h265}${codec_hevc}${yuv420p10le}" codec_h265_hevc="${codec_h265}${codec_hevc}${yuv420p10le}"
if [ -z "${codec_h265_hevc}" ] ; then if [ -z "${codec_h265_hevc}" ] ; then
p_conversion="-s ${rel_size} -c:v ${vcodec} -profile:v high -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec} -b:a ${b_acodec}" p_conversion="-s ${rel_size} -c:v ${vcodec} -profile:v high -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec} -b:a ${b_acodec}"
else else
p_conversion="-s ${rel_size} -c:v ${vcodec} -profile:v high -pix_fmt yuv420p -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec} -b:a ${b_acodec}" p_conversion="-s ${rel_size} -c:v ${vcodec} -profile:v high -pix_fmt yuv420p -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec} -b:a ${b_acodec}"
fi fi
# Init conversion file # Init conversion file
current_date=$(date +%Y) current_date=$(date +%Y)
if [ -z "${2}" ] ; then if [ -z "${2}" ] ; then
echo "" echo ""
echo "* ks-mp4 (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-mp4 (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "- Convert video file(s) to compact and efficient MP4" echo "- Convert video file(s) to compact and efficient MP4"
echo "" echo ""
echo "+ Config:" echo "+ Config:"
echo "" echo ""
echo " - Resolution: ${rel_size}" echo " - Resolution: ${rel_size}"
echo " - Video codec: ${vcodec}" echo " - Video codec: ${vcodec}"
echo " - Bitrate video: ${b_vcodec}" echo " - Bitrate video: ${b_vcodec}"
echo " - Preset: ${v_preset}" echo " - Preset: ${v_preset}"
echo " - Audio codec: ${acodec} (stereo)" echo " - Audio codec: ${acodec} (stereo)"
echo " - Bitrate audio: ${b_acodec}" echo " - Bitrate audio: ${b_acodec}"
echo " - Default Audio: ${default_lang_audio}" echo " - Default Audio: ${default_lang_audio}"
echo " - Default Subtitle: ${default_lang_subt} (forced)" echo " - Default Subtitle: ${default_lang_subt} (forced)"
echo " - Container: ${v_ext}" echo " - Container: ${v_ext}"
echo "" echo ""
echo "+ Syntax: " echo "+ Syntax: "
echo "" echo ""
echo " $ ks-mp4 </absolute/path/video.mkv> </path/prefix_name>" echo " $ ks-mp4 </absolute/path/video.mkv> </path/prefix_name>"
echo "" echo ""
echo " + Example: ks-mp4 /data/movies/Example.mkv /data/converted/Example" echo " + Example: ks-mp4 /data/movies/Example.mkv /data/converted/Example"
echo "" echo ""
exit exit
else else
echo "" echo ""
echo "* Information of ${1}:" echo "* Information of ${1}:"
echo "" echo ""
echo "+ Video Tracks:" echo "+ Video Tracks:"
${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | cut -d "," -f 1 ${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | cut -d "," -f 1
echo "" echo ""
echo "+ Audio Tracks:" echo "+ Audio Tracks:"
${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d "," -f 1 ${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d "," -f 1
echo "" echo ""
echo "+ Subtitle Tracks:" echo "+ Subtitle Tracks:"
${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Subtitle:" | cut -d "," -f 1 ${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Subtitle:" | cut -d "," -f 1
echo "" echo ""
# Check de video track by default # Check de video track by default
video_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1) video_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
if [ -z "${video_default}" ] ; then if [ -z "${video_default}" ] ; then
video_default="0:0" video_default="0:0"
else else
video_default_patch=$(echo ${video_default} | cut -c4) video_default_patch=$(echo ${video_default} | cut -c4)
if [ "${video_default_patch}" == ":" ] ; then if [ "${video_default_patch}" == ":" ] ; then
video_default=$(echo ${video_default} | cut -c1-3) video_default=$(echo ${video_default} | cut -c1-3)
else else
video_default="${video_default}" video_default="${video_default}"
fi fi
fi fi
# Ask for video # Ask for video
echo -n "* (Default: ${video_default}) Type the number of video track: " ; read video_track echo -n "* (Default: ${video_default}) Type the number of video track: " ; read video_track
if [ -z "${video_track}" ] ; then if [ -z "${video_track}" ] ; then
video_track="${video_default}" video_track="${video_default}"
else else
video_track="${video_track}" video_track="${video_track}"
fi fi
# Check the audio track by default # Check the audio track by default
audio_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "(${default_lang_audio})" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1) audio_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "(${default_lang_audio})" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
if [ -z "${audio_default}" ] ; then if [ -z "${audio_default}" ] ; then
audio_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1) audio_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
if [ -z "${audio_default}" ] ; then if [ -z "${audio_default}" ] ; then
audio_default="0:1" audio_default="0:1"
else else
audio_default_patch=$(echo ${audio_default} | cut -c4) audio_default_patch=$(echo ${audio_default} | cut -c4)
if [ "${audio_default_patch}" == ":" ] ; then if [ "${audio_default_patch}" == ":" ] ; then
audio_default=$(echo ${audio_default} | cut -c1-3) audio_default=$(echo ${audio_default} | cut -c1-3)
else else
audio_default="${audio_default}" audio_default="${audio_default}"
fi fi
fi fi
else else
audio_default_patch=$(echo ${audio_default} | cut -c4) audio_default_patch=$(echo ${audio_default} | cut -c4)
if [ "${audio_default_patch}" == ":" ] ; then if [ "${audio_default_patch}" == ":" ] ; then
audio_default=$(echo ${audio_default} | cut -c1-3) audio_default=$(echo ${audio_default} | cut -c1-3)
else else
audio_default="${audio_default}" audio_default="${audio_default}"
fi fi
fi fi
# Ask for audio # Ask for audio
echo -n "* (Default: ${audio_default}) Type the number of audio track: " ; read audio_track echo -n "* (Default: ${audio_default}) Type the number of audio track: " ; read audio_track
if [ -z "${audio_track}" ] ; then if [ -z "${audio_track}" ] ; then
audio_track="${audio_default}" audio_track="${audio_default}"
else else
audio_track="${audio_track}" audio_track="${audio_track}"
fi fi
# Check the subtitle track by default # Check the subtitle track by default
subtitle_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Subtitle:" | grep "(${default_lang_subt})" | grep "(forced)" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1) subtitle_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Subtitle:" | grep "(${default_lang_subt})" | grep "(forced)" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
if [ -z "${subtitle_default}" ] ; then if [ -z "${subtitle_default}" ] ; then
subtitle_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Subtitle:" | grep "(${default_lang_subt})" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1) subtitle_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Subtitle:" | grep "(${default_lang_subt})" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
if [ -z "${subtitle_default}" ] ; then if [ -z "${subtitle_default}" ] ; then
subtitle_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Subtitle:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1) subtitle_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Subtitle:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
if [ -z "${subtitle_default}" ] ; then if [ -z "${subtitle_default}" ] ; then
subtitle_default="0:3" subtitle_default="0:3"
else else
subtitle_default_patch=$(echo ${subtitle_default} | cut -c4) subtitle_default_patch=$(echo ${subtitle_default} | cut -c4)
if [ "${subtitle_default_patch}" == ":" ] ; then if [ "${subtitle_default_patch}" == ":" ] ; then
subtitle_default=$(echo ${subtitle_default} | cut -c1-3) subtitle_default=$(echo ${subtitle_default} | cut -c1-3)
else else
subtitle_default="${subtitle_default}" subtitle_default="${subtitle_default}"
fi fi
fi fi
else else
subtitle_default_patch=$(echo ${subtitle_default} | cut -c4) subtitle_default_patch=$(echo ${subtitle_default} | cut -c4)
if [ "${subtitle_default_patch}" == ":" ] ; then if [ "${subtitle_default_patch}" == ":" ] ; then
subtitle_default=$(echo ${subtitle_default} | cut -c1-3) subtitle_default=$(echo ${subtitle_default} | cut -c1-3)
else else
subtitle_default="${subtitle_default}" subtitle_default="${subtitle_default}"
fi fi
fi fi
else else
subtitle_default_patch=$(echo ${subtitle_default} | cut -c4) subtitle_default_patch=$(echo ${subtitle_default} | cut -c4)
if [ "${subtitle_default_patch}" == ":" ] ; then if [ "${subtitle_default_patch}" == ":" ] ; then
subtitle_default=$(echo ${subtitle_default} | cut -c1-3) subtitle_default=$(echo ${subtitle_default} | cut -c1-3)
else else
subtitle_default="${subtitle_default}" subtitle_default="${subtitle_default}"
fi fi
fi fi
# Ask for subtitle # Ask for subtitle
echo -n "* (Default: n) Do you want include subtitles? (y/n): " ; read subtitles_y_n echo -n "* (Default: n) Do you want include subtitles? (y/n): " ; read subtitles_y_n
if [ "${subtitles_y_n}" == "y" ] ; then if [ "${subtitles_y_n}" == "y" ] ; then
echo -n "* (Default: ${subtitle_default}) Type the number of subtitle track: " ; read subtitle_track echo -n "* (Default: ${subtitle_default}) Type the number of subtitle track: " ; read subtitle_track
if [ -z "${subtitle_track}" ] ; then if [ -z "${subtitle_track}" ] ; then
subtitle_track="${subtitle_default}" subtitle_track="${subtitle_default}"
else else
subtitle_track="${subtitle_track}" subtitle_track="${subtitle_track}"
fi fi
fi fi
echo -n "* (Default: ${rel_size}) Type the resolution: " ; read resolution echo -n "* (Default: ${rel_size}) Type the resolution: " ; read resolution
if [ -z "${resolution}" ] ; then if [ -z "${resolution}" ] ; then
resolution="${rel_size}" resolution="${rel_size}"
else else
rel_size="${resolution}" rel_size="${resolution}"
if [ -z "${codec_h265_hevc}" ] ; then if [ -z "${codec_h265_hevc}" ] ; then
p_conversion="-s ${rel_size} -c:v ${vcodec} -profile:v high -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec} -b:a ${b_acodec}" p_conversion="-s ${rel_size} -c:v ${vcodec} -profile:v high -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec} -b:a ${b_acodec}"
else else
p_conversion="-s ${rel_size} -c:v ${vcodec} -profile:v high -pix_fmt yuv420p -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec} -b:a ${b_acodec}" p_conversion="-s ${rel_size} -c:v ${vcodec} -profile:v high -pix_fmt yuv420p -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec} -b:a ${b_acodec}"
fi fi
fi fi
echo -n "* (Default: n) Do you want apply '-max_muxing_queue_size 9999' patch? (y/n): " ; read patch_thread echo -n "* (Default: n) Do you want apply '-max_muxing_queue_size 9999' patch? (y/n): " ; read patch_thread
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
patch_thread="y" patch_thread="y"
else else
patch_thread="n" patch_thread="n"
fi fi
echo "" echo ""
echo "* METADATA configuration:" echo "* METADATA configuration:"
echo "" echo ""
# Prepare name title by default # Prepare name title by default
FullPath="${1}" FullPath="${1}"
name_title_default=$(extractFolderOrFile "${FullPath}") name_title_default=$(extractFolderOrFile "${FullPath}")
name_title_default=$(removeExtension "${name_title_default}") name_title_default=$(removeExtension "${name_title_default}")
name_title_default=$(showFileWithSpace "${name_title_default}") name_title_default=$(showFileWithSpace "${name_title_default}")
# Ask name title, year and genre # Ask name title, year and genre
echo -n "* (Default: ${name_title_default}) Type name of title: " ; read name_title echo -n "* (Default: ${name_title_default}) Type name of title: " ; read name_title
if [ -z "${name_title}" ] ; then if [ -z "${name_title}" ] ; then
name_title="${name_title_default}" name_title="${name_title_default}"
else else
name_title="${name_title}" name_title="${name_title}"
fi fi
echo -n "* (Default: ${current_date}) Type the year: " ; read year_file echo -n "* (Default: ${current_date}) Type the year: " ; read year_file
if [ -z "${year_file}" ] ; then if [ -z "${year_file}" ] ; then
year_file="${current_date}" year_file="${current_date}"
else else
year_file="${year_file}" year_file="${year_file}"
fi fi
echo -n "* (Default: Unknown) Type the genre: " ; read genre_file echo -n "* (Default: Unknown) Type the genre: " ; read genre_file
if [ -z "${genre_file}" ] ; then if [ -z "${genre_file}" ] ; then
genre_file="Unknown" genre_file="Unknown"
else else
genre_file="${genre_file}" genre_file="${genre_file}"
fi fi
# Check audio 5.1 or 7.1 # Check audio 5.1 or 7.1
audio_5_7_1=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "${audio_track}" | grep -i "5.1") audio_5_7_1=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "${audio_track}" | grep -i "5.1")
audio_5_7_1_2=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "${audio_track}" | grep -i "7.1") audio_5_7_1_2=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "${audio_track}" | grep -i "7.1")
audio_5_7_1="${audio_5_7_1}${audio_5_7_1_2}" audio_5_7_1="${audio_5_7_1}${audio_5_7_1_2}"
if [ -z "${audio_5_7_1}" ] ; then if [ -z "${audio_5_7_1}" ] ; then
stereo_params="-ac 2" stereo_params="-ac 2"
else else
stereo_params="-ac 2 -clev 3dB -slev -6dB" stereo_params="-ac 2 -clev 3dB -slev -6dB"
fi fi
# Show commands for conversion # Show commands for conversion
echo "" echo ""
echo "* COMMANDS THAT WILL BE EXECUTED:" echo "* COMMANDS THAT WILL BE EXECUTED:"
echo "" echo ""
if [ "${subtitles_y_n}" == "y" ] ; then if [ "${subtitles_y_n}" == "y" ] ; then
echo " # Extract subtitles from file ${1}" echo " # Extract subtitles from file ${1}"
echo " ${p_ffmpeg} \"${1}\" -map ${subtitle_track} \"${2}.srt\"" echo " ${p_ffmpeg} \"${1}\" -map ${subtitle_track} \"${2}.srt\""
echo "" echo ""
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
echo " # Convert the file '${1}' to MP4" echo " # Convert the file '${1}' to MP4"
echo " ${p_ffmpeg} \"${1}\" ${f_conversion} -map ${video_track} -map ${audio_track} -vf subtitles=\"${2}.srt\" ${p_conversion} ${stereo_params} -metadata title=\"${name_title} (${year_file})\" -metadata date=\"${year_file}\" -metadata genre=\"${genre_file}\" -metadata:s:v:0 title=\"${name_title} (${year_file})\" -metadata:s:a:0 title=\"${acodec} Stereo Audio (${b_acodec})\" ${p_ffmpeg_patched} \"${2}.${v_ext}\"" echo " ${p_ffmpeg} \"${1}\" ${f_conversion} -map ${video_track} -map ${audio_track} -vf subtitles=\"${2}.srt\" ${p_conversion} ${stereo_params} -metadata title=\"${name_title} (${year_file})\" -metadata date=\"${year_file}\" -metadata genre=\"${genre_file}\" -metadata:s:v:0 title=\"${name_title} (${year_file})\" -metadata:s:a:0 title=\"${acodec} Stereo Audio (${b_acodec})\" ${p_ffmpeg_patched} \"${2}.${v_ext}\""
else else
echo " # Convert the file '${1}' to MP4" echo " # Convert the file '${1}' to MP4"
echo " ${p_ffmpeg} \"${1}\" ${f_conversion} -map ${video_track} -map ${audio_track} -vf subtitles=\"${2}.srt\" ${p_conversion} ${stereo_params} -metadata title=\"${name_title} (${year_file})\" -metadata date=\"${year_file}\" -metadata genre=\"${genre_file}\" -metadata:s:v:0 title=\"${name_title} (${year_file})\" -metadata:s:a:0 title=\"${acodec} Stereo Audio (${b_acodec})\" \"${2}.${v_ext}\"" echo " ${p_ffmpeg} \"${1}\" ${f_conversion} -map ${video_track} -map ${audio_track} -vf subtitles=\"${2}.srt\" ${p_conversion} ${stereo_params} -metadata title=\"${name_title} (${year_file})\" -metadata date=\"${year_file}\" -metadata genre=\"${genre_file}\" -metadata:s:v:0 title=\"${name_title} (${year_file})\" -metadata:s:a:0 title=\"${acodec} Stereo Audio (${b_acodec})\" \"${2}.${v_ext}\""
fi fi
else else
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
echo " # Convert the file '${1}' to MP4" echo " # Convert the file '${1}' to MP4"
echo " ${p_ffmpeg} \"${1}\" ${f_conversion} -map ${video_track} -map ${audio_track} ${p_conversion} ${stereo_params} -metadata title=\"${name_title} (${year_file})\" -metadata date=\"${year_file}\" -metadata genre=\"${genre_file}\" -metadata:s:v:0 title=\"${name_title} (${year_file})\" -metadata:s:a:0 title=\"${acodec} Stereo Audio (${b_acodec})\" ${p_ffmpeg_patched} \"${2}.${v_ext}\"" echo " ${p_ffmpeg} \"${1}\" ${f_conversion} -map ${video_track} -map ${audio_track} ${p_conversion} ${stereo_params} -metadata title=\"${name_title} (${year_file})\" -metadata date=\"${year_file}\" -metadata genre=\"${genre_file}\" -metadata:s:v:0 title=\"${name_title} (${year_file})\" -metadata:s:a:0 title=\"${acodec} Stereo Audio (${b_acodec})\" ${p_ffmpeg_patched} \"${2}.${v_ext}\""
else else
echo " # Convert the file '${1}' to MP4" echo " # Convert the file '${1}' to MP4"
echo " ${p_ffmpeg} \"${1}\" ${f_conversion} -map ${video_track} -map ${audio_track} ${p_conversion} ${stereo_params} -metadata title=\"${name_title} (${year_file})\" -metadata date=\"${year_file}\" -metadata genre=\"${genre_file}\" -metadata:s:v:0 title=\"${name_title} (${year_file})\" -metadata:s:a:0 title=\"${acodec} Stereo Audio (${b_acodec})\" \"${2}.${v_ext}\"" echo " ${p_ffmpeg} \"${1}\" ${f_conversion} -map ${video_track} -map ${audio_track} ${p_conversion} ${stereo_params} -metadata title=\"${name_title} (${year_file})\" -metadata date=\"${year_file}\" -metadata genre=\"${genre_file}\" -metadata:s:v:0 title=\"${name_title} (${year_file})\" -metadata:s:a:0 title=\"${acodec} Stereo Audio (${b_acodec})\" \"${2}.${v_ext}\""
fi fi
fi fi
# Execute commands for conversion # Execute commands for conversion
echo "" echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit exit
else else
if [ "${subtitles_y_n}" == "y" ] ; then if [ "${subtitles_y_n}" == "y" ] ; then
${p_ffmpeg} "${1}" -map ${subtitle_track} "${2}.srt" ${p_ffmpeg} "${1}" -map ${subtitle_track} "${2}.srt"
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
${p_ffmpeg} "${1}" ${f_conversion} -map ${video_track} -map ${audio_track} -vf subtitles="${2}.srt" ${p_conversion} ${stereo_params} -metadata title="${name_title} (${year_file})" -metadata date="${year_file}" -metadata genre="${genre_file}" -metadata:s:v:0 title="${name_title} (${year_file})" -metadata:s:a:0 title="${acodec} Stereo Audio (${b_acodec})" ${p_ffmpeg_patched} "${2}.${v_ext}" ${p_ffmpeg} "${1}" ${f_conversion} -map ${video_track} -map ${audio_track} -vf subtitles="${2}.srt" ${p_conversion} ${stereo_params} -metadata title="${name_title} (${year_file})" -metadata date="${year_file}" -metadata genre="${genre_file}" -metadata:s:v:0 title="${name_title} (${year_file})" -metadata:s:a:0 title="${acodec} Stereo Audio (${b_acodec})" ${p_ffmpeg_patched} "${2}.${v_ext}"
else else
${p_ffmpeg} "${1}" ${f_conversion} -map ${video_track} -map ${audio_track} -vf subtitles="${2}.srt" ${p_conversion} ${stereo_params} -metadata title="${name_title} (${year_file})" -metadata date="${year_file}" -metadata genre="${genre_file}" -metadata:s:v:0 title="${name_title} (${year_file})" -metadata:s:a:0 title="${acodec} Stereo Audio (${b_acodec})" "${2}.${v_ext}" ${p_ffmpeg} "${1}" ${f_conversion} -map ${video_track} -map ${audio_track} -vf subtitles="${2}.srt" ${p_conversion} ${stereo_params} -metadata title="${name_title} (${year_file})" -metadata date="${year_file}" -metadata genre="${genre_file}" -metadata:s:v:0 title="${name_title} (${year_file})" -metadata:s:a:0 title="${acodec} Stereo Audio (${b_acodec})" "${2}.${v_ext}"
fi fi
else else
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
${p_ffmpeg} "${1}" ${f_conversion} -map ${video_track} -map ${audio_track} ${p_conversion} ${stereo_params} -metadata title="${name_title} (${year_file})" -metadata date="${year_file}" -metadata genre="${genre_file}" -metadata:s:v:0 title="${name_title} (${year_file})" -metadata:s:a:0 title="${acodec} Stereo Audio (${b_acodec})" ${p_ffmpeg_patched} "${2}.${v_ext}" ${p_ffmpeg} "${1}" ${f_conversion} -map ${video_track} -map ${audio_track} ${p_conversion} ${stereo_params} -metadata title="${name_title} (${year_file})" -metadata date="${year_file}" -metadata genre="${genre_file}" -metadata:s:v:0 title="${name_title} (${year_file})" -metadata:s:a:0 title="${acodec} Stereo Audio (${b_acodec})" ${p_ffmpeg_patched} "${2}.${v_ext}"
else else
${p_ffmpeg} "${1}" ${f_conversion} -map ${video_track} -map ${audio_track} ${p_conversion} ${stereo_params} -metadata title="${name_title} (${year_file})" -metadata date="${year_file}" -metadata genre="${genre_file}" -metadata:s:v:0 title="${name_title} (${year_file})" -metadata:s:a:0 title="${acodec} Stereo Audio (${b_acodec})" "${2}.${v_ext}" ${p_ffmpeg} "${1}" ${f_conversion} -map ${video_track} -map ${audio_track} ${p_conversion} ${stereo_params} -metadata title="${name_title} (${year_file})" -metadata date="${year_file}" -metadata genre="${genre_file}" -metadata:s:v:0 title="${name_title} (${year_file})" -metadata:s:a:0 title="${acodec} Stereo Audio (${b_acodec})" "${2}.${v_ext}"
fi fi
fi fi
fi fi
fi fi

View File

@ -37,104 +37,104 @@ fi
ffmpeg_test=$(ffmpeg --help 2>&1) ffmpeg_test=$(ffmpeg --help 2>&1)
error_ffmpeg=$? error_ffmpeg=$?
if [ ${error_ffmpeg} -ne 0 ] ; then if [ ${error_ffmpeg} -ne 0 ] ; then
echo "" echo ""
echo "* ks-mp4k (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-mp4k (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "+ The 'ffmpeg' tool is not installed!" echo "+ The 'ffmpeg' tool is not installed!"
echo "" echo ""
exit exit
fi fi
# Funcion to show the name of file/folder from full path # Funcion to show the name of file/folder from full path
# Syntax: extractFolderOrFile <full/path/file.txt> # Syntax: extractFolderOrFile <full/path/file.txt>
function extractFolderOrFile() { function extractFolderOrFile() {
pathToExtract="${1}/" pathToExtract="${1}/"
findFolder=0 findFolder=0
count=1 count=1
nameFolder=$(echo ${pathToExtract} | cut -d "/" -f ${count}) nameFolder=$(echo ${pathToExtract} | cut -d "/" -f ${count})
count=$(expr $count + 1) count=$(expr $count + 1)
while [ ${findFolder} -eq 0 ] ; do while [ ${findFolder} -eq 0 ] ; do
nameFolderTemp=$(echo ${pathToExtract} | cut -d "/" -f ${count}) nameFolderTemp=$(echo ${pathToExtract} | cut -d "/" -f ${count})
if [ -z "${nameFolderTemp}" ] ; then if [ -z "${nameFolderTemp}" ] ; then
findFolder=1 findFolder=1
else else
nameFolder="${nameFolderTemp}" nameFolder="${nameFolderTemp}"
count=$(expr $count + 1) count=$(expr $count + 1)
fi fi
done done
echo "${nameFolder}" echo "${nameFolder}"
} }
# Function to remove extension from file # Function to remove extension from file
# Syntax: removeExtension "<text>" # Syntax: removeExtension "<text>"
function removeExtension() { function removeExtension() {
wordToConvert=${1} wordToConvert=${1}
ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt" ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt"
mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null
echo "${wordToConvert}" > ${ksToolsSedFile} echo "${wordToConvert}" > ${ksToolsSedFile}
# Remove extensions # Remove extensions
sed -i 's/.avi//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.avi//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mp4//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mp4//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mkv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mkv//g' "${ksToolsSedFile}" &> /dev/null
sed -i "s/.mov//g" "${ksToolsSedFile}" &> /dev/null sed -i "s/.mov//g" "${ksToolsSedFile}" &> /dev/null
sed -i 's/.vob//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.vob//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mpg//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mpg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mpeg//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mpeg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.wmv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.wmv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.ogv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.ogv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.webm//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.webm//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.flv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.flv//g' "${ksToolsSedFile}" &> /dev/null
# Show file without extension # Show file without extension
wordToConvert=$(cat ${ksToolsSedFile}) wordToConvert=$(cat ${ksToolsSedFile})
echo ${wordToConvert} echo ${wordToConvert}
} }
# Function to show files with spaces. # Function to show files with spaces.
# Syntax: showFileWithSpace <file number> # Syntax: showFileWithSpace <file number>
function showFileWithSpace() { function showFileWithSpace() {
echo "${1}" > ${dirTemp}/name.tmp echo "${1}" > ${dirTemp}/name.tmp
sed -i 's/_/ /g' ${dirTemp}/name.tmp sed -i 's/_/ /g' ${dirTemp}/name.tmp
DisplayName=$(cat ${dirTemp}/name.tmp) DisplayName=$(cat ${dirTemp}/name.tmp)
rm -rf ${dirTemp}/name.tmp rm -rf ${dirTemp}/name.tmp
echo ${DisplayName} echo ${DisplayName}
} }
# Syntax: ks-mp4k </absolute/path/video.mkv> </path/prefix_name> # Syntax: ks-mp4k </absolute/path/video.mkv> </path/prefix_name>
if [ -z "${1}" ] ; then if [ -z "${1}" ] ; then
echo "" echo ""
echo "* ks-mp4k (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-mp4k (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "- Convert video file(s) to compact and efficient MP4 (4K)" echo "- Convert video file(s) to compact and efficient MP4 (4K)"
echo "" echo ""
echo "+ Config:" echo "+ Config:"
echo "" echo ""
echo " - Resolution: ${rel_size}" echo " - Resolution: ${rel_size}"
echo " - Video codec: ${vcodec}" echo " - Video codec: ${vcodec}"
echo " - Bitrate video: ${b_vcodec}" echo " - Bitrate video: ${b_vcodec}"
echo " - Preset: ${v_preset}" echo " - Preset: ${v_preset}"
echo " - Audio codec: ${acodec} (stereo)" echo " - Audio codec: ${acodec} (stereo)"
echo " - Bitrate audio: ${b_acodec}" echo " - Bitrate audio: ${b_acodec}"
echo " - Default Audio: ${default_lang_audio}" echo " - Default Audio: ${default_lang_audio}"
echo " - Default Subtitle: ${default_lang_subt} (forced)" echo " - Default Subtitle: ${default_lang_subt} (forced)"
echo " - Container: ${v_ext}" echo " - Container: ${v_ext}"
echo "" echo ""
echo "+ Syntax: " echo "+ Syntax: "
echo "" echo ""
echo " $ ks-mp4k </absolute/path/video.mkv> </path/prefix_name>" echo " $ ks-mp4k </absolute/path/video.mkv> </path/prefix_name>"
echo "" echo ""
echo " + Example: ks-mp4k /data/movies/Example.mkv /data/converted/Example" echo " + Example: ks-mp4k /data/movies/Example.mkv /data/converted/Example"
echo "" echo ""
exit exit
fi fi
if [ -f "${1}" ] ; then if [ -f "${1}" ] ; then
echo "detected" > /dev/null echo "detected" > /dev/null
else else
echo "" echo ""
echo "* ks-mp4k (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-mp4k (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "* The file '${1}' does not exist!" echo "* The file '${1}' does not exist!"
echo "" echo ""
exit exit
fi fi
# Conversion parameters # Conversion parameters
@ -147,239 +147,239 @@ codec_hevc=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Video:" |
yuv420p10le=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | grep "yuv420p10le") yuv420p10le=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | grep "yuv420p10le")
codec_h265_hevc="${codec_h265}${codec_hevc}${yuv420p10le}" codec_h265_hevc="${codec_h265}${codec_hevc}${yuv420p10le}"
if [ -z "${codec_h265_hevc}" ] ; then if [ -z "${codec_h265_hevc}" ] ; then
p_conversion="-s ${rel_size} -c:v ${vcodec} -profile:v high -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec} -b:a ${b_acodec}" p_conversion="-s ${rel_size} -c:v ${vcodec} -profile:v high -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec} -b:a ${b_acodec}"
else else
p_conversion="-s ${rel_size} -c:v ${vcodec} -profile:v high -pix_fmt yuv420p -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec} -b:a ${b_acodec}" p_conversion="-s ${rel_size} -c:v ${vcodec} -profile:v high -pix_fmt yuv420p -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec} -b:a ${b_acodec}"
fi fi
# Init conversion file # Init conversion file
current_date=$(date +%Y) current_date=$(date +%Y)
if [ -z "${2}" ] ; then if [ -z "${2}" ] ; then
echo "" echo ""
echo "* ks-mp4k (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-mp4k (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "- Convert video file(s) to compact and efficient MP4 (4K)" echo "- Convert video file(s) to compact and efficient MP4 (4K)"
echo "" echo ""
echo "+ Config:" echo "+ Config:"
echo "" echo ""
echo " - Resolution: ${rel_size}" echo " - Resolution: ${rel_size}"
echo " - Video codec: ${vcodec}" echo " - Video codec: ${vcodec}"
echo " - Bitrate video: ${b_vcodec}" echo " - Bitrate video: ${b_vcodec}"
echo " - Preset: ${v_preset}" echo " - Preset: ${v_preset}"
echo " - Audio codec: ${acodec} (stereo)" echo " - Audio codec: ${acodec} (stereo)"
echo " - Bitrate audio: ${b_acodec}" echo " - Bitrate audio: ${b_acodec}"
echo " - Default Audio: ${default_lang_audio}" echo " - Default Audio: ${default_lang_audio}"
echo " - Default Subtitle: ${default_lang_subt} (forced)" echo " - Default Subtitle: ${default_lang_subt} (forced)"
echo " - Container: ${v_ext}" echo " - Container: ${v_ext}"
echo "" echo ""
echo "+ Syntax: " echo "+ Syntax: "
echo "" echo ""
echo " $ ks-mp4k </absolute/path/video.mkv> </path/prefix_name>" echo " $ ks-mp4k </absolute/path/video.mkv> </path/prefix_name>"
echo "" echo ""
echo " + Example: ks-mp4k /data/movies/Example.mkv /data/converted/Example" echo " + Example: ks-mp4k /data/movies/Example.mkv /data/converted/Example"
echo "" echo ""
exit exit
else else
echo "" echo ""
echo "* Information of ${1}:" echo "* Information of ${1}:"
echo "" echo ""
echo "+ Video Tracks:" echo "+ Video Tracks:"
${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | cut -d "," -f 1 ${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | cut -d "," -f 1
echo "" echo ""
echo "+ Audio Tracks:" echo "+ Audio Tracks:"
${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d "," -f 1 ${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d "," -f 1
echo "" echo ""
echo "+ Subtitle Tracks:" echo "+ Subtitle Tracks:"
${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Subtitle:" | cut -d "," -f 1 ${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Subtitle:" | cut -d "," -f 1
echo "" echo ""
# Check de video track by default # Check de video track by default
video_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1) video_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
if [ -z "${video_default}" ] ; then if [ -z "${video_default}" ] ; then
video_default="0:0" video_default="0:0"
else else
video_default_patch=$(echo ${video_default} | cut -c4) video_default_patch=$(echo ${video_default} | cut -c4)
if [ "${video_default_patch}" == ":" ] ; then if [ "${video_default_patch}" == ":" ] ; then
video_default=$(echo ${video_default} | cut -c1-3) video_default=$(echo ${video_default} | cut -c1-3)
else else
video_default="${video_default}" video_default="${video_default}"
fi fi
fi fi
# Ask for video # Ask for video
echo -n "* (Default: ${video_default}) Type the number of video track: " ; read video_track echo -n "* (Default: ${video_default}) Type the number of video track: " ; read video_track
if [ -z "${video_track}" ] ; then if [ -z "${video_track}" ] ; then
video_track="${video_default}" video_track="${video_default}"
else else
video_track="${video_track}" video_track="${video_track}"
fi fi
# Check the audio track by default # Check the audio track by default
audio_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "(${default_lang_audio})" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1) audio_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "(${default_lang_audio})" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
if [ -z "${audio_default}" ] ; then if [ -z "${audio_default}" ] ; then
audio_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1) audio_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
if [ -z "${audio_default}" ] ; then if [ -z "${audio_default}" ] ; then
audio_default="0:1" audio_default="0:1"
else else
audio_default_patch=$(echo ${audio_default} | cut -c4) audio_default_patch=$(echo ${audio_default} | cut -c4)
if [ "${audio_default_patch}" == ":" ] ; then if [ "${audio_default_patch}" == ":" ] ; then
audio_default=$(echo ${audio_default} | cut -c1-3) audio_default=$(echo ${audio_default} | cut -c1-3)
else else
audio_default="${audio_default}" audio_default="${audio_default}"
fi fi
fi fi
else else
audio_default_patch=$(echo ${audio_default} | cut -c4) audio_default_patch=$(echo ${audio_default} | cut -c4)
if [ "${audio_default_patch}" == ":" ] ; then if [ "${audio_default_patch}" == ":" ] ; then
audio_default=$(echo ${audio_default} | cut -c1-3) audio_default=$(echo ${audio_default} | cut -c1-3)
else else
audio_default="${audio_default}" audio_default="${audio_default}"
fi fi
fi fi
# Ask for audio # Ask for audio
echo -n "* (Default: ${audio_default}) Type the number of audio track: " ; read audio_track echo -n "* (Default: ${audio_default}) Type the number of audio track: " ; read audio_track
if [ -z "${audio_track}" ] ; then if [ -z "${audio_track}" ] ; then
audio_track="${audio_default}" audio_track="${audio_default}"
else else
audio_track="${audio_track}" audio_track="${audio_track}"
fi fi
# Check the subtitle track by default # Check the subtitle track by default
subtitle_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Subtitle:" | grep "(${default_lang_subt})" | grep "(forced)" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1) subtitle_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Subtitle:" | grep "(${default_lang_subt})" | grep "(forced)" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
if [ -z "${subtitle_default}" ] ; then if [ -z "${subtitle_default}" ] ; then
subtitle_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Subtitle:" | grep "(${default_lang_subt})" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1) subtitle_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Subtitle:" | grep "(${default_lang_subt})" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
if [ -z "${subtitle_default}" ] ; then if [ -z "${subtitle_default}" ] ; then
subtitle_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Subtitle:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1) subtitle_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Subtitle:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
if [ -z "${subtitle_default}" ] ; then if [ -z "${subtitle_default}" ] ; then
subtitle_default="0:3" subtitle_default="0:3"
else else
subtitle_default_patch=$(echo ${subtitle_default} | cut -c4) subtitle_default_patch=$(echo ${subtitle_default} | cut -c4)
if [ "${subtitle_default_patch}" == ":" ] ; then if [ "${subtitle_default_patch}" == ":" ] ; then
subtitle_default=$(echo ${subtitle_default} | cut -c1-3) subtitle_default=$(echo ${subtitle_default} | cut -c1-3)
else else
subtitle_default="${subtitle_default}" subtitle_default="${subtitle_default}"
fi fi
fi fi
else else
subtitle_default_patch=$(echo ${subtitle_default} | cut -c4) subtitle_default_patch=$(echo ${subtitle_default} | cut -c4)
if [ "${subtitle_default_patch}" == ":" ] ; then if [ "${subtitle_default_patch}" == ":" ] ; then
subtitle_default=$(echo ${subtitle_default} | cut -c1-3) subtitle_default=$(echo ${subtitle_default} | cut -c1-3)
else else
subtitle_default="${subtitle_default}" subtitle_default="${subtitle_default}"
fi fi
fi fi
else else
subtitle_default_patch=$(echo ${subtitle_default} | cut -c4) subtitle_default_patch=$(echo ${subtitle_default} | cut -c4)
if [ "${subtitle_default_patch}" == ":" ] ; then if [ "${subtitle_default_patch}" == ":" ] ; then
subtitle_default=$(echo ${subtitle_default} | cut -c1-3) subtitle_default=$(echo ${subtitle_default} | cut -c1-3)
else else
subtitle_default="${subtitle_default}" subtitle_default="${subtitle_default}"
fi fi
fi fi
# Ask for subtitle # Ask for subtitle
echo -n "* (Default: n) Do you want include subtitles? (y/n): " ; read subtitles_y_n echo -n "* (Default: n) Do you want include subtitles? (y/n): " ; read subtitles_y_n
if [ "${subtitles_y_n}" == "y" ] ; then if [ "${subtitles_y_n}" == "y" ] ; then
echo -n "* (Default: ${subtitle_default}) Type the number of subtitle track: " ; read subtitle_track echo -n "* (Default: ${subtitle_default}) Type the number of subtitle track: " ; read subtitle_track
if [ -z "${subtitle_track}" ] ; then if [ -z "${subtitle_track}" ] ; then
subtitle_track="${subtitle_default}" subtitle_track="${subtitle_default}"
else else
subtitle_track="${subtitle_track}" subtitle_track="${subtitle_track}"
fi fi
fi fi
echo -n "* (Default: ${rel_size}) Type the resolution: " ; read resolution echo -n "* (Default: ${rel_size}) Type the resolution: " ; read resolution
if [ -z "${resolution}" ] ; then if [ -z "${resolution}" ] ; then
resolution="${rel_size}" resolution="${rel_size}"
else else
rel_size="${resolution}" rel_size="${resolution}"
if [ -z "${codec_h265_hevc}" ] ; then if [ -z "${codec_h265_hevc}" ] ; then
p_conversion="-s ${rel_size} -c:v ${vcodec} -profile:v high -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec} -b:a ${b_acodec}" p_conversion="-s ${rel_size} -c:v ${vcodec} -profile:v high -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec} -b:a ${b_acodec}"
else else
p_conversion="-s ${rel_size} -c:v ${vcodec} -profile:v high -pix_fmt yuv420p -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec} -b:a ${b_acodec}" p_conversion="-s ${rel_size} -c:v ${vcodec} -profile:v high -pix_fmt yuv420p -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec} -b:a ${b_acodec}"
fi fi
fi fi
echo -n "* (Default: n) Do you want apply '-max_muxing_queue_size 9999' patch? (y/n): " ; read patch_thread echo -n "* (Default: n) Do you want apply '-max_muxing_queue_size 9999' patch? (y/n): " ; read patch_thread
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
patch_thread="y" patch_thread="y"
else else
patch_thread="n" patch_thread="n"
fi fi
echo "" echo ""
echo "* METADATA configuration:" echo "* METADATA configuration:"
echo "" echo ""
# Prepare name title by default # Prepare name title by default
FullPath="${1}" FullPath="${1}"
name_title_default=$(extractFolderOrFile "${FullPath}") name_title_default=$(extractFolderOrFile "${FullPath}")
name_title_default=$(removeExtension "${name_title_default}") name_title_default=$(removeExtension "${name_title_default}")
name_title_default=$(showFileWithSpace "${name_title_default}") name_title_default=$(showFileWithSpace "${name_title_default}")
# Ask name title, year and genre # Ask name title, year and genre
echo -n "* (Default: ${name_title_default}) Type name of title: " ; read name_title echo -n "* (Default: ${name_title_default}) Type name of title: " ; read name_title
if [ -z "${name_title}" ] ; then if [ -z "${name_title}" ] ; then
name_title="${name_title_default}" name_title="${name_title_default}"
else else
name_title="${name_title}" name_title="${name_title}"
fi fi
echo -n "* (Default: ${current_date}) Type the year: " ; read year_file echo -n "* (Default: ${current_date}) Type the year: " ; read year_file
if [ -z "${year_file}" ] ; then if [ -z "${year_file}" ] ; then
year_file="${current_date}" year_file="${current_date}"
else else
year_file="${year_file}" year_file="${year_file}"
fi fi
echo -n "* (Default: Unknown) Type the genre: " ; read genre_file echo -n "* (Default: Unknown) Type the genre: " ; read genre_file
if [ -z "${genre_file}" ] ; then if [ -z "${genre_file}" ] ; then
genre_file="Unknown" genre_file="Unknown"
else else
genre_file="${genre_file}" genre_file="${genre_file}"
fi fi
# Check audio 5.1 or 7.1 # Check audio 5.1 or 7.1
audio_5_7_1=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "${audio_track}" | grep -i "5.1") audio_5_7_1=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "${audio_track}" | grep -i "5.1")
audio_5_7_1_2=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "${audio_track}" | grep -i "7.1") audio_5_7_1_2=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "${audio_track}" | grep -i "7.1")
audio_5_7_1="${audio_5_7_1}${audio_5_7_1_2}" audio_5_7_1="${audio_5_7_1}${audio_5_7_1_2}"
if [ -z "${audio_5_7_1}" ] ; then if [ -z "${audio_5_7_1}" ] ; then
stereo_params="-ac 2" stereo_params="-ac 2"
else else
stereo_params="-ac 2 -clev 3dB -slev -6dB" stereo_params="-ac 2 -clev 3dB -slev -6dB"
fi fi
# Show commands for conversion # Show commands for conversion
echo "" echo ""
echo "* COMMANDS THAT WILL BE EXECUTED:" echo "* COMMANDS THAT WILL BE EXECUTED:"
echo "" echo ""
if [ "${subtitles_y_n}" == "y" ] ; then if [ "${subtitles_y_n}" == "y" ] ; then
echo " # Extract subtitles from file ${1}" echo " # Extract subtitles from file ${1}"
echo " ${p_ffmpeg} \"${1}\" -map ${subtitle_track} \"${2}.srt\"" echo " ${p_ffmpeg} \"${1}\" -map ${subtitle_track} \"${2}.srt\""
echo "" echo ""
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
echo " # Convert the file '${1}' to MP4" echo " # Convert the file '${1}' to MP4"
echo " ${p_ffmpeg} \"${1}\" ${f_conversion} -map ${video_track} -map ${audio_track} -vf subtitles=\"${2}.srt\" ${p_conversion} ${stereo_params} -metadata title=\"${name_title} (${year_file})\" -metadata date=\"${year_file}\" -metadata genre=\"${genre_file}\" -metadata:s:v:0 title=\"${name_title} (${year_file})\" -metadata:s:a:0 title=\"${acodec} Stereo Audio (${b_acodec})\" ${p_ffmpeg_patched} \"${2}.${v_ext}\"" echo " ${p_ffmpeg} \"${1}\" ${f_conversion} -map ${video_track} -map ${audio_track} -vf subtitles=\"${2}.srt\" ${p_conversion} ${stereo_params} -metadata title=\"${name_title} (${year_file})\" -metadata date=\"${year_file}\" -metadata genre=\"${genre_file}\" -metadata:s:v:0 title=\"${name_title} (${year_file})\" -metadata:s:a:0 title=\"${acodec} Stereo Audio (${b_acodec})\" ${p_ffmpeg_patched} \"${2}.${v_ext}\""
else else
echo " # Convert the file '${1}' to MP4" echo " # Convert the file '${1}' to MP4"
echo " ${p_ffmpeg} \"${1}\" ${f_conversion} -map ${video_track} -map ${audio_track} -vf subtitles=\"${2}.srt\" ${p_conversion} ${stereo_params} -metadata title=\"${name_title} (${year_file})\" -metadata date=\"${year_file}\" -metadata genre=\"${genre_file}\" -metadata:s:v:0 title=\"${name_title} (${year_file})\" -metadata:s:a:0 title=\"${acodec} Stereo Audio (${b_acodec})\" \"${2}.${v_ext}\"" echo " ${p_ffmpeg} \"${1}\" ${f_conversion} -map ${video_track} -map ${audio_track} -vf subtitles=\"${2}.srt\" ${p_conversion} ${stereo_params} -metadata title=\"${name_title} (${year_file})\" -metadata date=\"${year_file}\" -metadata genre=\"${genre_file}\" -metadata:s:v:0 title=\"${name_title} (${year_file})\" -metadata:s:a:0 title=\"${acodec} Stereo Audio (${b_acodec})\" \"${2}.${v_ext}\""
fi fi
else else
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
echo " # Convert the file '${1}' to MP4" echo " # Convert the file '${1}' to MP4"
echo " ${p_ffmpeg} \"${1}\" ${f_conversion} -map ${video_track} -map ${audio_track} ${p_conversion} ${stereo_params} -metadata title=\"${name_title} (${year_file})\" -metadata date=\"${year_file}\" -metadata genre=\"${genre_file}\" -metadata:s:v:0 title=\"${name_title} (${year_file})\" -metadata:s:a:0 title=\"${acodec} Stereo Audio (${b_acodec})\" ${p_ffmpeg_patched} \"${2}.${v_ext}\"" echo " ${p_ffmpeg} \"${1}\" ${f_conversion} -map ${video_track} -map ${audio_track} ${p_conversion} ${stereo_params} -metadata title=\"${name_title} (${year_file})\" -metadata date=\"${year_file}\" -metadata genre=\"${genre_file}\" -metadata:s:v:0 title=\"${name_title} (${year_file})\" -metadata:s:a:0 title=\"${acodec} Stereo Audio (${b_acodec})\" ${p_ffmpeg_patched} \"${2}.${v_ext}\""
else else
echo " # Convert the file '${1}' to MP4" echo " # Convert the file '${1}' to MP4"
echo " ${p_ffmpeg} \"${1}\" ${f_conversion} -map ${video_track} -map ${audio_track} ${p_conversion} ${stereo_params} -metadata title=\"${name_title} (${year_file})\" -metadata date=\"${year_file}\" -metadata genre=\"${genre_file}\" -metadata:s:v:0 title=\"${name_title} (${year_file})\" -metadata:s:a:0 title=\"${acodec} Stereo Audio (${b_acodec})\" \"${2}.${v_ext}\"" echo " ${p_ffmpeg} \"${1}\" ${f_conversion} -map ${video_track} -map ${audio_track} ${p_conversion} ${stereo_params} -metadata title=\"${name_title} (${year_file})\" -metadata date=\"${year_file}\" -metadata genre=\"${genre_file}\" -metadata:s:v:0 title=\"${name_title} (${year_file})\" -metadata:s:a:0 title=\"${acodec} Stereo Audio (${b_acodec})\" \"${2}.${v_ext}\""
fi fi
fi fi
# Execute commands for conversion # Execute commands for conversion
echo "" echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit exit
else else
if [ "${subtitles_y_n}" == "y" ] ; then if [ "${subtitles_y_n}" == "y" ] ; then
${p_ffmpeg} "${1}" -map ${subtitle_track} "${2}.srt" ${p_ffmpeg} "${1}" -map ${subtitle_track} "${2}.srt"
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
${p_ffmpeg} "${1}" ${f_conversion} -map ${video_track} -map ${audio_track} -vf subtitles="${2}.srt" ${p_conversion} ${stereo_params} -metadata title="${name_title} (${year_file})" -metadata date="${year_file}" -metadata genre="${genre_file}" -metadata:s:v:0 title="${name_title} (${year_file})" -metadata:s:a:0 title="${acodec} Stereo Audio (${b_acodec})" ${p_ffmpeg_patched} "${2}.${v_ext}" ${p_ffmpeg} "${1}" ${f_conversion} -map ${video_track} -map ${audio_track} -vf subtitles="${2}.srt" ${p_conversion} ${stereo_params} -metadata title="${name_title} (${year_file})" -metadata date="${year_file}" -metadata genre="${genre_file}" -metadata:s:v:0 title="${name_title} (${year_file})" -metadata:s:a:0 title="${acodec} Stereo Audio (${b_acodec})" ${p_ffmpeg_patched} "${2}.${v_ext}"
else else
${p_ffmpeg} "${1}" ${f_conversion} -map ${video_track} -map ${audio_track} -vf subtitles="${2}.srt" ${p_conversion} ${stereo_params} -metadata title="${name_title} (${year_file})" -metadata date="${year_file}" -metadata genre="${genre_file}" -metadata:s:v:0 title="${name_title} (${year_file})" -metadata:s:a:0 title="${acodec} Stereo Audio (${b_acodec})" "${2}.${v_ext}" ${p_ffmpeg} "${1}" ${f_conversion} -map ${video_track} -map ${audio_track} -vf subtitles="${2}.srt" ${p_conversion} ${stereo_params} -metadata title="${name_title} (${year_file})" -metadata date="${year_file}" -metadata genre="${genre_file}" -metadata:s:v:0 title="${name_title} (${year_file})" -metadata:s:a:0 title="${acodec} Stereo Audio (${b_acodec})" "${2}.${v_ext}"
fi fi
else else
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
${p_ffmpeg} "${1}" ${f_conversion} -map ${video_track} -map ${audio_track} ${p_conversion} ${stereo_params} -metadata title="${name_title} (${year_file})" -metadata date="${year_file}" -metadata genre="${genre_file}" -metadata:s:v:0 title="${name_title} (${year_file})" -metadata:s:a:0 title="${acodec} Stereo Audio (${b_acodec})" ${p_ffmpeg_patched} "${2}.${v_ext}" ${p_ffmpeg} "${1}" ${f_conversion} -map ${video_track} -map ${audio_track} ${p_conversion} ${stereo_params} -metadata title="${name_title} (${year_file})" -metadata date="${year_file}" -metadata genre="${genre_file}" -metadata:s:v:0 title="${name_title} (${year_file})" -metadata:s:a:0 title="${acodec} Stereo Audio (${b_acodec})" ${p_ffmpeg_patched} "${2}.${v_ext}"
else else
${p_ffmpeg} "${1}" ${f_conversion} -map ${video_track} -map ${audio_track} ${p_conversion} ${stereo_params} -metadata title="${name_title} (${year_file})" -metadata date="${year_file}" -metadata genre="${genre_file}" -metadata:s:v:0 title="${name_title} (${year_file})" -metadata:s:a:0 title="${acodec} Stereo Audio (${b_acodec})" "${2}.${v_ext}" ${p_ffmpeg} "${1}" ${f_conversion} -map ${video_track} -map ${audio_track} ${p_conversion} ${stereo_params} -metadata title="${name_title} (${year_file})" -metadata date="${year_file}" -metadata genre="${genre_file}" -metadata:s:v:0 title="${name_title} (${year_file})" -metadata:s:a:0 title="${acodec} Stereo Audio (${b_acodec})" "${2}.${v_ext}"
fi fi
fi fi
fi fi
fi fi

View File

@ -37,104 +37,104 @@ fi
ffmpeg_test=$(ffmpeg --help 2>&1) ffmpeg_test=$(ffmpeg --help 2>&1)
error_ffmpeg=$? error_ffmpeg=$?
if [ ${error_ffmpeg} -ne 0 ] ; then if [ ${error_ffmpeg} -ne 0 ] ; then
echo "" echo ""
echo "* ks-mp4s (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-mp4s (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "+ The 'ffmpeg' tool is not installed!" echo "+ The 'ffmpeg' tool is not installed!"
echo "" echo ""
exit exit
fi fi
# Funcion to show the name of file/folder from full path # Funcion to show the name of file/folder from full path
# Syntax: extractFolderOrFile <full/path/file.txt> # Syntax: extractFolderOrFile <full/path/file.txt>
function extractFolderOrFile() { function extractFolderOrFile() {
pathToExtract="${1}/" pathToExtract="${1}/"
findFolder=0 findFolder=0
count=1 count=1
nameFolder=$(echo ${pathToExtract} | cut -d "/" -f ${count}) nameFolder=$(echo ${pathToExtract} | cut -d "/" -f ${count})
count=$(expr $count + 1) count=$(expr $count + 1)
while [ ${findFolder} -eq 0 ] ; do while [ ${findFolder} -eq 0 ] ; do
nameFolderTemp=$(echo ${pathToExtract} | cut -d "/" -f ${count}) nameFolderTemp=$(echo ${pathToExtract} | cut -d "/" -f ${count})
if [ -z "${nameFolderTemp}" ] ; then if [ -z "${nameFolderTemp}" ] ; then
findFolder=1 findFolder=1
else else
nameFolder="${nameFolderTemp}" nameFolder="${nameFolderTemp}"
count=$(expr $count + 1) count=$(expr $count + 1)
fi fi
done done
echo "${nameFolder}" echo "${nameFolder}"
} }
# Function to remove extension from file # Function to remove extension from file
# Syntax: removeExtension "<text>" # Syntax: removeExtension "<text>"
function removeExtension() { function removeExtension() {
wordToConvert=${1} wordToConvert=${1}
ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt" ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt"
mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null
echo "${wordToConvert}" > ${ksToolsSedFile} echo "${wordToConvert}" > ${ksToolsSedFile}
# Remove extensions # Remove extensions
sed -i 's/.avi//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.avi//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mp4//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mp4//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mkv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mkv//g' "${ksToolsSedFile}" &> /dev/null
sed -i "s/.mov//g" "${ksToolsSedFile}" &> /dev/null sed -i "s/.mov//g" "${ksToolsSedFile}" &> /dev/null
sed -i 's/.vob//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.vob//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mpg//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mpg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mpeg//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mpeg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.wmv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.wmv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.ogv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.ogv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.webm//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.webm//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.flv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.flv//g' "${ksToolsSedFile}" &> /dev/null
# Show file without extension # Show file without extension
wordToConvert=$(cat ${ksToolsSedFile}) wordToConvert=$(cat ${ksToolsSedFile})
echo ${wordToConvert} echo ${wordToConvert}
} }
# Function to show files with spaces. # Function to show files with spaces.
# Syntax: showFileWithSpace <file number> # Syntax: showFileWithSpace <file number>
function showFileWithSpace() { function showFileWithSpace() {
echo "${1}" > ${dirTemp}/name.tmp echo "${1}" > ${dirTemp}/name.tmp
sed -i 's/_/ /g' ${dirTemp}/name.tmp sed -i 's/_/ /g' ${dirTemp}/name.tmp
DisplayName=$(cat ${dirTemp}/name.tmp) DisplayName=$(cat ${dirTemp}/name.tmp)
rm -rf ${dirTemp}/name.tmp rm -rf ${dirTemp}/name.tmp
echo ${DisplayName} echo ${DisplayName}
} }
# Syntax: ks-mp4s </absolute/path/video.mkv> </path/prefix_name> # Syntax: ks-mp4s </absolute/path/video.mkv> </path/prefix_name>
if [ -z "${1}" ] ; then if [ -z "${1}" ] ; then
echo "" echo ""
echo "* ks-mp4s (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-mp4s (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "- Convert video file(s) to compact and efficient MP4 (Series)" echo "- Convert video file(s) to compact and efficient MP4 (Series)"
echo "" echo ""
echo "+ Config:" echo "+ Config:"
echo "" echo ""
echo " - Resolution: ${rel_size}" echo " - Resolution: ${rel_size}"
echo " - Video codec: ${vcodec}" echo " - Video codec: ${vcodec}"
echo " - Bitrate video: ${b_vcodec}" echo " - Bitrate video: ${b_vcodec}"
echo " - Preset: ${v_preset}" echo " - Preset: ${v_preset}"
echo " - Audio codec: ${acodec} (stereo)" echo " - Audio codec: ${acodec} (stereo)"
echo " - Bitrate audio: ${b_acodec}" echo " - Bitrate audio: ${b_acodec}"
echo " - Default Audio: ${default_lang_audio}" echo " - Default Audio: ${default_lang_audio}"
echo " - Default Subtitle: ${default_lang_subt} (forced)" echo " - Default Subtitle: ${default_lang_subt} (forced)"
echo " - Container: ${v_ext}" echo " - Container: ${v_ext}"
echo "" echo ""
echo "+ Syntax: " echo "+ Syntax: "
echo "" echo ""
echo " $ ks-mp4s </absolute/path/video.mkv> </path/prefix_name>" echo " $ ks-mp4s </absolute/path/video.mkv> </path/prefix_name>"
echo "" echo ""
echo " + Example: ks-mp4s /data/movies/Example.mkv /data/converted/Example" echo " + Example: ks-mp4s /data/movies/Example.mkv /data/converted/Example"
echo "" echo ""
exit exit
fi fi
if [ -f "${1}" ] ; then if [ -f "${1}" ] ; then
echo "detected" > /dev/null echo "detected" > /dev/null
else else
echo "" echo ""
echo "* ks-mp4s (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-mp4s (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "* The file '${1}' does not exist!" echo "* The file '${1}' does not exist!"
echo "" echo ""
exit exit
fi fi
# Conversion parameters # Conversion parameters
@ -147,239 +147,239 @@ codec_hevc=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Video:" |
yuv420p10le=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | grep "yuv420p10le") yuv420p10le=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | grep "yuv420p10le")
codec_h265_hevc="${codec_h265}${codec_hevc}${yuv420p10le}" codec_h265_hevc="${codec_h265}${codec_hevc}${yuv420p10le}"
if [ -z "${codec_h265_hevc}" ] ; then if [ -z "${codec_h265_hevc}" ] ; then
p_conversion="-s ${rel_size} -c:v ${vcodec} -profile:v high -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec} -b:a ${b_acodec}" p_conversion="-s ${rel_size} -c:v ${vcodec} -profile:v high -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec} -b:a ${b_acodec}"
else else
p_conversion="-s ${rel_size} -c:v ${vcodec} -profile:v high -pix_fmt yuv420p -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec} -b:a ${b_acodec}" p_conversion="-s ${rel_size} -c:v ${vcodec} -profile:v high -pix_fmt yuv420p -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec} -b:a ${b_acodec}"
fi fi
# Init conversion file # Init conversion file
current_date=$(date +%Y) current_date=$(date +%Y)
if [ -z "${2}" ] ; then if [ -z "${2}" ] ; then
echo "" echo ""
echo "* ks-mp4s (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-mp4s (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "- Convert video file(s) to compact and efficient MP4 (Series)" echo "- Convert video file(s) to compact and efficient MP4 (Series)"
echo "" echo ""
echo "+ Config:" echo "+ Config:"
echo "" echo ""
echo " - Resolution: ${rel_size}" echo " - Resolution: ${rel_size}"
echo " - Video codec: ${vcodec}" echo " - Video codec: ${vcodec}"
echo " - Bitrate video: ${b_vcodec}" echo " - Bitrate video: ${b_vcodec}"
echo " - Preset: ${v_preset}" echo " - Preset: ${v_preset}"
echo " - Audio codec: ${acodec} (stereo)" echo " - Audio codec: ${acodec} (stereo)"
echo " - Bitrate audio: ${b_acodec}" echo " - Bitrate audio: ${b_acodec}"
echo " - Default Audio: ${default_lang_audio}" echo " - Default Audio: ${default_lang_audio}"
echo " - Default Subtitle: ${default_lang_subt} (forced)" echo " - Default Subtitle: ${default_lang_subt} (forced)"
echo " - Container: ${v_ext}" echo " - Container: ${v_ext}"
echo "" echo ""
echo "+ Syntax: " echo "+ Syntax: "
echo "" echo ""
echo " $ ks-mp4s </absolute/path/video.mkv> </path/prefix_name>" echo " $ ks-mp4s </absolute/path/video.mkv> </path/prefix_name>"
echo "" echo ""
echo " + Example: ks-mp4s /data/movies/Example.mkv /data/converted/Example" echo " + Example: ks-mp4s /data/movies/Example.mkv /data/converted/Example"
echo "" echo ""
exit exit
else else
echo "" echo ""
echo "* Information of ${1}:" echo "* Information of ${1}:"
echo "" echo ""
echo "+ Video Tracks:" echo "+ Video Tracks:"
${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | cut -d "," -f 1 ${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | cut -d "," -f 1
echo "" echo ""
echo "+ Audio Tracks:" echo "+ Audio Tracks:"
${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d "," -f 1 ${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d "," -f 1
echo "" echo ""
echo "+ Subtitle Tracks:" echo "+ Subtitle Tracks:"
${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Subtitle:" | cut -d "," -f 1 ${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Subtitle:" | cut -d "," -f 1
echo "" echo ""
# Check de video track by default # Check de video track by default
video_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1) video_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
if [ -z "${video_default}" ] ; then if [ -z "${video_default}" ] ; then
video_default="0:0" video_default="0:0"
else else
video_default_patch=$(echo ${video_default} | cut -c4) video_default_patch=$(echo ${video_default} | cut -c4)
if [ "${video_default_patch}" == ":" ] ; then if [ "${video_default_patch}" == ":" ] ; then
video_default=$(echo ${video_default} | cut -c1-3) video_default=$(echo ${video_default} | cut -c1-3)
else else
video_default="${video_default}" video_default="${video_default}"
fi fi
fi fi
# Ask for video # Ask for video
echo -n "* (Default: ${video_default}) Type the number of video track: " ; read video_track echo -n "* (Default: ${video_default}) Type the number of video track: " ; read video_track
if [ -z "${video_track}" ] ; then if [ -z "${video_track}" ] ; then
video_track="${video_default}" video_track="${video_default}"
else else
video_track="${video_track}" video_track="${video_track}"
fi fi
# Check the audio track by default # Check the audio track by default
audio_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "(${default_lang_audio})" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1) audio_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "(${default_lang_audio})" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
if [ -z "${audio_default}" ] ; then if [ -z "${audio_default}" ] ; then
audio_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1) audio_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
if [ -z "${audio_default}" ] ; then if [ -z "${audio_default}" ] ; then
audio_default="0:1" audio_default="0:1"
else else
audio_default_patch=$(echo ${audio_default} | cut -c4) audio_default_patch=$(echo ${audio_default} | cut -c4)
if [ "${audio_default_patch}" == ":" ] ; then if [ "${audio_default_patch}" == ":" ] ; then
audio_default=$(echo ${audio_default} | cut -c1-3) audio_default=$(echo ${audio_default} | cut -c1-3)
else else
audio_default="${audio_default}" audio_default="${audio_default}"
fi fi
fi fi
else else
audio_default_patch=$(echo ${audio_default} | cut -c4) audio_default_patch=$(echo ${audio_default} | cut -c4)
if [ "${audio_default_patch}" == ":" ] ; then if [ "${audio_default_patch}" == ":" ] ; then
audio_default=$(echo ${audio_default} | cut -c1-3) audio_default=$(echo ${audio_default} | cut -c1-3)
else else
audio_default="${audio_default}" audio_default="${audio_default}"
fi fi
fi fi
# Ask for audio # Ask for audio
echo -n "* (Default: ${audio_default}) Type the number of audio track: " ; read audio_track echo -n "* (Default: ${audio_default}) Type the number of audio track: " ; read audio_track
if [ -z "${audio_track}" ] ; then if [ -z "${audio_track}" ] ; then
audio_track="${audio_default}" audio_track="${audio_default}"
else else
audio_track="${audio_track}" audio_track="${audio_track}"
fi fi
# Check the subtitle track by default # Check the subtitle track by default
subtitle_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Subtitle:" | grep "(${default_lang_subt})" | grep "(forced)" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1) subtitle_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Subtitle:" | grep "(${default_lang_subt})" | grep "(forced)" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
if [ -z "${subtitle_default}" ] ; then if [ -z "${subtitle_default}" ] ; then
subtitle_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Subtitle:" | grep "(${default_lang_subt})" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1) subtitle_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Subtitle:" | grep "(${default_lang_subt})" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
if [ -z "${subtitle_default}" ] ; then if [ -z "${subtitle_default}" ] ; then
subtitle_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Subtitle:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1) subtitle_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Subtitle:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
if [ -z "${subtitle_default}" ] ; then if [ -z "${subtitle_default}" ] ; then
subtitle_default="0:3" subtitle_default="0:3"
else else
subtitle_default_patch=$(echo ${subtitle_default} | cut -c4) subtitle_default_patch=$(echo ${subtitle_default} | cut -c4)
if [ "${subtitle_default_patch}" == ":" ] ; then if [ "${subtitle_default_patch}" == ":" ] ; then
subtitle_default=$(echo ${subtitle_default} | cut -c1-3) subtitle_default=$(echo ${subtitle_default} | cut -c1-3)
else else
subtitle_default="${subtitle_default}" subtitle_default="${subtitle_default}"
fi fi
fi fi
else else
subtitle_default_patch=$(echo ${subtitle_default} | cut -c4) subtitle_default_patch=$(echo ${subtitle_default} | cut -c4)
if [ "${subtitle_default_patch}" == ":" ] ; then if [ "${subtitle_default_patch}" == ":" ] ; then
subtitle_default=$(echo ${subtitle_default} | cut -c1-3) subtitle_default=$(echo ${subtitle_default} | cut -c1-3)
else else
subtitle_default="${subtitle_default}" subtitle_default="${subtitle_default}"
fi fi
fi fi
else else
subtitle_default_patch=$(echo ${subtitle_default} | cut -c4) subtitle_default_patch=$(echo ${subtitle_default} | cut -c4)
if [ "${subtitle_default_patch}" == ":" ] ; then if [ "${subtitle_default_patch}" == ":" ] ; then
subtitle_default=$(echo ${subtitle_default} | cut -c1-3) subtitle_default=$(echo ${subtitle_default} | cut -c1-3)
else else
subtitle_default="${subtitle_default}" subtitle_default="${subtitle_default}"
fi fi
fi fi
# Ask for subtitle # Ask for subtitle
echo -n "* (Default: n) Do you want include subtitles? (y/n): " ; read subtitles_y_n echo -n "* (Default: n) Do you want include subtitles? (y/n): " ; read subtitles_y_n
if [ "${subtitles_y_n}" == "y" ] ; then if [ "${subtitles_y_n}" == "y" ] ; then
echo -n "* (Default: ${subtitle_default}) Type the number of subtitle track: " ; read subtitle_track echo -n "* (Default: ${subtitle_default}) Type the number of subtitle track: " ; read subtitle_track
if [ -z "${subtitle_track}" ] ; then if [ -z "${subtitle_track}" ] ; then
subtitle_track="${subtitle_default}" subtitle_track="${subtitle_default}"
else else
subtitle_track="${subtitle_track}" subtitle_track="${subtitle_track}"
fi fi
fi fi
echo -n "* (Default: ${rel_size}) Type the resolution: " ; read resolution echo -n "* (Default: ${rel_size}) Type the resolution: " ; read resolution
if [ -z "${resolution}" ] ; then if [ -z "${resolution}" ] ; then
resolution="${rel_size}" resolution="${rel_size}"
else else
rel_size="${resolution}" rel_size="${resolution}"
if [ -z "${codec_h265_hevc}" ] ; then if [ -z "${codec_h265_hevc}" ] ; then
p_conversion="-s ${rel_size} -c:v ${vcodec} -profile:v high -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec} -b:a ${b_acodec}" p_conversion="-s ${rel_size} -c:v ${vcodec} -profile:v high -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec} -b:a ${b_acodec}"
else else
p_conversion="-s ${rel_size} -c:v ${vcodec} -profile:v high -pix_fmt yuv420p -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec} -b:a ${b_acodec}" p_conversion="-s ${rel_size} -c:v ${vcodec} -profile:v high -pix_fmt yuv420p -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec} -b:a ${b_acodec}"
fi fi
fi fi
echo -n "* (Default: n) Do you want apply '-max_muxing_queue_size 9999' patch? (y/n): " ; read patch_thread echo -n "* (Default: n) Do you want apply '-max_muxing_queue_size 9999' patch? (y/n): " ; read patch_thread
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
patch_thread="y" patch_thread="y"
else else
patch_thread="n" patch_thread="n"
fi fi
echo "" echo ""
echo "* METADATA configuration:" echo "* METADATA configuration:"
echo "" echo ""
# Prepare name title by default # Prepare name title by default
FullPath="${1}" FullPath="${1}"
name_title_default=$(extractFolderOrFile "${FullPath}") name_title_default=$(extractFolderOrFile "${FullPath}")
name_title_default=$(removeExtension "${name_title_default}") name_title_default=$(removeExtension "${name_title_default}")
name_title_default=$(showFileWithSpace "${name_title_default}") name_title_default=$(showFileWithSpace "${name_title_default}")
# Ask name title, year and genre # Ask name title, year and genre
echo -n "* (Default: ${name_title_default}) Type name of title: " ; read name_title echo -n "* (Default: ${name_title_default}) Type name of title: " ; read name_title
if [ -z "${name_title}" ] ; then if [ -z "${name_title}" ] ; then
name_title="${name_title_default}" name_title="${name_title_default}"
else else
name_title="${name_title}" name_title="${name_title}"
fi fi
echo -n "* (Default: ${current_date}) Type the year: " ; read year_file echo -n "* (Default: ${current_date}) Type the year: " ; read year_file
if [ -z "${year_file}" ] ; then if [ -z "${year_file}" ] ; then
year_file="${current_date}" year_file="${current_date}"
else else
year_file="${year_file}" year_file="${year_file}"
fi fi
echo -n "* (Default: Unknown) Type the genre: " ; read genre_file echo -n "* (Default: Unknown) Type the genre: " ; read genre_file
if [ -z "${genre_file}" ] ; then if [ -z "${genre_file}" ] ; then
genre_file="Unknown" genre_file="Unknown"
else else
genre_file="${genre_file}" genre_file="${genre_file}"
fi fi
# Check audio 5.1 or 7.1 # Check audio 5.1 or 7.1
audio_5_7_1=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "${audio_track}" | grep -i "5.1") audio_5_7_1=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "${audio_track}" | grep -i "5.1")
audio_5_7_1_2=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "${audio_track}" | grep -i "7.1") audio_5_7_1_2=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "${audio_track}" | grep -i "7.1")
audio_5_7_1="${audio_5_7_1}${audio_5_7_1_2}" audio_5_7_1="${audio_5_7_1}${audio_5_7_1_2}"
if [ -z "${audio_5_7_1}" ] ; then if [ -z "${audio_5_7_1}" ] ; then
stereo_params="-ac 2" stereo_params="-ac 2"
else else
stereo_params="-ac 2 -clev 3dB -slev -6dB" stereo_params="-ac 2 -clev 3dB -slev -6dB"
fi fi
# Show commands for conversion # Show commands for conversion
echo "" echo ""
echo "* COMMANDS THAT WILL BE EXECUTED:" echo "* COMMANDS THAT WILL BE EXECUTED:"
echo "" echo ""
if [ "${subtitles_y_n}" == "y" ] ; then if [ "${subtitles_y_n}" == "y" ] ; then
echo " # Extract subtitles from file ${1}" echo " # Extract subtitles from file ${1}"
echo " ${p_ffmpeg} \"${1}\" -map ${subtitle_track} \"${2}.srt\"" echo " ${p_ffmpeg} \"${1}\" -map ${subtitle_track} \"${2}.srt\""
echo "" echo ""
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
echo " # Convert the file '${1}' to MP4" echo " # Convert the file '${1}' to MP4"
echo " ${p_ffmpeg} \"${1}\" ${f_conversion} -map ${video_track} -map ${audio_track} -vf subtitles=\"${2}.srt\" ${p_conversion} ${stereo_params} -metadata title=\"${name_title}\" -metadata date=\"${year_file}\" -metadata genre=\"${genre_file}\" -metadata:s:v:0 title=\"${name_title}\" -metadata:s:a:0 title=\"${acodec} Stereo Audio (${b_acodec})\" ${p_ffmpeg_patched} \"${2}.${v_ext}\"" echo " ${p_ffmpeg} \"${1}\" ${f_conversion} -map ${video_track} -map ${audio_track} -vf subtitles=\"${2}.srt\" ${p_conversion} ${stereo_params} -metadata title=\"${name_title}\" -metadata date=\"${year_file}\" -metadata genre=\"${genre_file}\" -metadata:s:v:0 title=\"${name_title}\" -metadata:s:a:0 title=\"${acodec} Stereo Audio (${b_acodec})\" ${p_ffmpeg_patched} \"${2}.${v_ext}\""
else else
echo " # Convert the file '${1}' to MP4" echo " # Convert the file '${1}' to MP4"
echo " ${p_ffmpeg} \"${1}\" ${f_conversion} -map ${video_track} -map ${audio_track} -vf subtitles=\"${2}.srt\" ${p_conversion} ${stereo_params} -metadata title=\"${name_title}\" -metadata date=\"${year_file}\" -metadata genre=\"${genre_file}\" -metadata:s:v:0 title=\"${name_title}\" -metadata:s:a:0 title=\"${acodec} Stereo Audio (${b_acodec})\" \"${2}.${v_ext}\"" echo " ${p_ffmpeg} \"${1}\" ${f_conversion} -map ${video_track} -map ${audio_track} -vf subtitles=\"${2}.srt\" ${p_conversion} ${stereo_params} -metadata title=\"${name_title}\" -metadata date=\"${year_file}\" -metadata genre=\"${genre_file}\" -metadata:s:v:0 title=\"${name_title}\" -metadata:s:a:0 title=\"${acodec} Stereo Audio (${b_acodec})\" \"${2}.${v_ext}\""
fi fi
else else
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
echo " # Convert the file '${1}' to MP4" echo " # Convert the file '${1}' to MP4"
echo " ${p_ffmpeg} \"${1}\" ${f_conversion} -map ${video_track} -map ${audio_track} ${p_conversion} ${stereo_params} -metadata title=\"${name_title}\" -metadata date=\"${year_file}\" -metadata genre=\"${genre_file}\" -metadata:s:v:0 title=\"${name_title}\" -metadata:s:a:0 title=\"${acodec} Stereo Audio (${b_acodec})\" ${p_ffmpeg_patched} \"${2}.${v_ext}\"" echo " ${p_ffmpeg} \"${1}\" ${f_conversion} -map ${video_track} -map ${audio_track} ${p_conversion} ${stereo_params} -metadata title=\"${name_title}\" -metadata date=\"${year_file}\" -metadata genre=\"${genre_file}\" -metadata:s:v:0 title=\"${name_title}\" -metadata:s:a:0 title=\"${acodec} Stereo Audio (${b_acodec})\" ${p_ffmpeg_patched} \"${2}.${v_ext}\""
else else
echo " # Convert the file '${1}' to MP4" echo " # Convert the file '${1}' to MP4"
echo " ${p_ffmpeg} \"${1}\" ${f_conversion} -map ${video_track} -map ${audio_track} ${p_conversion} ${stereo_params} -metadata title=\"${name_title}\" -metadata date=\"${year_file}\" -metadata genre=\"${genre_file}\" -metadata:s:v:0 title=\"${name_title}\" -metadata:s:a:0 title=\"${acodec} Stereo Audio (${b_acodec})\" \"${2}.${v_ext}\"" echo " ${p_ffmpeg} \"${1}\" ${f_conversion} -map ${video_track} -map ${audio_track} ${p_conversion} ${stereo_params} -metadata title=\"${name_title}\" -metadata date=\"${year_file}\" -metadata genre=\"${genre_file}\" -metadata:s:v:0 title=\"${name_title}\" -metadata:s:a:0 title=\"${acodec} Stereo Audio (${b_acodec})\" \"${2}.${v_ext}\""
fi fi
fi fi
# Execute commands for conversion # Execute commands for conversion
echo "" echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit exit
else else
if [ "${subtitles_y_n}" == "y" ] ; then if [ "${subtitles_y_n}" == "y" ] ; then
${p_ffmpeg} "${1}" -map ${subtitle_track} "${2}.srt" ${p_ffmpeg} "${1}" -map ${subtitle_track} "${2}.srt"
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
${p_ffmpeg} "${1}" ${f_conversion} -map ${video_track} -map ${audio_track} -vf subtitles="${2}.srt" ${p_conversion} ${stereo_params} -metadata title="${name_title}" -metadata date="${year_file}" -metadata genre="${genre_file}" -metadata:s:v:0 title="${name_title}" -metadata:s:a:0 title="${acodec} Stereo Audio (${b_acodec})" ${p_ffmpeg_patched} "${2}.${v_ext}" ${p_ffmpeg} "${1}" ${f_conversion} -map ${video_track} -map ${audio_track} -vf subtitles="${2}.srt" ${p_conversion} ${stereo_params} -metadata title="${name_title}" -metadata date="${year_file}" -metadata genre="${genre_file}" -metadata:s:v:0 title="${name_title}" -metadata:s:a:0 title="${acodec} Stereo Audio (${b_acodec})" ${p_ffmpeg_patched} "${2}.${v_ext}"
else else
${p_ffmpeg} "${1}" ${f_conversion} -map ${video_track} -map ${audio_track} -vf subtitles="${2}.srt" ${p_conversion} ${stereo_params} -metadata title="${name_title}" -metadata date="${year_file}" -metadata genre="${genre_file}" -metadata:s:v:0 title="${name_title}" -metadata:s:a:0 title="${acodec} Stereo Audio (${b_acodec})" "${2}.${v_ext}" ${p_ffmpeg} "${1}" ${f_conversion} -map ${video_track} -map ${audio_track} -vf subtitles="${2}.srt" ${p_conversion} ${stereo_params} -metadata title="${name_title}" -metadata date="${year_file}" -metadata genre="${genre_file}" -metadata:s:v:0 title="${name_title}" -metadata:s:a:0 title="${acodec} Stereo Audio (${b_acodec})" "${2}.${v_ext}"
fi fi
else else
if [ "${patch_thread}" == "y" ] ; then if [ "${patch_thread}" == "y" ] ; then
${p_ffmpeg} "${1}" ${f_conversion} -map ${video_track} -map ${audio_track} ${p_conversion} ${stereo_params} -metadata title="${name_title}" -metadata date="${year_file}" -metadata genre="${genre_file}" -metadata:s:v:0 title="${name_title}" -metadata:s:a:0 title="${acodec} Stereo Audio (${b_acodec})" ${p_ffmpeg_patched} "${2}.${v_ext}" ${p_ffmpeg} "${1}" ${f_conversion} -map ${video_track} -map ${audio_track} ${p_conversion} ${stereo_params} -metadata title="${name_title}" -metadata date="${year_file}" -metadata genre="${genre_file}" -metadata:s:v:0 title="${name_title}" -metadata:s:a:0 title="${acodec} Stereo Audio (${b_acodec})" ${p_ffmpeg_patched} "${2}.${v_ext}"
else else
${p_ffmpeg} "${1}" ${f_conversion} -map ${video_track} -map ${audio_track} ${p_conversion} ${stereo_params} -metadata title="${name_title}" -metadata date="${year_file}" -metadata genre="${genre_file}" -metadata:s:v:0 title="${name_title}" -metadata:s:a:0 title="${acodec} Stereo Audio (${b_acodec})" "${2}.${v_ext}" ${p_ffmpeg} "${1}" ${f_conversion} -map ${video_track} -map ${audio_track} ${p_conversion} ${stereo_params} -metadata title="${name_title}" -metadata date="${year_file}" -metadata genre="${genre_file}" -metadata:s:v:0 title="${name_title}" -metadata:s:a:0 title="${acodec} Stereo Audio (${b_acodec})" "${2}.${v_ext}"
fi fi
fi fi
fi fi
fi fi

View File

@ -30,121 +30,121 @@ fi
ffmpeg_test=$(ffmpeg --help 2>&1) ffmpeg_test=$(ffmpeg --help 2>&1)
error_ffmpeg=$? error_ffmpeg=$?
if [ ${error_ffmpeg} -ne 0 ] ; then if [ ${error_ffmpeg} -ne 0 ] ; then
echo "" echo ""
echo "* ks-oga (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-oga (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "+ The 'ffmpeg' tool is not installed!" echo "+ The 'ffmpeg' tool is not installed!"
echo "" echo ""
exit exit
fi fi
# Funcion to show the name of file/folder from full path # Funcion to show the name of file/folder from full path
# Syntax: extractFolderOrFile <full/path/file.txt> # Syntax: extractFolderOrFile <full/path/file.txt>
function extractFolderOrFile() { function extractFolderOrFile() {
pathToExtract="${1}/" pathToExtract="${1}/"
findFolder=0 findFolder=0
count=1 count=1
nameFolder=$(echo ${pathToExtract} | cut -d "/" -f ${count}) nameFolder=$(echo ${pathToExtract} | cut -d "/" -f ${count})
count=$(expr $count + 1) count=$(expr $count + 1)
while [ ${findFolder} -eq 0 ] ; do while [ ${findFolder} -eq 0 ] ; do
nameFolderTemp=$(echo ${pathToExtract} | cut -d "/" -f ${count}) nameFolderTemp=$(echo ${pathToExtract} | cut -d "/" -f ${count})
if [ -z "${nameFolderTemp}" ] ; then if [ -z "${nameFolderTemp}" ] ; then
findFolder=1 findFolder=1
else else
nameFolder="${nameFolderTemp}" nameFolder="${nameFolderTemp}"
count=$(expr $count + 1) count=$(expr $count + 1)
fi fi
done done
echo "${nameFolder}" echo "${nameFolder}"
} }
# Function to remove extension from file # Function to remove extension from file
# Syntax: removeExtension "<text>" # Syntax: removeExtension "<text>"
function removeExtension() { function removeExtension() {
wordToConvert=${1} wordToConvert=${1}
ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt" ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt"
mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null
echo "${wordToConvert}" > ${ksToolsSedFile} echo "${wordToConvert}" > ${ksToolsSedFile}
# Remove extensions # Remove extensions
sed -i 's/.avi//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.avi//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mp4//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mp4//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mkv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mkv//g' "${ksToolsSedFile}" &> /dev/null
sed -i "s/.mov//g" "${ksToolsSedFile}" &> /dev/null sed -i "s/.mov//g" "${ksToolsSedFile}" &> /dev/null
sed -i 's/.vob//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.vob//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mpg//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mpg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mpeg//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mpeg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.wmv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.wmv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.ogv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.ogv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.webm//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.webm//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.flv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.flv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mp3//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mp3//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mp2//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mp2//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.oga//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.oga//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.ogg//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.ogg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.ac3//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.ac3//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.aac//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.aac//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.flac//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.flac//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.wav//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.wav//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.opus//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.opus//g' "${ksToolsSedFile}" &> /dev/null
# Show file without extension # Show file without extension
wordToConvert=$(cat ${ksToolsSedFile}) wordToConvert=$(cat ${ksToolsSedFile})
echo ${wordToConvert} echo ${wordToConvert}
} }
# Function to show files with spaces. # Function to show files with spaces.
# Syntax: showFileWithSpace <file number> # Syntax: showFileWithSpace <file number>
function showFileWithSpace() { function showFileWithSpace() {
echo "${1}" > ${dirTemp}/name.tmp echo "${1}" > ${dirTemp}/name.tmp
sed -i 's/_/ /g' ${dirTemp}/name.tmp sed -i 's/_/ /g' ${dirTemp}/name.tmp
DisplayName=$(cat ${dirTemp}/name.tmp) DisplayName=$(cat ${dirTemp}/name.tmp)
rm -rf ${dirTemp}/name.tmp rm -rf ${dirTemp}/name.tmp
cutDisplayName=$(echo ${DisplayName} | cut -c1) cutDisplayName=$(echo ${DisplayName} | cut -c1)
if [ "${cutDisplayName}" == "-" ] ; then if [ "${cutDisplayName}" == "-" ] ; then
DisplayName=$(echo ${DisplayName} | cut -c2-100) DisplayName=$(echo ${DisplayName} | cut -c2-100)
else else
cutDisplayName=$(echo ${DisplayName} | cut -c2) cutDisplayName=$(echo ${DisplayName} | cut -c2)
if [ "${cutDisplayName}" == "-" ] ; then if [ "${cutDisplayName}" == "-" ] ; then
DisplayName=$(echo ${DisplayName} | cut -c3-100) DisplayName=$(echo ${DisplayName} | cut -c3-100)
else else
cutDisplayName=$(echo ${DisplayName} | cut -c3) cutDisplayName=$(echo ${DisplayName} | cut -c3)
if [ "${cutDisplayName}" == "-" ] ; then if [ "${cutDisplayName}" == "-" ] ; then
DisplayName=$(echo ${DisplayName} | cut -c4-100) DisplayName=$(echo ${DisplayName} | cut -c4-100)
fi fi
fi fi
fi fi
echo ${DisplayName} echo ${DisplayName}
} }
# Syntax: ks-oga </absolute/path/song.mp3> </path/prefix_name> # Syntax: ks-oga </absolute/path/song.mp3> </path/prefix_name>
if [ -z "${1}" ] ; then if [ -z "${1}" ] ; then
echo "" echo ""
echo "* ks-oga (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-oga (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "- Convert video/audio file(s) to OGA (OGG Audio) Format" echo "- Convert video/audio file(s) to OGA (OGG Audio) Format"
echo "" echo ""
echo "+ Config:" echo "+ Config:"
echo "" echo ""
echo " - Audio codec: ${acodec}" echo " - Audio codec: ${acodec}"
echo " - Bitrate audio: ${b_acodec}" echo " - Bitrate audio: ${b_acodec}"
echo " - Container: ${v_ext}" echo " - Container: ${v_ext}"
echo "" echo ""
echo "+ Syntax: " echo "+ Syntax: "
echo "" echo ""
echo " $ ks-oga </absolute/path/song.mp3> </path/prefix_name>" echo " $ ks-oga </absolute/path/song.mp3> </path/prefix_name>"
echo "" echo ""
echo " + Example: ks-oga /data/songs/Example.mp3 /data/converted/Example" echo " + Example: ks-oga /data/songs/Example.mp3 /data/converted/Example"
echo "" echo ""
exit exit
fi fi
if [ -f "${1}" ] ; then if [ -f "${1}" ] ; then
echo "detected" > /dev/null echo "detected" > /dev/null
else else
echo "" echo ""
echo "* ks-oga (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-oga (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "* The file '${1}' does not exist!" echo "* The file '${1}' does not exist!"
echo "" echo ""
exit exit
fi fi
# Conversion parameters # Conversion parameters
@ -153,132 +153,132 @@ p_ffmpeg="ffmpeg -i"
# Init conversion file # Init conversion file
current_date=$(date +%Y) current_date=$(date +%Y)
if [ -z "${2}" ] ; then if [ -z "${2}" ] ; then
echo "" echo ""
echo "* ks-oga (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-oga (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "- Convert video/audio file(s) to OGA (OGG Audio) Format" echo "- Convert video/audio file(s) to OGA (OGG Audio) Format"
echo "" echo ""
echo "+ Config:" echo "+ Config:"
echo "" echo ""
echo " - Audio codec: ${acodec}" echo " - Audio codec: ${acodec}"
echo " - Bitrate audio: ${b_acodec}" echo " - Bitrate audio: ${b_acodec}"
echo " - Container: ${v_ext}" echo " - Container: ${v_ext}"
echo "" echo ""
echo "+ Syntax: " echo "+ Syntax: "
echo "" echo ""
echo " $ ks-oga </absolute/path/song.mp3> </path/prefix_name>" echo " $ ks-oga </absolute/path/song.mp3> </path/prefix_name>"
echo "" echo ""
echo " + Example: ks-oga /data/songs/Example.mp3 /data/converted/Example" echo " + Example: ks-oga /data/songs/Example.mp3 /data/converted/Example"
echo "" echo ""
exit exit
else else
echo "" echo ""
echo "* Information of ${1}:" echo "* Information of ${1}:"
echo "" echo ""
echo "+ Audio Tracks:" echo "+ Audio Tracks:"
${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d "," -f 1 ${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d "," -f 1
echo "" echo ""
# Check the audio track by default # Check the audio track by default
audio_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "(${default_lang_audio})" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1) audio_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "(${default_lang_audio})" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
if [ -z "${audio_default}" ] ; then if [ -z "${audio_default}" ] ; then
audio_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1) audio_default=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
if [ -z "${audio_default}" ] ; then if [ -z "${audio_default}" ] ; then
audio_default="0:1" audio_default="0:1"
else else
audio_default_patch=$(echo ${audio_default} | cut -c4) audio_default_patch=$(echo ${audio_default} | cut -c4)
if [ "${audio_default_patch}" == ":" ] ; then if [ "${audio_default_patch}" == ":" ] ; then
audio_default=$(echo ${audio_default} | cut -c1-3) audio_default=$(echo ${audio_default} | cut -c1-3)
else else
audio_default="${audio_default}" audio_default="${audio_default}"
fi fi
fi fi
else else
audio_default_patch=$(echo ${audio_default} | cut -c4) audio_default_patch=$(echo ${audio_default} | cut -c4)
if [ "${audio_default_patch}" == ":" ] ; then if [ "${audio_default_patch}" == ":" ] ; then
audio_default=$(echo ${audio_default} | cut -c1-3) audio_default=$(echo ${audio_default} | cut -c1-3)
else else
audio_default="${audio_default}" audio_default="${audio_default}"
fi fi
fi fi
# Ask for audio # Ask for audio
echo -n "* (Default: ${audio_default}) Type the number of audio track: " ; read audio_track echo -n "* (Default: ${audio_default}) Type the number of audio track: " ; read audio_track
if [ -z "${audio_track}" ] ; then if [ -z "${audio_track}" ] ; then
audio_track="${audio_default}" audio_track="${audio_default}"
else else
audio_track="${audio_track}" audio_track="${audio_track}"
fi fi
# Ask for METADATA # Ask for METADATA
echo "" echo ""
echo "* METADATA configuration:" echo "* METADATA configuration:"
echo "" echo ""
# Prepare name title by default # Prepare name title by default
FullPath="${1}" FullPath="${1}"
name_title_default=$(extractFolderOrFile "${FullPath}") name_title_default=$(extractFolderOrFile "${FullPath}")
name_title_default=$(removeExtension "${name_title_default}") name_title_default=$(removeExtension "${name_title_default}")
name_title_default=$(showFileWithSpace "${name_title_default}") name_title_default=$(showFileWithSpace "${name_title_default}")
# Ask name title, year and genre # Ask name title, year and genre
echo -n "* (Default: ${name_title_default}) Type name of title: " ; read name_title echo -n "* (Default: ${name_title_default}) Type name of title: " ; read name_title
if [ -z "${name_title}" ] ; then if [ -z "${name_title}" ] ; then
name_title="${name_title_default}" name_title="${name_title_default}"
else else
name_title="${name_title}" name_title="${name_title}"
fi fi
echo -n "* (Default: Album-Disc) Type name of album: " ; read album_file echo -n "* (Default: Album-Disc) Type name of album: " ; read album_file
if [ -z "${album_file}" ] ; then if [ -z "${album_file}" ] ; then
album_title="Album-Disc" album_title="Album-Disc"
else else
album_title="${album_file}" album_title="${album_file}"
fi fi
echo -n "* (Default: 01) Type number of track: " ; read track_file echo -n "* (Default: 01) Type number of track: " ; read track_file
if [ -z "${track_file}" ] ; then if [ -z "${track_file}" ] ; then
track_num="01" track_num="01"
else else
track_num="${track_file}" track_num="${track_file}"
fi fi
echo -n "* (Default: Artist) Type name of artist: " ; read artist_file echo -n "* (Default: Artist) Type name of artist: " ; read artist_file
if [ -z "${artist_file}" ] ; then if [ -z "${artist_file}" ] ; then
artist_title="Artist" artist_title="Artist"
else else
artist_title="${artist_file}" artist_title="${artist_file}"
fi fi
echo -n "* (Default: ${current_date}) Type the year: " ; read year_file echo -n "* (Default: ${current_date}) Type the year: " ; read year_file
if [ -z "${year_file}" ] ; then if [ -z "${year_file}" ] ; then
year_num="${current_date}" year_num="${current_date}"
else else
year_num="${year_file}" year_num="${year_file}"
fi fi
echo -n "* (Default: Pop) Type the genre: " ; read genre_file echo -n "* (Default: Pop) Type the genre: " ; read genre_file
if [ -z "${genre_file}" ] ; then if [ -z "${genre_file}" ] ; then
genre_file="Pop" genre_file="Pop"
else else
genre_file="${genre_file}" genre_file="${genre_file}"
fi fi
# Check audio 5.1 or 7.1 # Check audio 5.1 or 7.1
audio_5_7_1=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "${audio_track}" | grep -i "5.1") audio_5_7_1=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "${audio_track}" | grep -i "5.1")
audio_5_7_1_2=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "${audio_track}" | grep -i "7.1") audio_5_7_1_2=$(${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "${audio_track}" | grep -i "7.1")
audio_5_7_1="${audio_5_7_1}${audio_5_7_1_2}" audio_5_7_1="${audio_5_7_1}${audio_5_7_1_2}"
if [ -z "${audio_5_7_1}" ] ; then if [ -z "${audio_5_7_1}" ] ; then
stereo_params="-ac 2" stereo_params="-ac 2"
else else
stereo_params="-ac 2 -clev 3dB -slev -6dB" stereo_params="-ac 2 -clev 3dB -slev -6dB"
fi fi
# Show commands for conversion # Show commands for conversion
echo "" echo ""
echo "* COMMANDS THAT WILL BE EXECUTED:" echo "* COMMANDS THAT WILL BE EXECUTED:"
echo "" echo ""
echo " # Convert the file '${1}' to OGG Audio" echo " # Convert the file '${1}' to OGG Audio"
echo " ${p_ffmpeg} \"${1}\" -map ${audio_track} -c:a ${acodec} -b:a ${b_acodec} ${stereo_params} -metadata title=\"${name_title}\" -metadata date=\"${year_num}\" -metadata genre=\"${genre_file}\" -metadata album=\"${album_title}\" -metadata artist=\"${artist_title}\" -metadata track=\"${track_num}\" \"${2}.${v_ext}\"" echo " ${p_ffmpeg} \"${1}\" -map ${audio_track} -c:a ${acodec} -b:a ${b_acodec} ${stereo_params} -metadata title=\"${name_title}\" -metadata date=\"${year_num}\" -metadata genre=\"${genre_file}\" -metadata album=\"${album_title}\" -metadata artist=\"${artist_title}\" -metadata track=\"${track_num}\" \"${2}.${v_ext}\""
# Execute commands for conversion # Execute commands for conversion
echo "" echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit exit
else else
${p_ffmpeg} "${1}" -map ${audio_track} -c:a ${acodec} -b:a ${b_acodec} ${stereo_params} -metadata title="${name_title}" -metadata date="${year_num}" -metadata genre="${genre_file}" -metadata album="${album_title}" -metadata artist="${artist_title}" -metadata track="${track_num}" "${2}.${v_ext}" ${p_ffmpeg} "${1}" -map ${audio_track} -c:a ${acodec} -b:a ${b_acodec} ${stereo_params} -metadata title="${name_title}" -metadata date="${year_num}" -metadata genre="${genre_file}" -metadata album="${album_title}" -metadata artist="${artist_title}" -metadata track="${track_num}" "${2}.${v_ext}"
fi fi
fi fi

View File

@ -37,123 +37,123 @@ fi
ffmpeg_test=$(ffmpeg --help 2>&1) ffmpeg_test=$(ffmpeg --help 2>&1)
error_ffmpeg=$? error_ffmpeg=$?
if [ ${error_ffmpeg} -ne 0 ] ; then if [ ${error_ffmpeg} -ne 0 ] ; then
echo "" echo ""
echo "* ks-oga-album (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-oga-album (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "+ The 'ffmpeg' tool is not installed!" echo "+ The 'ffmpeg' tool is not installed!"
echo "" echo ""
exit exit
fi fi
# Funcion to show the name of file/folder from full path # Funcion to show the name of file/folder from full path
# Syntax: extractFolderOrFile <full/path/file.txt> # Syntax: extractFolderOrFile <full/path/file.txt>
function extractFolderOrFile() { function extractFolderOrFile() {
pathToExtract="${1}/" pathToExtract="${1}/"
findFolder=0 findFolder=0
count=1 count=1
nameFolder=$(echo ${pathToExtract} | cut -d "/" -f ${count}) nameFolder=$(echo ${pathToExtract} | cut -d "/" -f ${count})
count=$(expr $count + 1) count=$(expr $count + 1)
while [ ${findFolder} -eq 0 ] ; do while [ ${findFolder} -eq 0 ] ; do
nameFolderTemp=$(echo ${pathToExtract} | cut -d "/" -f ${count}) nameFolderTemp=$(echo ${pathToExtract} | cut -d "/" -f ${count})
if [ -z "${nameFolderTemp}" ] ; then if [ -z "${nameFolderTemp}" ] ; then
findFolder=1 findFolder=1
else else
nameFolder="${nameFolderTemp}" nameFolder="${nameFolderTemp}"
count=$(expr $count + 1) count=$(expr $count + 1)
fi fi
done done
echo "${nameFolder}" echo "${nameFolder}"
} }
# Function to show files with spaces. # Function to show files with spaces.
# Syntax: showFileWithSpace <file number> # Syntax: showFileWithSpace <file number>
function showFileWithSpace() { function showFileWithSpace() {
echo "${1}" > ${dirTemp}/name.tmp echo "${1}" > ${dirTemp}/name.tmp
sed -i 's/_/ /g' ${dirTemp}/name.tmp sed -i 's/_/ /g' ${dirTemp}/name.tmp
DisplayName=$(cat ${dirTemp}/name.tmp) DisplayName=$(cat ${dirTemp}/name.tmp)
rm -rf ${dirTemp}/name.tmp rm -rf ${dirTemp}/name.tmp
cutDisplayName=$(echo ${DisplayName} | cut -c1) cutDisplayName=$(echo ${DisplayName} | cut -c1)
if [ "${cutDisplayName}" == "-" ] ; then if [ "${cutDisplayName}" == "-" ] ; then
DisplayName=$(echo ${DisplayName} | cut -c2-100) DisplayName=$(echo ${DisplayName} | cut -c2-100)
else else
cutDisplayName=$(echo ${DisplayName} | cut -c2) cutDisplayName=$(echo ${DisplayName} | cut -c2)
if [ "${cutDisplayName}" == "-" ] ; then if [ "${cutDisplayName}" == "-" ] ; then
DisplayName=$(echo ${DisplayName} | cut -c3-100) DisplayName=$(echo ${DisplayName} | cut -c3-100)
else else
cutDisplayName=$(echo ${DisplayName} | cut -c3) cutDisplayName=$(echo ${DisplayName} | cut -c3)
if [ "${cutDisplayName}" == "-" ] ; then if [ "${cutDisplayName}" == "-" ] ; then
DisplayName=$(echo ${DisplayName} | cut -c4-100) DisplayName=$(echo ${DisplayName} | cut -c4-100)
fi fi
fi fi
fi fi
echo ${DisplayName} echo ${DisplayName}
} }
# Function to remove extension from file # Function to remove extension from file
# Syntax: removeExtension "<text>" # Syntax: removeExtension "<text>"
function removeExtension() { function removeExtension() {
wordToConvert=${1} wordToConvert=${1}
ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt" ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt"
mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null
echo "${wordToConvert}" > ${ksToolsSedFile} echo "${wordToConvert}" > ${ksToolsSedFile}
# Remove extensions # Remove extensions
sed -i 's/.avi//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.avi//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mp4//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mp4//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mkv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mkv//g' "${ksToolsSedFile}" &> /dev/null
sed -i "s/.mov//g" "${ksToolsSedFile}" &> /dev/null sed -i "s/.mov//g" "${ksToolsSedFile}" &> /dev/null
sed -i 's/.vob//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.vob//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mpg//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mpg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mpeg//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mpeg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.wmv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.wmv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.ogv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.ogv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.webm//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.webm//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.flv//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.flv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mp3//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mp3//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mp2//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.mp2//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.oga//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.oga//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.ogg//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.ogg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.ac3//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.ac3//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.aac//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.aac//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.flac//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.flac//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.wav//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.wav//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.opus//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/.opus//g' "${ksToolsSedFile}" &> /dev/null
# Show file without extension # Show file without extension
wordToConvert=$(cat ${ksToolsSedFile}) wordToConvert=$(cat ${ksToolsSedFile})
echo ${wordToConvert} echo ${wordToConvert}
} }
# Syntax: ks-oga </absolute/path/song.mp3> </path/prefix_name> # Syntax: ks-oga </absolute/path/song.mp3> </path/prefix_name>
if [ -z "${1}" ] ; then if [ -z "${1}" ] ; then
echo "" echo ""
echo "* ks-oga-album (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-oga-album (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "- Convert folder album to OGA (OGG Audio) Format" echo "- Convert folder album to OGA (OGG Audio) Format"
echo "" echo ""
echo "+ Config:" echo "+ Config:"
echo "" echo ""
echo " - Audio codec: ${acodec}" echo " - Audio codec: ${acodec}"
echo " - Bitrate audio: ${b_acodec}" echo " - Bitrate audio: ${b_acodec}"
echo " - Container: ${v_ext}" echo " - Container: ${v_ext}"
echo "" echo ""
echo "+ Syntax: " echo "+ Syntax: "
echo "" echo ""
echo " $ ks-oga-album </absolute/path/album>" echo " $ ks-oga-album </absolute/path/album>"
echo "" echo ""
echo " + Example: ks-oga-album /data/albums/matrix-soundtrack" echo " + Example: ks-oga-album /data/albums/matrix-soundtrack"
echo "" echo ""
exit exit
fi fi
# Check if folder exist # Check if folder exist
if [ -d "${1}" ] ; then if [ -d "${1}" ] ; then
echo null > /dev/null echo null > /dev/null
else else
echo "" echo ""
echo "* ks-oga-album (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-oga-album (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "+ The folder '${1}' does not exist!" echo "+ The folder '${1}' does not exist!"
echo "" echo ""
exit exit
fi fi
# Scan videos/audio files format # Scan videos/audio files format
@ -167,14 +167,14 @@ echo -n "* Scanning ${1} " && sleep 4
echo "" echo ""
rm -rf ${tempFile} && touch ${tempFile} rm -rf ${tempFile} && touch ${tempFile}
for format in ${formatFiles} ; do for format in ${formatFiles} ; do
find "${1}"/*.${format} &> ${tempFileTest} find "${1}"/*.${format} &> ${tempFileTest}
if [ $? -ne 0 ] ; then if [ $? -ne 0 ] ; then
echo "null" > /dev/null echo "null" > /dev/null
else else
echo "+ Video file(s) in .${format} found!" echo "+ Video file(s) in .${format} found!"
cd "${1}" && ls -1 *.${format} &>> ${tempFile} cd "${1}" && ls -1 *.${format} &>> ${tempFile}
fail=0 fail=0
fi fi
done done
# Set the global metadata album # Set the global metadata album
@ -184,129 +184,129 @@ echo "* Common METADATA configuration:"
echo "" echo ""
echo -n "* (Default: Album-Disc) Type name of album: " ; read album_file echo -n "* (Default: Album-Disc) Type name of album: " ; read album_file
if [ -z "${album_file}" ] ; then if [ -z "${album_file}" ] ; then
album_title="Album-Disc" album_title="Album-Disc"
else else
album_title="${album_file}" album_title="${album_file}"
fi fi
echo -n "* (Default: ${current_date}) Type the year of album: " ; read year_file echo -n "* (Default: ${current_date}) Type the year of album: " ; read year_file
if [ -z "${year_file}" ] ; then if [ -z "${year_file}" ] ; then
year_num="${current_date}" year_num="${current_date}"
else else
year_num="${year_file}" year_num="${year_file}"
fi fi
echo -n "* (Default: Pop) Type the genre of album: " ; read genre_file echo -n "* (Default: Pop) Type the genre of album: " ; read genre_file
if [ -z "${genre_file}" ] ; then if [ -z "${genre_file}" ] ; then
genre_file="Pop" genre_file="Pop"
else else
genre_file="${genre_file}" genre_file="${genre_file}"
fi fi
# Init the conversion files # Init the conversion files
convert_files=1 convert_files=1
num_files=$(cat ${tempFile} | wc -l) num_files=$(cat ${tempFile} | wc -l)
if [ ${num_files} -eq 0 ] ; then if [ ${num_files} -eq 0 ] ; then
echo "" echo ""
echo "+ No video/audio file(s) found in folder '${1}" echo "+ No video/audio file(s) found in folder '${1}"
echo "" echo ""
exit exit
else else
echo "" echo ""
echo "* List of files:" echo "* List of files:"
echo "" echo ""
while [ ${convert_files} -le ${num_files} ] ; do while [ ${convert_files} -le ${num_files} ] ; do
show_file=$(cat ${tempFile} | head -${convert_files} | tail -1) show_file=$(cat ${tempFile} | head -${convert_files} | tail -1)
echo " + ${show_file}" echo " + ${show_file}"
convert_files=$(expr ${convert_files} + 1) convert_files=$(expr ${convert_files} + 1)
done done
echo "" echo ""
echo "* The output folder will be '${1}/to-oga'" echo "* The output folder will be '${1}/to-oga'"
# Execute commands for conversion # Execute commands for conversion
echo "" echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit exit
else else
convert_files=1 convert_files=1
cd "${1}" && mkdir -p to-oga && rm -rf to-oga/* cd "${1}" && mkdir -p to-oga && rm -rf to-oga/*
while [ ${convert_files} -le ${num_files} ] ; do while [ ${convert_files} -le ${num_files} ] ; do
show_file=$(cat ${tempFile} | head -${convert_files} | tail -1) show_file=$(cat ${tempFile} | head -${convert_files} | tail -1)
fname=$(echo "${show_file}" | cut -d "." -f 1) fname=$(echo "${show_file}" | cut -d "." -f 1)
name_title_default=$(removeExtension "${show_file}") name_title_default=$(removeExtension "${show_file}")
name_title_default=$(showFileWithSpace "${name_title_default}") name_title_default=$(showFileWithSpace "${name_title_default}")
echo "" echo ""
echo "* METADATA for '${show_file}'" echo "* METADATA for '${show_file}'"
echo "" echo ""
echo " - Album: ${album_title}" echo " - Album: ${album_title}"
echo " - Year: ${year_num}" echo " - Year: ${year_num}"
echo " - Genre: ${genre_file}" echo " - Genre: ${genre_file}"
echo "" echo ""
echo "* Information of '${show_file}':" echo "* Information of '${show_file}':"
echo "" echo ""
echo "+ Audio Tracks:" echo "+ Audio Tracks:"
echo "" echo ""
ffmpeg -i "${show_file}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d "," -f 1 ffmpeg -i "${show_file}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d "," -f 1
echo "" echo ""
# Check the audio track by default # Check the audio track by default
audio_default=$(ffmpeg -i "${show_file}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "(${default_lang_audio})" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1) audio_default=$(ffmpeg -i "${show_file}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "(${default_lang_audio})" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
if [ -z "${audio_default}" ] ; then if [ -z "${audio_default}" ] ; then
audio_default=$(ffmpeg -i "${show_file}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1) audio_default=$(ffmpeg -i "${show_file}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d " " -f 3 | cut -c2-5 | cut -d "(" -f 1 | cut -d "[" -f 1 | head -1)
if [ -z "${audio_default}" ] ; then if [ -z "${audio_default}" ] ; then
audio_default="0:1" audio_default="0:1"
else else
audio_default_patch=$(echo ${audio_default} | cut -c4) audio_default_patch=$(echo ${audio_default} | cut -c4)
if [ "${audio_default_patch}" == ":" ] ; then if [ "${audio_default_patch}" == ":" ] ; then
audio_default=$(echo ${audio_default} | cut -c1-3) audio_default=$(echo ${audio_default} | cut -c1-3)
else else
audio_default="${audio_default}" audio_default="${audio_default}"
fi fi
fi fi
else else
audio_default_patch=$(echo ${audio_default} | cut -c4) audio_default_patch=$(echo ${audio_default} | cut -c4)
if [ "${audio_default_patch}" == ":" ] ; then if [ "${audio_default_patch}" == ":" ] ; then
audio_default=$(echo ${audio_default} | cut -c1-3) audio_default=$(echo ${audio_default} | cut -c1-3)
else else
audio_default="${audio_default}" audio_default="${audio_default}"
fi fi
fi fi
# Ask for audio # Ask for audio
echo -n "* (Default: ${audio_default}) Type the number of audio track: " ; read audio_track echo -n "* (Default: ${audio_default}) Type the number of audio track: " ; read audio_track
if [ -z "${audio_track}" ] ; then if [ -z "${audio_track}" ] ; then
audio_track="${audio_default}" audio_track="${audio_default}"
else else
audio_track="${audio_track}" audio_track="${audio_track}"
fi fi
echo -n "* (Default: ${name_title_default}) Type name of title: " ; read name_title echo -n "* (Default: ${name_title_default}) Type name of title: " ; read name_title
if [ -z "${name_title}" ] ; then if [ -z "${name_title}" ] ; then
name_title="${name_title_default}" name_title="${name_title_default}"
else else
name_title="${name_title}" name_title="${name_title}"
fi fi
echo -n "* (Default: ${track_init}) Type number of track: " ; read track_file echo -n "* (Default: ${track_init}) Type number of track: " ; read track_file
if [ -z "${track_file}" ] ; then if [ -z "${track_file}" ] ; then
track_num="${track_init}" track_num="${track_init}"
else else
track_num="${track_file}" track_num="${track_file}"
fi fi
echo -n "* (Default: ${artist_init}) Type name of artist: " ; read artist_file echo -n "* (Default: ${artist_init}) Type name of artist: " ; read artist_file
if [ -z "${artist_file}" ] ; then if [ -z "${artist_file}" ] ; then
artist_title="${artist_init}" artist_title="${artist_init}"
else else
artist_title="${artist_file}" artist_title="${artist_file}"
artist_init="${artist_file}" artist_init="${artist_file}"
fi fi
# Check audio 5.1 or 7.1 # Check audio 5.1 or 7.1
audio_5_7_1=$(${p_ffmpeg} "${show_file}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "${audio_track}" | grep -i "5.1") audio_5_7_1=$(${p_ffmpeg} "${show_file}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "${audio_track}" | grep -i "5.1")
audio_5_7_1_2=$(${p_ffmpeg} "${show_file}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "${audio_track}" | grep -i "7.1") audio_5_7_1_2=$(${p_ffmpeg} "${show_file}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | grep "${audio_track}" | grep -i "7.1")
audio_5_7_1="${audio_5_7_1}${audio_5_7_1_2}" audio_5_7_1="${audio_5_7_1}${audio_5_7_1_2}"
if [ -z "${audio_5_7_1}" ] ; then if [ -z "${audio_5_7_1}" ] ; then
stereo_params="-ac 2" stereo_params="-ac 2"
else else
stereo_params="-ac 2 -clev 3dB -slev -6dB" stereo_params="-ac 2 -clev 3dB -slev -6dB"
fi fi
ffmpeg -i "${show_file}" -map ${audio_track} -c:a ${acodec} -b:a ${b_acodec} ${stereo_params} -metadata title="${name_title}" -metadata date="${year_num}" -metadata genre="${genre_file}" -metadata album="${album_title}" -metadata artist="${artist_title}" -metadata track="${track_num}" "to-oga/${fname}.${v_ext}" ffmpeg -i "${show_file}" -map ${audio_track} -c:a ${acodec} -b:a ${b_acodec} ${stereo_params} -metadata title="${name_title}" -metadata date="${year_num}" -metadata genre="${genre_file}" -metadata album="${album_title}" -metadata artist="${artist_title}" -metadata track="${track_num}" "to-oga/${fname}.${v_ext}"
# Increment variables # Increment variables
convert_files=$(expr ${convert_files} + 1) convert_files=$(expr ${convert_files} + 1)
track_init=$(expr ${track_num} + 1) track_init=$(expr ${track_num} + 1)
done done
fi fi
fi fi

View File

@ -26,425 +26,425 @@ fi
# Function to remove spaces and symbols # Function to remove spaces and symbols
# Syntax: convertText "<text>" # Syntax: convertText "<text>"
function convertText() { function convertText() {
wordToConvert=${1} wordToConvert=${1}
ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt" ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt"
mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null
echo "${wordToConvert}" > ${ksToolsSedFile} echo "${wordToConvert}" > ${ksToolsSedFile}
# Borrar espacios # Borrar espacios
sed -i 's/ /_/g' "${ksToolsSedFile}" &> /dev/null sed -i 's/ /_/g' "${ksToolsSedFile}" &> /dev/null
# Borrar simbolos # Borrar simbolos
symbolsList="[ ] @ { } | \ / ~ # $ % & ? ¿ = ( ) < > ! ¡" symbolsList="[ ] @ { } | \ / ~ # $ % & ? ¿ = ( ) < > ! ¡"
for findSymbol in ${symbolsList} ; do for findSymbol in ${symbolsList} ; do
sed -i "s/${findSymbol}//g" "${ksToolsSedFile}" &> /dev/null sed -i "s/${findSymbol}//g" "${ksToolsSedFile}" &> /dev/null
done done
# Borrar el resto de simbolos # Borrar el resto de simbolos
sed -i 's/*//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/*//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/"//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/"//g' "${ksToolsSedFile}" &> /dev/null
sed -i "s/^//g" "${ksToolsSedFile}" &> /dev/null sed -i "s/^//g" "${ksToolsSedFile}" &> /dev/null
# Cambiar algunos simbolos # Cambiar algunos simbolos
sed -i 's/+/_/g' "${ksToolsSedFile}" &> /dev/null sed -i 's/+/_/g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/:/-/g' "${ksToolsSedFile}" &> /dev/null sed -i 's/:/-/g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/;/-/g' "${ksToolsSedFile}" &> /dev/null sed -i 's/;/-/g' "${ksToolsSedFile}" &> /dev/null
# Mostrar texto convertido # Mostrar texto convertido
wordToConvert=$(cat ${ksToolsSedFile}) wordToConvert=$(cat ${ksToolsSedFile})
echo ${wordToConvert} echo ${wordToConvert}
} }
# Function to list the files of a directory. # Function to list the files of a directory.
# Syntax: listArchives <directory> # Syntax: listArchives <directory>
function listArchives() { function listArchives() {
fail=1 fail=1
formatFiles="mp3 wma ogg wav flac midi acc oga opus mp2 ra m4a mka" formatFiles="mp3 wma ogg wav flac midi acc oga opus mp2 ra m4a mka"
# Rename files # Rename files
cd "${1}" cd "${1}"
mkdir -p ${ksToolsTempFolder} mkdir -p ${ksToolsTempFolder}
ls -1 > ${ksToolsTempFolder}/rename-files.txt ls -1 > ${ksToolsTempFolder}/rename-files.txt
count=1 count=1
sizeFile=$(cat ${ksToolsTempFolder}/rename-files.txt | wc -l) sizeFile=$(cat ${ksToolsTempFolder}/rename-files.txt | wc -l)
while [ ${count} -le ${sizeFile} ] ; do while [ ${count} -le ${sizeFile} ] ; do
fileToRename=$(cat ${ksToolsTempFolder}/rename-files.txt | head -${count} | tail -1) fileToRename=$(cat ${ksToolsTempFolder}/rename-files.txt | head -${count} | tail -1)
fileRenamed=$(convertText "${fileToRename}") fileRenamed=$(convertText "${fileToRename}")
if [ "${fileRenamed}" == "${fileToRename}" ] ; then if [ "${fileRenamed}" == "${fileToRename}" ] ; then
echo "null" > /dev/null echo "null" > /dev/null
else else
mv "${fileToRename}" "${fileRenamed}" mv "${fileToRename}" "${fileRenamed}"
fi fi
count=$(expr $count + 1) count=$(expr $count + 1)
done done
# Scan audio files # Scan audio files
rm -rf ${dirTemp}/${listTemp} rm -rf ${dirTemp}/${listTemp}
rm -rf ${dirTemp}/${listCompTemp} rm -rf ${dirTemp}/${listCompTemp}
for format in ${formatFiles} ; do for format in ${formatFiles} ; do
find "${1}"/*.${format} &> ${dirTemp}/${listCompTempTest} find "${1}"/*.${format} &> ${dirTemp}/${listCompTempTest}
if [ $? -ne 0 ] ; then if [ $? -ne 0 ] ; then
echo "null" > /dev/null echo "null" > /dev/null
else else
find "${1}"/*.${format} &>> ${dirTemp}/${listCompTemp} find "${1}"/*.${format} &>> ${dirTemp}/${listCompTemp}
echo "+ Audio file(s) in .${format} found!" echo "+ Audio file(s) in .${format} found!"
cd "${1}" && ls -1 *.${format} &>> ${dirTemp}/${listTemp} cd "${1}" && ls -1 *.${format} &>> ${dirTemp}/${listTemp}
fail=0 fail=0
fi fi
done done
if [ ${fail} -eq 1 ] ; then if [ ${fail} -eq 1 ] ; then
echo "+ No audio file(s) found!" echo "+ No audio file(s) found!"
echo "" echo ""
exit exit
else else
echo "" echo ""
fi fi
} }
# Function to count the found files. # Function to count the found files.
function countArchives() { function countArchives() {
totalArchives=$(cat ${dirTemp}/${listCompTemp} | wc -l) totalArchives=$(cat ${dirTemp}/${listCompTemp} | wc -l)
echo ${totalArchives} echo ${totalArchives}
} }
# Function to show files with spaces. # Function to show files with spaces.
# Syntax: showFileWithSpace <file number> # Syntax: showFileWithSpace <file number>
function showFileWithSpace() { function showFileWithSpace() {
FileName=$(cat ${dirTemp}/${listTemp} | head -${1} | tail -1) FileName=$(cat ${dirTemp}/${listTemp} | head -${1} | tail -1)
FileNoExtension=$(echo $FileName | cut -d "." -f 1) FileNoExtension=$(echo $FileName | cut -d "." -f 1)
echo $FileNoExtension > ${dirTemp}/name.tmp echo $FileNoExtension > ${dirTemp}/name.tmp
sed -i 's/_/ /g' ${dirTemp}/name.tmp sed -i 's/_/ /g' ${dirTemp}/name.tmp
DisplayName=$(cat ${dirTemp}/name.tmp) DisplayName=$(cat ${dirTemp}/name.tmp)
rm -rf ${dirTemp}/name.tmp rm -rf ${dirTemp}/name.tmp
echo ${DisplayName} echo ${DisplayName}
} }
# Function to show the name of the file. # Function to show the name of the file.
# Syntax: showFile <file number> # Syntax: showFile <file number>
function showFile() { function showFile() {
archive=$(cat ${dirTemp}/${listTemp} | head -${1} | tail -1) archive=$(cat ${dirTemp}/${listTemp} | head -${1} | tail -1)
echo ${archive} echo ${archive}
} }
# Function to show full file path. # Function to show full file path.
# Syntax: showPathFile <file number> # Syntax: showPathFile <file number>
function showPathFile() { function showPathFile() {
pathFile=$(cat ${dirTemp}/${listCompTemp} | head -${1} | tail -1) pathFile=$(cat ${dirTemp}/${listCompTemp} | head -${1} | tail -1)
echo ${pathFile} echo ${pathFile}
} }
# Function to send file to server. # Function to send file to server.
# Syntax: sendFile <password> <file path> <user> <server> <server path> [file name] # Syntax: sendFile <password> <file path> <user> <server> <server path> [file name]
function sendFile() { function sendFile() {
correct=0 correct=0
countSend=0 countSend=0
while [ ${correct} -eq 0 ] ; do while [ ${correct} -eq 0 ] ; do
#sshpass -p ${1} scp ${2} ${3}@${4}:${5} &> /dev/null #sshpass -p ${1} scp ${2} ${3}@${4}:${5} &> /dev/null
comandOne="sshpass -p ${1} rsync -azL -e" comandOne="sshpass -p ${1} rsync -azL -e"
comandTwo="--progress ${2} ${3}@${4}:${5}" comandTwo="--progress ${2} ${3}@${4}:${5}"
${comandOne} "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" ${comandTwo} 2> /dev/null ${comandOne} "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" ${comandTwo} 2> /dev/null
sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
OUTPUT=$? OUTPUT=$?
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "Failure to send ${2}" echo "Failure to send ${2}"
echo "Retrying..." echo "Retrying..."
sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
sleep 5 sleep 5
countSend=$(expr ${countSend} + 1) countSend=$(expr ${countSend} + 1)
if [ ${countSend} -eq 5 ] ; then if [ ${countSend} -eq 5 ] ; then
correct=1 correct=1
fi fi
else else
correct=1 correct=1
fi fi
done done
} }
# Function to check local and server checksum. # Function to check local and server checksum.
# Syntax: checkChecksum <password> <local file path> <user> <server> <server file path> # Syntax: checkChecksum <password> <local file path> <user> <server> <server file path>
function checkChecksum() { function checkChecksum() {
correct=0 correct=0
countChecksum=0 countChecksum=0
echo -n "Checking checksum... " && sleep 4 echo -n "Checking checksum... " && sleep 4
echo "" echo ""
while [ ${correct} -eq 0 ] ; do while [ ${correct} -eq 0 ] ; do
checksumServer=$(sshpass -p ${1} ssh ${3}@${4} md5sum ${5} 2> /dev/null) checksumServer=$(sshpass -p ${1} ssh ${3}@${4} md5sum ${5} 2> /dev/null)
OUTPUT=$? OUTPUT=$?
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "Failed to get checksum for ${5}" echo "Failed to get checksum for ${5}"
echo "Retrying..." echo "Retrying..."
sleep 5 sleep 5
countChecksum=$(expr ${countChecksum} + 1) countChecksum=$(expr ${countChecksum} + 1)
if [ ${countChecksum} -eq 5 ] ; then if [ ${countChecksum} -eq 5 ] ; then
correct=1 correct=1
fi fi
else else
checksumLocal=$(md5sum ${2}) checksumLocal=$(md5sum ${2})
echo "Local checksum: $checksumLocal" echo "Local checksum: $checksumLocal"
echo "Server checksum: $checksumServer" echo "Server checksum: $checksumServer"
correct=1 correct=1
fi fi
done done
} }
# Function to show config # Function to show config
function showConfig() { function showConfig() {
configAvailable=0 configAvailable=0
echo "" echo ""
echo "* ks-upa (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-upa (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
if [ -f ${dirConfig}/USER ] ; then if [ -f ${dirConfig}/USER ] ; then
showUser=$(cat ${dirConfig}/USER) showUser=$(cat ${dirConfig}/USER)
echo "- Server User: ${showUser}" echo "- Server User: ${showUser}"
configAvailable=1 configAvailable=1
fi fi
if [ -f ${dirConfig}/PASS ] ; then if [ -f ${dirConfig}/PASS ] ; then
showPassword=$(cat ${dirConfig}/PASS) showPassword=$(cat ${dirConfig}/PASS)
echo "- Server Password: ${showPassword}" echo "- Server Password: ${showPassword}"
configAvailable=1 configAvailable=1
fi fi
if [ -f ${dirConfig}/SERVER ] ; then if [ -f ${dirConfig}/SERVER ] ; then
showServer=$(cat ${dirConfig}/SERVER) showServer=$(cat ${dirConfig}/SERVER)
echo "- URL (or IP) Server: ${showServer}" echo "- URL (or IP) Server: ${showServer}"
configAvailable=1 configAvailable=1
fi fi
if [ -f ${dirConfig}/DIR_SERVER ] ; then if [ -f ${dirConfig}/DIR_SERVER ] ; then
showDirServer=$(cat ${dirConfig}/DIR_SERVER) showDirServer=$(cat ${dirConfig}/DIR_SERVER)
echo "- Destination Path (Server): ${showDirServer}" echo "- Destination Path (Server): ${showDirServer}"
configAvailable=1 configAvailable=1
fi fi
if [ -f ${dirConfig}/DIR ] ; then if [ -f ${dirConfig}/DIR ] ; then
showDirLocal=$(cat ${dirConfig}/DIR) showDirLocal=$(cat ${dirConfig}/DIR)
echo "- Scan Path (Local): ${showDirLocal}" echo "- Scan Path (Local): ${showDirLocal}"
configAvailable=1 configAvailable=1
fi fi
if [ ${configAvailable} -eq 0 ] ; then if [ ${configAvailable} -eq 0 ] ; then
echo "* The configuration file does not exist!" echo "* The configuration file does not exist!"
fi fi
echo "" echo ""
exit exit
} }
# Function to edit the configuration file # Function to edit the configuration file
function editConfig() { function editConfig() {
editConfig=0 editConfig=0
while [ ${editConfig} -eq 0 ] ; do while [ ${editConfig} -eq 0 ] ; do
clear clear
editUser=$(cat ${dirConfig}/USER 2> /dev/null) editUser=$(cat ${dirConfig}/USER 2> /dev/null)
editPassword=$(cat ${dirConfig}/PASS 2> /dev/null) editPassword=$(cat ${dirConfig}/PASS 2> /dev/null)
editServer=$(cat ${dirConfig}/SERVER 2> /dev/null) editServer=$(cat ${dirConfig}/SERVER 2> /dev/null)
editDirServer=$(cat ${dirConfig}/DIR_SERVER 2> /dev/null) editDirServer=$(cat ${dirConfig}/DIR_SERVER 2> /dev/null)
editDirLocal=$(cat ${dirConfig}/DIR 2> /dev/null) editDirLocal=$(cat ${dirConfig}/DIR 2> /dev/null)
echo "" echo ""
echo "* ks-upa (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-upa (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo " 1 - Edit User (${editUser})" echo " 1 - Edit User (${editUser})"
echo " 2 - Edit Password (${editPassword})" echo " 2 - Edit Password (${editPassword})"
echo " 3 - Edit Server (${editServer})" echo " 3 - Edit Server (${editServer})"
echo " 4 - Edit Dest. Path (${editDirServer})" echo " 4 - Edit Dest. Path (${editDirServer})"
echo " 5 - Edit Local Path (${editDirLocal})" echo " 5 - Edit Local Path (${editDirLocal})"
echo "" echo ""
echo " 6 - Exit" echo " 6 - Exit"
echo "" echo ""
echo -n "* Choose an option: " ; read EDIT echo -n "* Choose an option: " ; read EDIT
echo "" echo ""
if [ "${EDIT}" == "1" ] ; then if [ "${EDIT}" == "1" ] ; then
echo -n "* Enter the server user: " ; read USER echo -n "* Enter the server user: " ; read USER
user=${USER} user=${USER}
echo ${user} > ${dirConfig}/USER echo ${user} > ${dirConfig}/USER
elif [ "${EDIT}" == "2" ] ; then elif [ "${EDIT}" == "2" ] ; then
echo -n "* Enter the server key: " ; read PASS echo -n "* Enter the server key: " ; read PASS
password=${PASS} password=${PASS}
echo ${password} > ${dirConfig}/PASS echo ${password} > ${dirConfig}/PASS
elif [ "${EDIT}" == "3" ] ; then elif [ "${EDIT}" == "3" ] ; then
echo -n "* Enter the server URL: " ; read SERVER echo -n "* Enter the server URL: " ; read SERVER
server=${SERVER} server=${SERVER}
echo ${server} > ${dirConfig}/SERVER echo ${server} > ${dirConfig}/SERVER
elif [ "${EDIT}" == "4" ] ; then elif [ "${EDIT}" == "4" ] ; then
echo -n "* Enter the path on the server: " ; read DIR_SERVER echo -n "* Enter the path on the server: " ; read DIR_SERVER
dirServer=${DIR_SERVER} dirServer=${DIR_SERVER}
echo ${dirServer} > ${dirConfig}/DIR_SERVER echo ${dirServer} > ${dirConfig}/DIR_SERVER
elif [ "${EDIT}" == "5" ] ; then elif [ "${EDIT}" == "5" ] ; then
echo -n "* Enter the local path to scan: " ; read DIR echo -n "* Enter the local path to scan: " ; read DIR
dirLocal=${DIR} dirLocal=${DIR}
echo ${dirLocal} > ${dirConfig}/DIR echo ${dirLocal} > ${dirConfig}/DIR
elif [ "${EDIT}" == "6" ] ; then elif [ "${EDIT}" == "6" ] ; then
editConfig=1 editConfig=1
else else
echo "+ Invalid option!" echo "+ Invalid option!"
echo -n "- Press ENTER to continue " ; read CONTINUE echo -n "- Press ENTER to continue " ; read CONTINUE
fi fi
done done
exit exit
} }
# Function to show version # Function to show version
function showVersion() { function showVersion() {
echo "" echo ""
echo "* ks-upa (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-upa (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
exit exit
} }
# Function to show help # Function to show help
function showHelp() { function showHelp() {
echo "" echo ""
echo "* ks-upa (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-upa (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "- Upload audio file(s) to server with rsync+ssh" echo "- Upload audio file(s) to server with rsync+ssh"
echo "" echo ""
echo "+ Syntax:" echo "+ Syntax:"
echo "" echo ""
echo " $ ks-upa -i - Start upload" echo " $ ks-upa -i - Start upload"
echo " $ ks-upa -r - Remove configuration" echo " $ ks-upa -r - Remove configuration"
echo " $ ks-upa -c - Show configuration" echo " $ ks-upa -c - Show configuration"
echo " $ ks-upa -e - Edit configuration" echo " $ ks-upa -e - Edit configuration"
echo " $ ks-upa -v - Show version" echo " $ ks-upa -v - Show version"
echo " $ ks-upa -h - Show help" echo " $ ks-upa -h - Show help"
echo "" echo ""
exit exit
} }
# Function to check if all the necessary tools # Function to check if all the necessary tools
# for the execution are installed. # for the execution are installed.
function checkDependencies() { function checkDependencies() {
dependence=0 dependence=0
echo -n "* Checking necessary tools... " echo -n "* Checking necessary tools... "
sleep 3 && echo "" sleep 3 && echo ""
sshpass -h &> /dev/null sshpass -h &> /dev/null
OUTPUT=$? OUTPUT=$?
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "* The 'sshpass' tool is not installed!" echo "* The 'sshpass' tool is not installed!"
dependence=1 dependence=1
fi fi
md5sum --help &> /dev/null md5sum --help &> /dev/null
OUTPUT=$? OUTPUT=$?
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "* The 'md5sum' tool is not installed!" echo "* The 'md5sum' tool is not installed!"
dependence=1 dependence=1
fi fi
rsync --version &> /dev/null rsync --version &> /dev/null
OUTPUT=$? OUTPUT=$?
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "* The 'rsync' tool is not installed!" echo "* The 'rsync' tool is not installed!"
dependence=1 dependence=1
fi fi
if [ -f /usr/bin/scp ] ; then if [ -f /usr/bin/scp ] ; then
echo "OK" > /dev/null echo "OK" > /dev/null
else else
echo "* The 'scp' tool is not installed!" echo "* The 'scp' tool is not installed!"
dependence=1 dependence=1
fi fi
if [ -f /usr/bin/ssh ] ; then if [ -f /usr/bin/ssh ] ; then
echo "OK" > /dev/null echo "OK" > /dev/null
else else
echo "* The 'ssh' tool is not installed!" echo "* The 'ssh' tool is not installed!"
dependence=1 dependence=1
fi fi
if [ ${dependence} -eq 0 ] ; then if [ ${dependence} -eq 0 ] ; then
echo "* Necessary tools installed!" echo "* Necessary tools installed!"
echo "" echo ""
else else
echo "" echo ""
exit exit
fi fi
} }
# Check if the configuration directory exists. # Check if the configuration directory exists.
if [ -d ${dirConfig} ] ; then if [ -d ${dirConfig} ] ; then
echo ${dirConfig} > /dev/null echo ${dirConfig} > /dev/null
else else
mkdir -p ${dirConfig} mkdir -p ${dirConfig}
fi fi
# Delete the existing configuration. # Delete the existing configuration.
if [ "$1" == "-r" ] ; then if [ "$1" == "-r" ] ; then
rm -rf ${dirConfig}/USER rm -rf ${dirConfig}/USER
rm -rf ${dirConfig}/PASS rm -rf ${dirConfig}/PASS
rm -rf ${dirConfig}/SERVER rm -rf ${dirConfig}/SERVER
rm -rf ${dirConfig}/DIR_SERVER rm -rf ${dirConfig}/DIR_SERVER
rm -rf ${dirConfig}/DIR rm -rf ${dirConfig}/DIR
exit exit
fi fi
# Show configuration file # Show configuration file
if [ "$1" == "-c" ] ; then if [ "$1" == "-c" ] ; then
showConfig showConfig
# Show configuration file # Show configuration file
elif [ "$1" == "-e" ] ; then elif [ "$1" == "-e" ] ; then
editConfig editConfig
# Show the version # Show the version
elif [ "$1" == "-v" ] ; then elif [ "$1" == "-v" ] ; then
showVersion showVersion
# Show the help # Show the help
elif [ "$1" == "-h" ] ; then elif [ "$1" == "-h" ] ; then
showHelp showHelp
# Init # Init
elif [ "$1" == "-i" ] ; then elif [ "$1" == "-i" ] ; then
# Start script # Start script
clear clear
echo "" echo ""
echo "* ks-upa (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-upa (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
checkDependencies checkDependencies
# Ask the user and if it exists, read it from the config. # Ask the user and if it exists, read it from the config.
if [ -f ${dirConfig}/USER ] ; then if [ -f ${dirConfig}/USER ] ; then
user=$(cat ${dirConfig}/USER) user=$(cat ${dirConfig}/USER)
else else
echo -n "* Enter the server user: " ; read USER echo -n "* Enter the server user: " ; read USER
user=${USER} user=${USER}
echo ${user} > ${dirConfig}/USER echo ${user} > ${dirConfig}/USER
fi fi
# Ask the password and if it exists, read it from the config. # Ask the password and if it exists, read it from the config.
if [ -f ${dirConfig}/PASS ] ; then if [ -f ${dirConfig}/PASS ] ; then
password=$(cat ${dirConfig}/PASS) password=$(cat ${dirConfig}/PASS)
else else
echo -n "* Enter the server key: " ; read PASS echo -n "* Enter the server key: " ; read PASS
password=${PASS} password=${PASS}
echo ${password} > ${dirConfig}/PASS echo ${password} > ${dirConfig}/PASS
fi fi
# Ask the server URL and if it exists, read it from the config. # Ask the server URL and if it exists, read it from the config.
if [ -f ${dirConfig}/SERVER ] ; then if [ -f ${dirConfig}/SERVER ] ; then
server=$(cat ${dirConfig}/SERVER) server=$(cat ${dirConfig}/SERVER)
else else
echo -n "* Enter the server URL: " ; read SERVER echo -n "* Enter the server URL: " ; read SERVER
server=${SERVER} server=${SERVER}
echo ${server} > ${dirConfig}/SERVER echo ${server} > ${dirConfig}/SERVER
fi fi
# Ask the path on the server and if it exists, read it from the config. # Ask the path on the server and if it exists, read it from the config.
if [ -f ${dirConfig}/DIR_SERVER ] ; then if [ -f ${dirConfig}/DIR_SERVER ] ; then
dirServer=$(cat ${dirConfig}/DIR_SERVER) dirServer=$(cat ${dirConfig}/DIR_SERVER)
else else
echo -n "* Enter the path on the server: " ; read DIR_SERVER echo -n "* Enter the path on the server: " ; read DIR_SERVER
dirServer=${DIR_SERVER} dirServer=${DIR_SERVER}
echo ${dirServer} > ${dirConfig}/DIR_SERVER echo ${dirServer} > ${dirConfig}/DIR_SERVER
fi fi
# Ask the local path and if it exists, read it from the config. # Ask the local path and if it exists, read it from the config.
if [ -f ${dirConfig}/DIR ] ; then if [ -f ${dirConfig}/DIR ] ; then
dirLocal=$(cat ${dirConfig}/DIR) dirLocal=$(cat ${dirConfig}/DIR)
else else
echo -n "* Enter the local path to scan: " ; read DIR echo -n "* Enter the local path to scan: " ; read DIR
dirLocal=${DIR} dirLocal=${DIR}
echo ${dirLocal} > ${dirConfig}/DIR echo ${dirLocal} > ${dirConfig}/DIR
fi fi
# Call the functions to perform the whole process. # Call the functions to perform the whole process.
echo -n "* Scanning ${dirLocal} " && sleep 4 echo -n "* Scanning ${dirLocal} " && sleep 4
echo "" echo ""
if [ -d ${dirLocal} ] ; then if [ -d ${dirLocal} ] ; then
listArchives "${dirLocal}" listArchives "${dirLocal}"
totalFiles=$(countArchives) totalFiles=$(countArchives)
count=1 count=1
echo "+ ${totalFiles} audio file(s) found!" echo "+ ${totalFiles} audio file(s) found!"
echo "" echo ""
while [ ${count} -le ${totalFiles} ] ; do while [ ${count} -le ${totalFiles} ] ; do
fullNameFile=$(showFile ${count}) fullNameFile=$(showFile ${count})
fullPathFile=$(showPathFile ${count}) fullPathFile=$(showPathFile ${count})
echo "Uploading '${fullNameFile}' " echo "Uploading '${fullNameFile}' "
sendFile ${password} ${fullPathFile} ${user} ${server} ${dirServer} ${fullNameFile} sendFile ${password} ${fullPathFile} ${user} ${server} ${dirServer} ${fullNameFile}
checkChecksum ${password} ${fullPathFile} ${user} ${server} ${dirServer}/${fullNameFile} checkChecksum ${password} ${fullPathFile} ${user} ${server} ${dirServer}/${fullNameFile}
echo "" echo ""
count=$(expr ${count} + 1) count=$(expr ${count} + 1)
done done
else else
echo "* Directory ${dirLocal} does not exist!" echo "* Directory ${dirLocal} does not exist!"
echo "" echo ""
exit exit
fi fi
# Show help # Show help
else else
showHelp showHelp
fi fi

View File

@ -26,443 +26,443 @@ fi
# Function to remove spaces and symbols # Function to remove spaces and symbols
# Syntax: convertText "<text>" # Syntax: convertText "<text>"
function convertText() { function convertText() {
wordToConvert=${1} wordToConvert=${1}
ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt" ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt"
mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null
echo "${wordToConvert}" > ${ksToolsSedFile} echo "${wordToConvert}" > ${ksToolsSedFile}
# Borrar espacios # Borrar espacios
sed -i 's/ /_/g' "${ksToolsSedFile}" &> /dev/null sed -i 's/ /_/g' "${ksToolsSedFile}" &> /dev/null
# Borrar simbolos # Borrar simbolos
symbolsList="[ ] @ { } | \ / ~ # $ % & ? ¿ = ( ) < > ! ¡" symbolsList="[ ] @ { } | \ / ~ # $ % & ? ¿ = ( ) < > ! ¡"
for findSymbol in ${symbolsList} ; do for findSymbol in ${symbolsList} ; do
sed -i "s/${findSymbol}//g" "${ksToolsSedFile}" &> /dev/null sed -i "s/${findSymbol}//g" "${ksToolsSedFile}" &> /dev/null
done done
# Borrar el resto de simbolos # Borrar el resto de simbolos
sed -i 's/*//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/*//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/"//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/"//g' "${ksToolsSedFile}" &> /dev/null
sed -i "s/^//g" "${ksToolsSedFile}" &> /dev/null sed -i "s/^//g" "${ksToolsSedFile}" &> /dev/null
# Cambiar algunos simbolos # Cambiar algunos simbolos
sed -i 's/+/_/g' "${ksToolsSedFile}" &> /dev/null sed -i 's/+/_/g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/:/-/g' "${ksToolsSedFile}" &> /dev/null sed -i 's/:/-/g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/;/-/g' "${ksToolsSedFile}" &> /dev/null sed -i 's/;/-/g' "${ksToolsSedFile}" &> /dev/null
# Mostrar texto convertido # Mostrar texto convertido
wordToConvert=$(cat ${ksToolsSedFile}) wordToConvert=$(cat ${ksToolsSedFile})
echo ${wordToConvert} echo ${wordToConvert}
} }
# Function to list the files of a directory. # Function to list the files of a directory.
# Syntax: listArchives <directory> # Syntax: listArchives <directory>
function listArchives() { function listArchives() {
fail=1 fail=1
formatFiles="" formatFiles=""
videoFiles="mp4 avi mpg mpeg mov wmv mkv ogv webm rm flv vob ts" videoFiles="mp4 avi mpg mpeg mov wmv mkv ogv webm rm flv vob ts"
formatFiles="${formatFiles} ${videoFiles}" formatFiles="${formatFiles} ${videoFiles}"
audioFiles="mp3 wma ogg wav flac midi acc oga opus mp2 ra m4a mka" audioFiles="mp3 wma ogg wav flac midi acc oga opus mp2 ra m4a mka"
formatFiles="${formatFiles} ${audioFiles}" formatFiles="${formatFiles} ${audioFiles}"
compressFiles="zip rar 7z bz2 gz xz tar bzip2 gzip" compressFiles="zip rar 7z bz2 gz xz tar bzip2 gzip"
formatFiles="${formatFiles} ${compressFiles}" formatFiles="${formatFiles} ${compressFiles}"
open_libreOfficeFiles="odt ods odp odb odg" open_libreOfficeFiles="odt ods odp odb odg"
formatFiles="${formatFiles} ${open_libreOfficeFiles}" formatFiles="${formatFiles} ${open_libreOfficeFiles}"
OfficeFiles="doc docx dotx dot docm dic thmx xlsx ppt pps pst mbd accdb msg" OfficeFiles="doc docx dotx dot docm dic thmx xlsx ppt pps pst mbd accdb msg"
formatFiles="${formatFiles} ${OfficeFiles}" formatFiles="${formatFiles} ${OfficeFiles}"
documentFiles="txt pdf rtf html php xml json css" documentFiles="txt pdf rtf html php xml json css"
formatFiles="${formatFiles} ${documentFiles}" formatFiles="${formatFiles} ${documentFiles}"
pictureFiles="png jpg jpeg gif bmp raw xcf ppm pnm tiff ico tga pbm pgm svg psd" pictureFiles="png jpg jpeg gif bmp raw xcf ppm pnm tiff ico tga pbm pgm svg psd"
formatFiles="${formatFiles} ${pictureFiles}" formatFiles="${formatFiles} ${pictureFiles}"
executableFiles="exe msi run bin elf dmg deb rpm tgz ebuild flatpakref snap sh bash cmd bat AppImage jar" executableFiles="exe msi run bin elf dmg deb rpm tgz ebuild flatpakref snap sh bash cmd bat AppImage jar"
formatFiles="${formatFiles} ${executableFiles}" formatFiles="${formatFiles} ${executableFiles}"
otherFiles="desktop lnk blend db c cpp cxx cc py rb dll so link network service ko list java" otherFiles="desktop lnk blend db c cpp cxx cc py rb dll so link network service ko list java"
formatFiles="${formatFiles} ${otherFiles}" formatFiles="${formatFiles} ${otherFiles}"
# Rename files # Rename files
cd "${1}" cd "${1}"
mkdir -p ${ksToolsTempFolder} mkdir -p ${ksToolsTempFolder}
ls -1 > ${ksToolsTempFolder}/rename-files.txt ls -1 > ${ksToolsTempFolder}/rename-files.txt
count=1 count=1
sizeFile=$(cat ${ksToolsTempFolder}/rename-files.txt | wc -l) sizeFile=$(cat ${ksToolsTempFolder}/rename-files.txt | wc -l)
while [ ${count} -le ${sizeFile} ] ; do while [ ${count} -le ${sizeFile} ] ; do
fileToRename=$(cat ${ksToolsTempFolder}/rename-files.txt | head -${count} | tail -1) fileToRename=$(cat ${ksToolsTempFolder}/rename-files.txt | head -${count} | tail -1)
fileRenamed=$(convertText "${fileToRename}") fileRenamed=$(convertText "${fileToRename}")
if [ "${fileRenamed}" == "${fileToRename}" ] ; then if [ "${fileRenamed}" == "${fileToRename}" ] ; then
echo "null" > /dev/null echo "null" > /dev/null
else else
mv "${fileToRename}" "${fileRenamed}" mv "${fileToRename}" "${fileRenamed}"
fi fi
count=$(expr $count + 1) count=$(expr $count + 1)
done done
# Scan audio files # Scan audio files
rm -rf ${dirTemp}/${listTemp} rm -rf ${dirTemp}/${listTemp}
rm -rf ${dirTemp}/${listCompTemp} rm -rf ${dirTemp}/${listCompTemp}
for format in ${formatFiles} ; do for format in ${formatFiles} ; do
find "${1}"/*.${format} &> ${dirTemp}/${listCompTempTest} find "${1}"/*.${format} &> ${dirTemp}/${listCompTempTest}
if [ $? -ne 0 ] ; then if [ $? -ne 0 ] ; then
echo "null" > /dev/null echo "null" > /dev/null
else else
find "${1}"/*.${format} &>> ${dirTemp}/${listCompTemp} find "${1}"/*.${format} &>> ${dirTemp}/${listCompTemp}
echo "+ File(s) in .${format} format found!" echo "+ File(s) in .${format} format found!"
cd "${1}" && ls -1 *.${format} &>> ${dirTemp}/${listTemp} cd "${1}" && ls -1 *.${format} &>> ${dirTemp}/${listTemp}
fail=0 fail=0
fi fi
done done
if [ ${fail} -eq 1 ] ; then if [ ${fail} -eq 1 ] ; then
echo "+ No common file(s) found!" echo "+ No common file(s) found!"
echo "" echo ""
exit exit
else else
echo "" echo ""
fi fi
} }
# Function to count the found files. # Function to count the found files.
function countArchives() { function countArchives() {
totalArchives=$(cat ${dirTemp}/${listCompTemp} | wc -l) totalArchives=$(cat ${dirTemp}/${listCompTemp} | wc -l)
echo ${totalArchives} echo ${totalArchives}
} }
# Function to show files with spaces. # Function to show files with spaces.
# Syntax: showFileWithSpace <file number> # Syntax: showFileWithSpace <file number>
function showFileWithSpace() { function showFileWithSpace() {
FileName=$(cat ${dirTemp}/${listTemp} | head -${1} | tail -1) FileName=$(cat ${dirTemp}/${listTemp} | head -${1} | tail -1)
FileNoExtension=$(echo $FileName | cut -d "." -f 1) FileNoExtension=$(echo $FileName | cut -d "." -f 1)
echo $FileNoExtension > ${dirTemp}/name.tmp echo $FileNoExtension > ${dirTemp}/name.tmp
sed -i 's/_/ /g' ${dirTemp}/name.tmp sed -i 's/_/ /g' ${dirTemp}/name.tmp
DisplayName=$(cat ${dirTemp}/name.tmp) DisplayName=$(cat ${dirTemp}/name.tmp)
rm -rf ${dirTemp}/name.tmp rm -rf ${dirTemp}/name.tmp
echo ${DisplayName} echo ${DisplayName}
} }
# Function to show the name of the file. # Function to show the name of the file.
# Syntax: showFile <file number> # Syntax: showFile <file number>
function showFile() { function showFile() {
archive=$(cat ${dirTemp}/${listTemp} | head -${1} | tail -1) archive=$(cat ${dirTemp}/${listTemp} | head -${1} | tail -1)
echo ${archive} echo ${archive}
} }
# Function to show full file path. # Function to show full file path.
# Syntax: showPathFile <file number> # Syntax: showPathFile <file number>
function showPathFile() { function showPathFile() {
pathFile=$(cat ${dirTemp}/${listCompTemp} | head -${1} | tail -1) pathFile=$(cat ${dirTemp}/${listCompTemp} | head -${1} | tail -1)
echo ${pathFile} echo ${pathFile}
} }
# Function to send file to server. # Function to send file to server.
# Syntax: sendFile <password> <file path> <user> <server> <server path> [file name] # Syntax: sendFile <password> <file path> <user> <server> <server path> [file name]
function sendFile() { function sendFile() {
correct=0 correct=0
countSend=0 countSend=0
while [ ${correct} -eq 0 ] ; do while [ ${correct} -eq 0 ] ; do
#sshpass -p ${1} scp ${2} ${3}@${4}:${5} &> /dev/null #sshpass -p ${1} scp ${2} ${3}@${4}:${5} &> /dev/null
comandOne="sshpass -p ${1} rsync -azL -e" comandOne="sshpass -p ${1} rsync -azL -e"
comandTwo="--progress ${2} ${3}@${4}:${5}" comandTwo="--progress ${2} ${3}@${4}:${5}"
${comandOne} "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" ${comandTwo} 2> /dev/null ${comandOne} "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" ${comandTwo} 2> /dev/null
sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
OUTPUT=$? OUTPUT=$?
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "Failure to send ${2}" echo "Failure to send ${2}"
echo "Retrying..." echo "Retrying..."
sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
sleep 5 sleep 5
countSend=$(expr ${countSend} + 1) countSend=$(expr ${countSend} + 1)
if [ ${countSend} -eq 5 ] ; then if [ ${countSend} -eq 5 ] ; then
correct=1 correct=1
fi fi
else else
correct=1 correct=1
fi fi
done done
} }
# Function to check local and server checksum. # Function to check local and server checksum.
# Syntax: checkChecksum <password> <local file path> <user> <server> <server file path> # Syntax: checkChecksum <password> <local file path> <user> <server> <server file path>
function checkChecksum() { function checkChecksum() {
correct=0 correct=0
countChecksum=0 countChecksum=0
echo -n "Checking checksum... " && sleep 4 echo -n "Checking checksum... " && sleep 4
echo "" echo ""
while [ ${correct} -eq 0 ] ; do while [ ${correct} -eq 0 ] ; do
checksumServer=$(sshpass -p ${1} ssh ${3}@${4} md5sum ${5} 2> /dev/null) checksumServer=$(sshpass -p ${1} ssh ${3}@${4} md5sum ${5} 2> /dev/null)
OUTPUT=$? OUTPUT=$?
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "Failed to get checksum for ${5}" echo "Failed to get checksum for ${5}"
echo "Retrying..." echo "Retrying..."
sleep 5 sleep 5
countChecksum=$(expr ${countChecksum} + 1) countChecksum=$(expr ${countChecksum} + 1)
if [ ${countChecksum} -eq 5 ] ; then if [ ${countChecksum} -eq 5 ] ; then
correct=1 correct=1
fi fi
else else
checksumLocal=$(md5sum ${2}) checksumLocal=$(md5sum ${2})
echo "Local checksum: $checksumLocal" echo "Local checksum: $checksumLocal"
echo "Server checksum: $checksumServer" echo "Server checksum: $checksumServer"
correct=1 correct=1
fi fi
done done
} }
# Function to show config # Function to show config
function showConfig() { function showConfig() {
configAvailable=0 configAvailable=0
echo "" echo ""
echo "* ks-upf (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-upf (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
if [ -f ${dirConfig}/USER ] ; then if [ -f ${dirConfig}/USER ] ; then
showUser=$(cat ${dirConfig}/USER) showUser=$(cat ${dirConfig}/USER)
echo "- Server User: ${showUser}" echo "- Server User: ${showUser}"
configAvailable=1 configAvailable=1
fi fi
if [ -f ${dirConfig}/PASS ] ; then if [ -f ${dirConfig}/PASS ] ; then
showPassword=$(cat ${dirConfig}/PASS) showPassword=$(cat ${dirConfig}/PASS)
echo "- Server Password: ${showPassword}" echo "- Server Password: ${showPassword}"
configAvailable=1 configAvailable=1
fi fi
if [ -f ${dirConfig}/SERVER ] ; then if [ -f ${dirConfig}/SERVER ] ; then
showServer=$(cat ${dirConfig}/SERVER) showServer=$(cat ${dirConfig}/SERVER)
echo "- URL (or IP) Server: ${showServer}" echo "- URL (or IP) Server: ${showServer}"
configAvailable=1 configAvailable=1
fi fi
if [ -f ${dirConfig}/DIR_SERVER ] ; then if [ -f ${dirConfig}/DIR_SERVER ] ; then
showDirServer=$(cat ${dirConfig}/DIR_SERVER) showDirServer=$(cat ${dirConfig}/DIR_SERVER)
echo "- Destination Path (Server): ${showDirServer}" echo "- Destination Path (Server): ${showDirServer}"
configAvailable=1 configAvailable=1
fi fi
if [ -f ${dirConfig}/DIR ] ; then if [ -f ${dirConfig}/DIR ] ; then
showDirLocal=$(cat ${dirConfig}/DIR) showDirLocal=$(cat ${dirConfig}/DIR)
echo "- Scan Path (Local): ${showDirLocal}" echo "- Scan Path (Local): ${showDirLocal}"
configAvailable=1 configAvailable=1
fi fi
if [ ${configAvailable} -eq 0 ] ; then if [ ${configAvailable} -eq 0 ] ; then
echo "* The configuration file does not exist!" echo "* The configuration file does not exist!"
fi fi
echo "" echo ""
exit exit
} }
# Function to edit the configuration file # Function to edit the configuration file
function editConfig() { function editConfig() {
editConfig=0 editConfig=0
while [ ${editConfig} -eq 0 ] ; do while [ ${editConfig} -eq 0 ] ; do
clear clear
editUser=$(cat ${dirConfig}/USER 2> /dev/null) editUser=$(cat ${dirConfig}/USER 2> /dev/null)
editPassword=$(cat ${dirConfig}/PASS 2> /dev/null) editPassword=$(cat ${dirConfig}/PASS 2> /dev/null)
editServer=$(cat ${dirConfig}/SERVER 2> /dev/null) editServer=$(cat ${dirConfig}/SERVER 2> /dev/null)
editDirServer=$(cat ${dirConfig}/DIR_SERVER 2> /dev/null) editDirServer=$(cat ${dirConfig}/DIR_SERVER 2> /dev/null)
editDirLocal=$(cat ${dirConfig}/DIR 2> /dev/null) editDirLocal=$(cat ${dirConfig}/DIR 2> /dev/null)
echo "" echo ""
echo "* ks-upf (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-upf (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo " 1 - Edit User (${editUser})" echo " 1 - Edit User (${editUser})"
echo " 2 - Edit Password (${editPassword})" echo " 2 - Edit Password (${editPassword})"
echo " 3 - Edit Server (${editServer})" echo " 3 - Edit Server (${editServer})"
echo " 4 - Edit Dest. Path (${editDirServer})" echo " 4 - Edit Dest. Path (${editDirServer})"
echo " 5 - Edit Local Path (${editDirLocal})" echo " 5 - Edit Local Path (${editDirLocal})"
echo "" echo ""
echo " 6 - Exit" echo " 6 - Exit"
echo "" echo ""
echo -n "* Choose an option: " ; read EDIT echo -n "* Choose an option: " ; read EDIT
echo "" echo ""
if [ "${EDIT}" == "1" ] ; then if [ "${EDIT}" == "1" ] ; then
echo -n "* Enter the server user: " ; read USER echo -n "* Enter the server user: " ; read USER
user=${USER} user=${USER}
echo ${user} > ${dirConfig}/USER echo ${user} > ${dirConfig}/USER
elif [ "${EDIT}" == "2" ] ; then elif [ "${EDIT}" == "2" ] ; then
echo -n "* Enter the server key: " ; read PASS echo -n "* Enter the server key: " ; read PASS
password=${PASS} password=${PASS}
echo ${password} > ${dirConfig}/PASS echo ${password} > ${dirConfig}/PASS
elif [ "${EDIT}" == "3" ] ; then elif [ "${EDIT}" == "3" ] ; then
echo -n "* Enter the server URL: " ; read SERVER echo -n "* Enter the server URL: " ; read SERVER
server=${SERVER} server=${SERVER}
echo ${server} > ${dirConfig}/SERVER echo ${server} > ${dirConfig}/SERVER
elif [ "${EDIT}" == "4" ] ; then elif [ "${EDIT}" == "4" ] ; then
echo -n "* Enter the path on the server: " ; read DIR_SERVER echo -n "* Enter the path on the server: " ; read DIR_SERVER
dirServer=${DIR_SERVER} dirServer=${DIR_SERVER}
echo ${dirServer} > ${dirConfig}/DIR_SERVER echo ${dirServer} > ${dirConfig}/DIR_SERVER
elif [ "${EDIT}" == "5" ] ; then elif [ "${EDIT}" == "5" ] ; then
echo -n "* Enter the local path to scan: " ; read DIR echo -n "* Enter the local path to scan: " ; read DIR
dirLocal=${DIR} dirLocal=${DIR}
echo ${dirLocal} > ${dirConfig}/DIR echo ${dirLocal} > ${dirConfig}/DIR
elif [ "${EDIT}" == "6" ] ; then elif [ "${EDIT}" == "6" ] ; then
editConfig=1 editConfig=1
else else
echo "+ Invalid option!" echo "+ Invalid option!"
echo -n "- Press ENTER to continue " ; read CONTINUE echo -n "- Press ENTER to continue " ; read CONTINUE
fi fi
done done
exit exit
} }
# Function to show version # Function to show version
function showVersion() { function showVersion() {
echo "" echo ""
echo "* ks-upf (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-upf (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
exit exit
} }
# Function to show help # Function to show help
function showHelp() { function showHelp() {
echo "" echo ""
echo "* ks-upf (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-upf (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "- Upload common file(s) to server with rsync+ssh" echo "- Upload common file(s) to server with rsync+ssh"
echo "" echo ""
echo "+ Syntax:" echo "+ Syntax:"
echo "" echo ""
echo " $ ks-upf -i - Start upload" echo " $ ks-upf -i - Start upload"
echo " $ ks-upf -r - Remove configuration" echo " $ ks-upf -r - Remove configuration"
echo " $ ks-upf -c - Show configuration" echo " $ ks-upf -c - Show configuration"
echo " $ ks-upf -e - Edit configuration" echo " $ ks-upf -e - Edit configuration"
echo " $ ks-upf -v - Show version" echo " $ ks-upf -v - Show version"
echo " $ ks-upf -h - Show help" echo " $ ks-upf -h - Show help"
echo "" echo ""
exit exit
} }
# Function to check if all the necessary tools # Function to check if all the necessary tools
# for the execution are installed. # for the execution are installed.
function checkDependencies() { function checkDependencies() {
dependence=0 dependence=0
echo -n "* Checking necessary tools... " echo -n "* Checking necessary tools... "
sleep 3 && echo "" sleep 3 && echo ""
sshpass -h &> /dev/null sshpass -h &> /dev/null
OUTPUT=$? OUTPUT=$?
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "* The 'sshpass' tool is not installed!" echo "* The 'sshpass' tool is not installed!"
dependence=1 dependence=1
fi fi
md5sum --help &> /dev/null md5sum --help &> /dev/null
OUTPUT=$? OUTPUT=$?
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "* The 'md5sum' tool is not installed!" echo "* The 'md5sum' tool is not installed!"
dependence=1 dependence=1
fi fi
rsync --version &> /dev/null rsync --version &> /dev/null
OUTPUT=$? OUTPUT=$?
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "* The 'rsync' tool is not installed!" echo "* The 'rsync' tool is not installed!"
dependence=1 dependence=1
fi fi
if [ -f /usr/bin/scp ] ; then if [ -f /usr/bin/scp ] ; then
echo "OK" > /dev/null echo "OK" > /dev/null
else else
echo "* The 'scp' tool is not installed!" echo "* The 'scp' tool is not installed!"
dependence=1 dependence=1
fi fi
if [ -f /usr/bin/ssh ] ; then if [ -f /usr/bin/ssh ] ; then
echo "OK" > /dev/null echo "OK" > /dev/null
else else
echo "* The 'ssh' tool is not installed!" echo "* The 'ssh' tool is not installed!"
dependence=1 dependence=1
fi fi
if [ ${dependence} -eq 0 ] ; then if [ ${dependence} -eq 0 ] ; then
echo "* Necessary tools installed!" echo "* Necessary tools installed!"
echo "" echo ""
else else
echo "" echo ""
exit exit
fi fi
} }
# Check if the configuration directory exists. # Check if the configuration directory exists.
if [ -d ${dirConfig} ] ; then if [ -d ${dirConfig} ] ; then
echo ${dirConfig} > /dev/null echo ${dirConfig} > /dev/null
else else
mkdir -p ${dirConfig} mkdir -p ${dirConfig}
fi fi
# Delete the existing configuration. # Delete the existing configuration.
if [ "$1" == "-r" ] ; then if [ "$1" == "-r" ] ; then
rm -rf ${dirConfig}/USER rm -rf ${dirConfig}/USER
rm -rf ${dirConfig}/PASS rm -rf ${dirConfig}/PASS
rm -rf ${dirConfig}/SERVER rm -rf ${dirConfig}/SERVER
rm -rf ${dirConfig}/DIR_SERVER rm -rf ${dirConfig}/DIR_SERVER
rm -rf ${dirConfig}/DIR rm -rf ${dirConfig}/DIR
exit exit
fi fi
# Show configuration file # Show configuration file
if [ "$1" == "-c" ] ; then if [ "$1" == "-c" ] ; then
showConfig showConfig
# Show configuration file # Show configuration file
elif [ "$1" == "-e" ] ; then elif [ "$1" == "-e" ] ; then
editConfig editConfig
# Show the version # Show the version
elif [ "$1" == "-v" ] ; then elif [ "$1" == "-v" ] ; then
showVersion showVersion
# Show the help # Show the help
elif [ "$1" == "-h" ] ; then elif [ "$1" == "-h" ] ; then
showHelp showHelp
# Init # Init
elif [ "$1" == "-i" ] ; then elif [ "$1" == "-i" ] ; then
# Start script # Start script
clear clear
echo "" echo ""
echo "* ks-upf (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-upf (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
checkDependencies checkDependencies
# Ask the user and if it exists, read it from the config. # Ask the user and if it exists, read it from the config.
if [ -f ${dirConfig}/USER ] ; then if [ -f ${dirConfig}/USER ] ; then
user=$(cat ${dirConfig}/USER) user=$(cat ${dirConfig}/USER)
else else
echo -n "* Enter the server user: " ; read USER echo -n "* Enter the server user: " ; read USER
user=${USER} user=${USER}
echo ${user} > ${dirConfig}/USER echo ${user} > ${dirConfig}/USER
fi fi
# Ask the password and if it exists, read it from the config. # Ask the password and if it exists, read it from the config.
if [ -f ${dirConfig}/PASS ] ; then if [ -f ${dirConfig}/PASS ] ; then
password=$(cat ${dirConfig}/PASS) password=$(cat ${dirConfig}/PASS)
else else
echo -n "* Enter the server key: " ; read PASS echo -n "* Enter the server key: " ; read PASS
password=${PASS} password=${PASS}
echo ${password} > ${dirConfig}/PASS echo ${password} > ${dirConfig}/PASS
fi fi
# Ask the server URL and if it exists, read it from the config. # Ask the server URL and if it exists, read it from the config.
if [ -f ${dirConfig}/SERVER ] ; then if [ -f ${dirConfig}/SERVER ] ; then
server=$(cat ${dirConfig}/SERVER) server=$(cat ${dirConfig}/SERVER)
else else
echo -n "* Enter the server URL: " ; read SERVER echo -n "* Enter the server URL: " ; read SERVER
server=${SERVER} server=${SERVER}
echo ${server} > ${dirConfig}/SERVER echo ${server} > ${dirConfig}/SERVER
fi fi
# Ask the path on the server and if it exists, read it from the config. # Ask the path on the server and if it exists, read it from the config.
if [ -f ${dirConfig}/DIR_SERVER ] ; then if [ -f ${dirConfig}/DIR_SERVER ] ; then
dirServer=$(cat ${dirConfig}/DIR_SERVER) dirServer=$(cat ${dirConfig}/DIR_SERVER)
else else
echo -n "* Enter the path on the server: " ; read DIR_SERVER echo -n "* Enter the path on the server: " ; read DIR_SERVER
dirServer=${DIR_SERVER} dirServer=${DIR_SERVER}
echo ${dirServer} > ${dirConfig}/DIR_SERVER echo ${dirServer} > ${dirConfig}/DIR_SERVER
fi fi
# Ask the local path and if it exists, read it from the config. # Ask the local path and if it exists, read it from the config.
if [ -f ${dirConfig}/DIR ] ; then if [ -f ${dirConfig}/DIR ] ; then
dirLocal=$(cat ${dirConfig}/DIR) dirLocal=$(cat ${dirConfig}/DIR)
else else
echo -n "* Enter the local path to scan: " ; read DIR echo -n "* Enter the local path to scan: " ; read DIR
dirLocal=${DIR} dirLocal=${DIR}
echo ${dirLocal} > ${dirConfig}/DIR echo ${dirLocal} > ${dirConfig}/DIR
fi fi
# Call the functions to perform the whole process. # Call the functions to perform the whole process.
echo -n "* Scanning ${dirLocal} " && sleep 4 echo -n "* Scanning ${dirLocal} " && sleep 4
echo "" echo ""
if [ -d ${dirLocal} ] ; then if [ -d ${dirLocal} ] ; then
listArchives "${dirLocal}" listArchives "${dirLocal}"
totalFiles=$(countArchives) totalFiles=$(countArchives)
count=1 count=1
echo "+ ${totalFiles} common file(s) found!" echo "+ ${totalFiles} common file(s) found!"
echo "" echo ""
while [ ${count} -le ${totalFiles} ] ; do while [ ${count} -le ${totalFiles} ] ; do
fullNameFile=$(showFile ${count}) fullNameFile=$(showFile ${count})
fullPathFile=$(showPathFile ${count}) fullPathFile=$(showPathFile ${count})
echo "Uploading '${fullNameFile}' " echo "Uploading '${fullNameFile}' "
sendFile ${password} ${fullPathFile} ${user} ${server} ${dirServer} ${fullNameFile} sendFile ${password} ${fullPathFile} ${user} ${server} ${dirServer} ${fullNameFile}
checkChecksum ${password} ${fullPathFile} ${user} ${server} ${dirServer}/${fullNameFile} checkChecksum ${password} ${fullPathFile} ${user} ${server} ${dirServer}/${fullNameFile}
echo "" echo ""
count=$(expr ${count} + 1) count=$(expr ${count} + 1)
done done
else else
echo "* Directory ${dirLocal} does not exist!" echo "* Directory ${dirLocal} does not exist!"
echo "" echo ""
exit exit
fi fi
# Show help # Show help
else else
showHelp showHelp
fi fi

View File

@ -26,388 +26,388 @@ fi
# Function to remove spaces and symbols # Function to remove spaces and symbols
# Syntax: convertText "<text>" # Syntax: convertText "<text>"
function convertText() { function convertText() {
wordToConvert=${1} wordToConvert=${1}
ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt" ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt"
mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null
echo "${wordToConvert}" > ${ksToolsSedFile} echo "${wordToConvert}" > ${ksToolsSedFile}
# Borrar espacios # Borrar espacios
sed -i 's/ /_/g' "${ksToolsSedFile}" &> /dev/null sed -i 's/ /_/g' "${ksToolsSedFile}" &> /dev/null
# Borrar simbolos # Borrar simbolos
symbolsList="[ ] @ { } | \ / ~ # $ % & ? ¿ = ( ) < > ! ¡" symbolsList="[ ] @ { } | \ / ~ # $ % & ? ¿ = ( ) < > ! ¡"
for findSymbol in ${symbolsList} ; do for findSymbol in ${symbolsList} ; do
sed -i "s/${findSymbol}//g" "${ksToolsSedFile}" &> /dev/null sed -i "s/${findSymbol}//g" "${ksToolsSedFile}" &> /dev/null
done done
# Borrar el resto de simbolos # Borrar el resto de simbolos
sed -i 's/*//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/*//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/"//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/"//g' "${ksToolsSedFile}" &> /dev/null
sed -i "s/^//g" "${ksToolsSedFile}" &> /dev/null sed -i "s/^//g" "${ksToolsSedFile}" &> /dev/null
# Cambiar algunos simbolos # Cambiar algunos simbolos
sed -i 's/+/_/g' "${ksToolsSedFile}" &> /dev/null sed -i 's/+/_/g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/:/-/g' "${ksToolsSedFile}" &> /dev/null sed -i 's/:/-/g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/;/-/g' "${ksToolsSedFile}" &> /dev/null sed -i 's/;/-/g' "${ksToolsSedFile}" &> /dev/null
# Mostrar texto convertido # Mostrar texto convertido
wordToConvert=$(cat ${ksToolsSedFile}) wordToConvert=$(cat ${ksToolsSedFile})
echo ${wordToConvert} echo ${wordToConvert}
} }
# Function to list the files of a directory. # Function to list the files of a directory.
# Syntax: listArchives <directory> # Syntax: listArchives <directory>
function listArchives() { function listArchives() {
fail=1 fail=1
formatFiles="" formatFiles=""
videoFiles="mp4 avi mpg mpeg mov wmv mkv ogv webm rm flv vob" videoFiles="mp4 avi mpg mpeg mov wmv mkv ogv webm rm flv vob"
formatFiles="${formatFiles} ${videoFiles}" formatFiles="${formatFiles} ${videoFiles}"
audioFiles="mp3 wma ogg wav flac midi acc oga opus mp2 ra m4a mka" audioFiles="mp3 wma ogg wav flac midi acc oga opus mp2 ra m4a mka"
formatFiles="${formatFiles} ${audioFiles}" formatFiles="${formatFiles} ${audioFiles}"
compressFiles="zip rar 7z bz2 gz xz tar bzip2 gzip" compressFiles="zip rar 7z bz2 gz xz tar bzip2 gzip"
formatFiles="${formatFiles} ${compressFiles}" formatFiles="${formatFiles} ${compressFiles}"
open_libreOfficeFiles="odt ods odp odb odg" open_libreOfficeFiles="odt ods odp odb odg"
formatFiles="${formatFiles} ${open_libreOfficeFiles}" formatFiles="${formatFiles} ${open_libreOfficeFiles}"
OfficeFiles="doc docx dotx dot docm dic thmx xlsx ppt pps pst mbd accdb msg" OfficeFiles="doc docx dotx dot docm dic thmx xlsx ppt pps pst mbd accdb msg"
formatFiles="${formatFiles} ${OfficeFiles}" formatFiles="${formatFiles} ${OfficeFiles}"
documentFiles="txt pdf rtf html php xml json css" documentFiles="txt pdf rtf html php xml json css"
formatFiles="${formatFiles} ${documentFiles}" formatFiles="${formatFiles} ${documentFiles}"
pictureFiles="png jpg jpeg gif bmp raw xcf ppm pnm tiff ico tga pbm pgm svg psd" pictureFiles="png jpg jpeg gif bmp raw xcf ppm pnm tiff ico tga pbm pgm svg psd"
formatFiles="${formatFiles} ${pictureFiles}" formatFiles="${formatFiles} ${pictureFiles}"
executableFiles="exe msi run bin elf dmg deb rpm tgz ebuild flatpakref snap sh bash cmd bat AppImage jar" executableFiles="exe msi run bin elf dmg deb rpm tgz ebuild flatpakref snap sh bash cmd bat AppImage jar"
formatFiles="${formatFiles} ${executableFiles}" formatFiles="${formatFiles} ${executableFiles}"
otherFiles="desktop lnk blend db c cpp cxx cc py rb dll so link network service ko list java" otherFiles="desktop lnk blend db c cpp cxx cc py rb dll so link network service ko list java"
formatFiles="${formatFiles} ${otherFiles}" formatFiles="${formatFiles} ${otherFiles}"
# Rename files # Rename files
cd "${1}" cd "${1}"
mkdir -p ${ksToolsTempFolder} mkdir -p ${ksToolsTempFolder}
ls -1 > ${ksToolsTempFolder}/rename-files.txt ls -1 > ${ksToolsTempFolder}/rename-files.txt
count=1 count=1
sizeFile=$(cat ${ksToolsTempFolder}/rename-files.txt | wc -l) sizeFile=$(cat ${ksToolsTempFolder}/rename-files.txt | wc -l)
while [ ${count} -le ${sizeFile} ] ; do while [ ${count} -le ${sizeFile} ] ; do
fileToRename=$(cat ${ksToolsTempFolder}/rename-files.txt | head -${count} | tail -1) fileToRename=$(cat ${ksToolsTempFolder}/rename-files.txt | head -${count} | tail -1)
fileRenamed=$(convertText "${fileToRename}") fileRenamed=$(convertText "${fileToRename}")
if [ "${fileRenamed}" == "${fileToRename}" ] ; then if [ "${fileRenamed}" == "${fileToRename}" ] ; then
echo "null" > /dev/null echo "null" > /dev/null
else else
mv "${fileToRename}" "${fileRenamed}" mv "${fileToRename}" "${fileRenamed}"
fi fi
count=$(expr $count + 1) count=$(expr $count + 1)
done done
# Scan audio files # Scan audio files
rm -rf ${dirTemp}/${listTemp} rm -rf ${dirTemp}/${listTemp}
rm -rf ${dirTemp}/${listCompTemp} rm -rf ${dirTemp}/${listCompTemp}
for format in ${formatFiles} ; do for format in ${formatFiles} ; do
find "${1}"/*.${format} &> ${dirTemp}/${listCompTempTest} find "${1}"/*.${format} &> ${dirTemp}/${listCompTempTest}
if [ $? -ne 0 ] ; then if [ $? -ne 0 ] ; then
echo "null" > /dev/null echo "null" > /dev/null
else else
find "${1}"/*.${format} &>> ${dirTemp}/${listCompTemp} find "${1}"/*.${format} &>> ${dirTemp}/${listCompTemp}
echo "+ File(s) in .${format} format found!" echo "+ File(s) in .${format} format found!"
cd "${1}" && ls -1 *.${format} &>> ${dirTemp}/${listTemp} cd "${1}" && ls -1 *.${format} &>> ${dirTemp}/${listTemp}
fail=0 fail=0
fi fi
done done
if [ ${fail} -eq 1 ] ; then if [ ${fail} -eq 1 ] ; then
echo "+ No common file(s) found!" echo "+ No common file(s) found!"
echo "" echo ""
exit exit
else else
echo "" echo ""
fi fi
} }
# Function to count the found files. # Function to count the found files.
function countArchives() { function countArchives() {
totalArchives=$(cat ${dirTemp}/${listCompTemp} | wc -l) totalArchives=$(cat ${dirTemp}/${listCompTemp} | wc -l)
echo ${totalArchives} echo ${totalArchives}
} }
# Function to show files with spaces. # Function to show files with spaces.
# Syntax: showFileWithSpace <file number> # Syntax: showFileWithSpace <file number>
function showFileWithSpace() { function showFileWithSpace() {
FileName=$(cat ${dirTemp}/${listTemp} | head -${1} | tail -1) FileName=$(cat ${dirTemp}/${listTemp} | head -${1} | tail -1)
FileNoExtension=$(echo $FileName | cut -d "." -f 1) FileNoExtension=$(echo $FileName | cut -d "." -f 1)
echo $FileNoExtension > ${dirTemp}/name.tmp echo $FileNoExtension > ${dirTemp}/name.tmp
sed -i 's/_/ /g' ${dirTemp}/name.tmp sed -i 's/_/ /g' ${dirTemp}/name.tmp
DisplayName=$(cat ${dirTemp}/name.tmp) DisplayName=$(cat ${dirTemp}/name.tmp)
rm -rf ${dirTemp}/name.tmp rm -rf ${dirTemp}/name.tmp
echo ${DisplayName} echo ${DisplayName}
} }
# Function to show the name of the file. # Function to show the name of the file.
# Syntax: showFile <file number> # Syntax: showFile <file number>
function showFile() { function showFile() {
archive=$(cat ${dirTemp}/${listTemp} | head -${1} | tail -1) archive=$(cat ${dirTemp}/${listTemp} | head -${1} | tail -1)
echo ${archive} echo ${archive}
} }
# Function to show full file path. # Function to show full file path.
# Syntax: showPathFile <file number> # Syntax: showPathFile <file number>
function showPathFile() { function showPathFile() {
pathFile=$(cat ${dirTemp}/${listCompTemp} | head -${1} | tail -1) pathFile=$(cat ${dirTemp}/${listCompTemp} | head -${1} | tail -1)
echo ${pathFile} echo ${pathFile}
} }
# Function to send file to server. # Function to send file to server.
# Syntax: sendFile <password> <file path> <user> <server> <server path> [file name] # Syntax: sendFile <password> <file path> <user> <server> <server path> [file name]
function sendFile() { function sendFile() {
#sshpass -p ${1} scp ${2} ${3}@${4}:${5} &> /dev/null #sshpass -p ${1} scp ${2} ${3}@${4}:${5} &> /dev/null
comandOne="sshpass -p ${1} rsync -azlr -e" comandOne="sshpass -p ${1} rsync -azlr -e"
comandTwo="--progress ${2}/ ${3}@${4}:${5}/" comandTwo="--progress ${2}/ ${3}@${4}:${5}/"
${comandOne} "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" ${comandTwo} 2> /dev/null ${comandOne} "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" ${comandTwo} 2> /dev/null
sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
} }
# Function to show config # Function to show config
function showConfig() { function showConfig() {
configAvailable=0 configAvailable=0
echo "" echo ""
echo "* ks-upr (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-upr (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
if [ -f ${dirConfig}/USER ] ; then if [ -f ${dirConfig}/USER ] ; then
showUser=$(cat ${dirConfig}/USER) showUser=$(cat ${dirConfig}/USER)
echo "- Server User: ${showUser}" echo "- Server User: ${showUser}"
configAvailable=1 configAvailable=1
fi fi
if [ -f ${dirConfig}/PASS ] ; then if [ -f ${dirConfig}/PASS ] ; then
showPassword=$(cat ${dirConfig}/PASS) showPassword=$(cat ${dirConfig}/PASS)
echo "- Server Password: ${showPassword}" echo "- Server Password: ${showPassword}"
configAvailable=1 configAvailable=1
fi fi
if [ -f ${dirConfig}/SERVER ] ; then if [ -f ${dirConfig}/SERVER ] ; then
showServer=$(cat ${dirConfig}/SERVER) showServer=$(cat ${dirConfig}/SERVER)
echo "- URL (or IP) Server: ${showServer}" echo "- URL (or IP) Server: ${showServer}"
configAvailable=1 configAvailable=1
fi fi
if [ -f ${dirConfig}/DIR_SERVER ] ; then if [ -f ${dirConfig}/DIR_SERVER ] ; then
showDirServer=$(cat ${dirConfig}/DIR_SERVER) showDirServer=$(cat ${dirConfig}/DIR_SERVER)
echo "- Destination Path (Server): ${showDirServer}" echo "- Destination Path (Server): ${showDirServer}"
configAvailable=1 configAvailable=1
fi fi
if [ -f ${dirConfig}/DIR ] ; then if [ -f ${dirConfig}/DIR ] ; then
showDirLocal=$(cat ${dirConfig}/DIR) showDirLocal=$(cat ${dirConfig}/DIR)
echo "- Scan Path (Local): ${showDirLocal}" echo "- Scan Path (Local): ${showDirLocal}"
configAvailable=1 configAvailable=1
fi fi
if [ ${configAvailable} -eq 0 ] ; then if [ ${configAvailable} -eq 0 ] ; then
echo "* The configuration file does not exist!" echo "* The configuration file does not exist!"
fi fi
echo "" echo ""
exit exit
} }
# Function to edit the configuration file # Function to edit the configuration file
function editConfig() { function editConfig() {
editConfig=0 editConfig=0
while [ ${editConfig} -eq 0 ] ; do while [ ${editConfig} -eq 0 ] ; do
clear clear
editUser=$(cat ${dirConfig}/USER 2> /dev/null) editUser=$(cat ${dirConfig}/USER 2> /dev/null)
editPassword=$(cat ${dirConfig}/PASS 2> /dev/null) editPassword=$(cat ${dirConfig}/PASS 2> /dev/null)
editServer=$(cat ${dirConfig}/SERVER 2> /dev/null) editServer=$(cat ${dirConfig}/SERVER 2> /dev/null)
editDirServer=$(cat ${dirConfig}/DIR_SERVER 2> /dev/null) editDirServer=$(cat ${dirConfig}/DIR_SERVER 2> /dev/null)
editDirLocal=$(cat ${dirConfig}/DIR 2> /dev/null) editDirLocal=$(cat ${dirConfig}/DIR 2> /dev/null)
echo "" echo ""
echo "* ks-upr (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-upr (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo " 1 - Edit User (${editUser})" echo " 1 - Edit User (${editUser})"
echo " 2 - Edit Password (${editPassword})" echo " 2 - Edit Password (${editPassword})"
echo " 3 - Edit Server (${editServer})" echo " 3 - Edit Server (${editServer})"
echo " 4 - Edit Dest. Path (${editDirServer})" echo " 4 - Edit Dest. Path (${editDirServer})"
echo " 5 - Edit Local Path (${editDirLocal})" echo " 5 - Edit Local Path (${editDirLocal})"
echo "" echo ""
echo " 6 - Exit" echo " 6 - Exit"
echo "" echo ""
echo -n "* Choose an option: " ; read EDIT echo -n "* Choose an option: " ; read EDIT
echo "" echo ""
if [ "${EDIT}" == "1" ] ; then if [ "${EDIT}" == "1" ] ; then
echo -n "* Enter the server user: " ; read USER echo -n "* Enter the server user: " ; read USER
user=${USER} user=${USER}
echo ${user} > ${dirConfig}/USER echo ${user} > ${dirConfig}/USER
elif [ "${EDIT}" == "2" ] ; then elif [ "${EDIT}" == "2" ] ; then
echo -n "* Enter the server key: " ; read PASS echo -n "* Enter the server key: " ; read PASS
password=${PASS} password=${PASS}
echo ${password} > ${dirConfig}/PASS echo ${password} > ${dirConfig}/PASS
elif [ "${EDIT}" == "3" ] ; then elif [ "${EDIT}" == "3" ] ; then
echo -n "* Enter the server URL: " ; read SERVER echo -n "* Enter the server URL: " ; read SERVER
server=${SERVER} server=${SERVER}
echo ${server} > ${dirConfig}/SERVER echo ${server} > ${dirConfig}/SERVER
elif [ "${EDIT}" == "4" ] ; then elif [ "${EDIT}" == "4" ] ; then
echo -n "* Enter the path on the server: " ; read DIR_SERVER echo -n "* Enter the path on the server: " ; read DIR_SERVER
dirServer=${DIR_SERVER} dirServer=${DIR_SERVER}
echo ${dirServer} > ${dirConfig}/DIR_SERVER echo ${dirServer} > ${dirConfig}/DIR_SERVER
elif [ "${EDIT}" == "5" ] ; then elif [ "${EDIT}" == "5" ] ; then
echo -n "* Enter the local path to scan: " ; read DIR echo -n "* Enter the local path to scan: " ; read DIR
dirLocal=${DIR} dirLocal=${DIR}
echo ${dirLocal} > ${dirConfig}/DIR echo ${dirLocal} > ${dirConfig}/DIR
elif [ "${EDIT}" == "6" ] ; then elif [ "${EDIT}" == "6" ] ; then
editConfig=1 editConfig=1
else else
echo "+ Invalid option!" echo "+ Invalid option!"
echo -n "- Press ENTER to continue " ; read CONTINUE echo -n "- Press ENTER to continue " ; read CONTINUE
fi fi
done done
exit exit
} }
# Function to show version # Function to show version
function showVersion() { function showVersion() {
echo "" echo ""
echo "* ks-upr (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-upr (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
exit exit
} }
# Function to show help # Function to show help
function showHelp() { function showHelp() {
echo "" echo ""
echo "* ks-upr (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-upr (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "- Upload recursively file(s) to server with rsync+ssh" echo "- Upload recursively file(s) to server with rsync+ssh"
echo "" echo ""
echo "+ Syntax:" echo "+ Syntax:"
echo "" echo ""
echo " $ ks-upf -i - Start upload" echo " $ ks-upf -i - Start upload"
echo " $ ks-upf -r - Remove configuration" echo " $ ks-upf -r - Remove configuration"
echo " $ ks-upf -c - Show configuration" echo " $ ks-upf -c - Show configuration"
echo " $ ks-upf -e - Edit configuration" echo " $ ks-upf -e - Edit configuration"
echo " $ ks-upf -v - Show version" echo " $ ks-upf -v - Show version"
echo " $ ks-upf -h - Show help" echo " $ ks-upf -h - Show help"
echo "" echo ""
exit exit
} }
# Function to check if all the necessary tools # Function to check if all the necessary tools
# for the execution are installed. # for the execution are installed.
function checkDependencies() { function checkDependencies() {
dependence=0 dependence=0
echo -n "* Checking necessary tools... " echo -n "* Checking necessary tools... "
sleep 3 && echo "" sleep 3 && echo ""
sshpass -h &> /dev/null sshpass -h &> /dev/null
OUTPUT=$? OUTPUT=$?
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "* The 'sshpass' tool is not installed!" echo "* The 'sshpass' tool is not installed!"
dependence=1 dependence=1
fi fi
md5sum --help &> /dev/null md5sum --help &> /dev/null
OUTPUT=$? OUTPUT=$?
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "* The 'md5sum' tool is not installed!" echo "* The 'md5sum' tool is not installed!"
dependence=1 dependence=1
fi fi
rsync --version &> /dev/null rsync --version &> /dev/null
OUTPUT=$? OUTPUT=$?
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "* The 'rsync' tool is not installed!" echo "* The 'rsync' tool is not installed!"
dependence=1 dependence=1
fi fi
if [ -f /usr/bin/scp ] ; then if [ -f /usr/bin/scp ] ; then
echo "OK" > /dev/null echo "OK" > /dev/null
else else
echo "* The 'scp' tool is not installed!" echo "* The 'scp' tool is not installed!"
dependence=1 dependence=1
fi fi
if [ -f /usr/bin/ssh ] ; then if [ -f /usr/bin/ssh ] ; then
echo "OK" > /dev/null echo "OK" > /dev/null
else else
echo "* The 'ssh' tool is not installed!" echo "* The 'ssh' tool is not installed!"
dependence=1 dependence=1
fi fi
if [ ${dependence} -eq 0 ] ; then if [ ${dependence} -eq 0 ] ; then
echo "* Necessary tools installed!" echo "* Necessary tools installed!"
echo "" echo ""
else else
echo "" echo ""
exit exit
fi fi
} }
# Check if the configuration directory exists. # Check if the configuration directory exists.
if [ -d ${dirConfig} ] ; then if [ -d ${dirConfig} ] ; then
echo ${dirConfig} > /dev/null echo ${dirConfig} > /dev/null
else else
mkdir -p ${dirConfig} mkdir -p ${dirConfig}
fi fi
# Delete the existing configuration. # Delete the existing configuration.
if [ "$1" == "-r" ] ; then if [ "$1" == "-r" ] ; then
rm -rf ${dirConfig}/USER rm -rf ${dirConfig}/USER
rm -rf ${dirConfig}/PASS rm -rf ${dirConfig}/PASS
rm -rf ${dirConfig}/SERVER rm -rf ${dirConfig}/SERVER
rm -rf ${dirConfig}/DIR_SERVER rm -rf ${dirConfig}/DIR_SERVER
rm -rf ${dirConfig}/DIR rm -rf ${dirConfig}/DIR
exit exit
fi fi
# Show configuration file # Show configuration file
if [ "$1" == "-c" ] ; then if [ "$1" == "-c" ] ; then
showConfig showConfig
# Show configuration file # Show configuration file
elif [ "$1" == "-e" ] ; then elif [ "$1" == "-e" ] ; then
editConfig editConfig
# Show the version # Show the version
elif [ "$1" == "-v" ] ; then elif [ "$1" == "-v" ] ; then
showVersion showVersion
# Show the help # Show the help
elif [ "$1" == "-h" ] ; then elif [ "$1" == "-h" ] ; then
showHelp showHelp
# Init # Init
elif [ "$1" == "-i" ] ; then elif [ "$1" == "-i" ] ; then
# Start script # Start script
clear clear
echo "" echo ""
echo "* ks-upr (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-upr (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
checkDependencies checkDependencies
# Ask the user and if it exists, read it from the config. # Ask the user and if it exists, read it from the config.
if [ -f ${dirConfig}/USER ] ; then if [ -f ${dirConfig}/USER ] ; then
user=$(cat ${dirConfig}/USER) user=$(cat ${dirConfig}/USER)
else else
echo -n "* Enter the server user: " ; read USER echo -n "* Enter the server user: " ; read USER
user=${USER} user=${USER}
echo ${user} > ${dirConfig}/USER echo ${user} > ${dirConfig}/USER
fi fi
# Ask the password and if it exists, read it from the config. # Ask the password and if it exists, read it from the config.
if [ -f ${dirConfig}/PASS ] ; then if [ -f ${dirConfig}/PASS ] ; then
password=$(cat ${dirConfig}/PASS) password=$(cat ${dirConfig}/PASS)
else else
echo -n "* Enter the server key: " ; read PASS echo -n "* Enter the server key: " ; read PASS
password=${PASS} password=${PASS}
echo ${password} > ${dirConfig}/PASS echo ${password} > ${dirConfig}/PASS
fi fi
# Ask the server URL and if it exists, read it from the config. # Ask the server URL and if it exists, read it from the config.
if [ -f ${dirConfig}/SERVER ] ; then if [ -f ${dirConfig}/SERVER ] ; then
server=$(cat ${dirConfig}/SERVER) server=$(cat ${dirConfig}/SERVER)
else else
echo -n "* Enter the server URL: " ; read SERVER echo -n "* Enter the server URL: " ; read SERVER
server=${SERVER} server=${SERVER}
echo ${server} > ${dirConfig}/SERVER echo ${server} > ${dirConfig}/SERVER
fi fi
# Ask the path on the server and if it exists, read it from the config. # Ask the path on the server and if it exists, read it from the config.
if [ -f ${dirConfig}/DIR_SERVER ] ; then if [ -f ${dirConfig}/DIR_SERVER ] ; then
dirServer=$(cat ${dirConfig}/DIR_SERVER) dirServer=$(cat ${dirConfig}/DIR_SERVER)
else else
echo -n "* Enter the path on the server: " ; read DIR_SERVER echo -n "* Enter the path on the server: " ; read DIR_SERVER
dirServer=${DIR_SERVER} dirServer=${DIR_SERVER}
echo ${dirServer} > ${dirConfig}/DIR_SERVER echo ${dirServer} > ${dirConfig}/DIR_SERVER
fi fi
# Ask the local path and if it exists, read it from the config. # Ask the local path and if it exists, read it from the config.
if [ -f ${dirConfig}/DIR ] ; then if [ -f ${dirConfig}/DIR ] ; then
dirLocal=$(cat ${dirConfig}/DIR) dirLocal=$(cat ${dirConfig}/DIR)
else else
echo -n "* Enter the local path to scan: " ; read DIR echo -n "* Enter the local path to scan: " ; read DIR
dirLocal=${DIR} dirLocal=${DIR}
echo ${dirLocal} > ${dirConfig}/DIR echo ${dirLocal} > ${dirConfig}/DIR
fi fi
# Call the functions to perform the whole process. # Call the functions to perform the whole process.
echo -n "* Scanning ${dirLocal} " && sleep 4 echo -n "* Scanning ${dirLocal} " && sleep 4
echo "" echo ""
if [ -d ${dirLocal} ] ; then if [ -d ${dirLocal} ] ; then
sendFile ${password} "${dirLocal}" ${user} ${server} ${dirServer} sendFile ${password} "${dirLocal}" ${user} ${server} ${dirServer}
echo "" echo ""
count=$(expr ${count} + 1) count=$(expr ${count} + 1)
else else
echo "* Directory ${dirLocal} does not exist!" echo "* Directory ${dirLocal} does not exist!"
echo "" echo ""
exit exit
fi fi
# Show help # Show help
else else
showHelp showHelp
fi fi

View File

@ -26,425 +26,425 @@ fi
# Function to remove spaces and symbols # Function to remove spaces and symbols
# Syntax: convertText "<text>" # Syntax: convertText "<text>"
function convertText() { function convertText() {
wordToConvert=${1} wordToConvert=${1}
ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt" ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt"
mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null
echo "${wordToConvert}" > ${ksToolsSedFile} echo "${wordToConvert}" > ${ksToolsSedFile}
# Borrar espacios # Borrar espacios
sed -i 's/ /_/g' "${ksToolsSedFile}" &> /dev/null sed -i 's/ /_/g' "${ksToolsSedFile}" &> /dev/null
# Borrar simbolos # Borrar simbolos
symbolsList="[ ] @ { } | \ / ~ # $ % & ? ¿ = ( ) < > ! ¡" symbolsList="[ ] @ { } | \ / ~ # $ % & ? ¿ = ( ) < > ! ¡"
for findSymbol in ${symbolsList} ; do for findSymbol in ${symbolsList} ; do
sed -i "s/${findSymbol}//g" "${ksToolsSedFile}" &> /dev/null sed -i "s/${findSymbol}//g" "${ksToolsSedFile}" &> /dev/null
done done
# Borrar el resto de simbolos # Borrar el resto de simbolos
sed -i 's/*//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/*//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/"//g' "${ksToolsSedFile}" &> /dev/null sed -i 's/"//g' "${ksToolsSedFile}" &> /dev/null
sed -i "s/^//g" "${ksToolsSedFile}" &> /dev/null sed -i "s/^//g" "${ksToolsSedFile}" &> /dev/null
# Cambiar algunos simbolos # Cambiar algunos simbolos
sed -i 's/+/_/g' "${ksToolsSedFile}" &> /dev/null sed -i 's/+/_/g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/:/-/g' "${ksToolsSedFile}" &> /dev/null sed -i 's/:/-/g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/;/-/g' "${ksToolsSedFile}" &> /dev/null sed -i 's/;/-/g' "${ksToolsSedFile}" &> /dev/null
# Mostrar texto convertido # Mostrar texto convertido
wordToConvert=$(cat ${ksToolsSedFile}) wordToConvert=$(cat ${ksToolsSedFile})
echo ${wordToConvert} echo ${wordToConvert}
} }
# Function to list the files of a directory. # Function to list the files of a directory.
# Syntax: listArchives <directory> # Syntax: listArchives <directory>
function listArchives() { function listArchives() {
fail=1 fail=1
formatFiles="mp4 avi mpg mpeg mov wmv mkv ogv webm rm flv vob ts" formatFiles="mp4 avi mpg mpeg mov wmv mkv ogv webm rm flv vob ts"
# Rename files # Rename files
cd "${1}" cd "${1}"
mkdir -p ${ksToolsTempFolder} mkdir -p ${ksToolsTempFolder}
ls -1 > ${ksToolsTempFolder}/rename-files.txt ls -1 > ${ksToolsTempFolder}/rename-files.txt
count=1 count=1
sizeFile=$(cat ${ksToolsTempFolder}/rename-files.txt | wc -l) sizeFile=$(cat ${ksToolsTempFolder}/rename-files.txt | wc -l)
while [ ${count} -le ${sizeFile} ] ; do while [ ${count} -le ${sizeFile} ] ; do
fileToRename=$(cat ${ksToolsTempFolder}/rename-files.txt | head -${count} | tail -1) fileToRename=$(cat ${ksToolsTempFolder}/rename-files.txt | head -${count} | tail -1)
fileRenamed=$(convertText "${fileToRename}") fileRenamed=$(convertText "${fileToRename}")
if [ "${fileRenamed}" == "${fileToRename}" ] ; then if [ "${fileRenamed}" == "${fileToRename}" ] ; then
echo "null" > /dev/null echo "null" > /dev/null
else else
mv "${fileToRename}" "${fileRenamed}" mv "${fileToRename}" "${fileRenamed}"
fi fi
count=$(expr $count + 1) count=$(expr $count + 1)
done done
# Scan video files # Scan video files
rm -rf ${dirTemp}/${listTemp} rm -rf ${dirTemp}/${listTemp}
rm -rf ${dirTemp}/${listCompTemp} rm -rf ${dirTemp}/${listCompTemp}
for format in ${formatFiles} ; do for format in ${formatFiles} ; do
find "${1}"/*.${format} &> ${dirTemp}/${listCompTempTest} find "${1}"/*.${format} &> ${dirTemp}/${listCompTempTest}
if [ $? -ne 0 ] ; then if [ $? -ne 0 ] ; then
echo "null" > /dev/null echo "null" > /dev/null
else else
find "${1}"/*.${format} &>> ${dirTemp}/${listCompTemp} find "${1}"/*.${format} &>> ${dirTemp}/${listCompTemp}
echo "+ Video file(s) in .${format} found!" echo "+ Video file(s) in .${format} found!"
cd "${1}" && ls -1 *.${format} &>> ${dirTemp}/${listTemp} cd "${1}" && ls -1 *.${format} &>> ${dirTemp}/${listTemp}
fail=0 fail=0
fi fi
done done
if [ ${fail} -eq 1 ] ; then if [ ${fail} -eq 1 ] ; then
echo "+ No video file(s) found!" echo "+ No video file(s) found!"
echo "" echo ""
exit exit
else else
echo "" echo ""
fi fi
} }
# Function to count the found files. # Function to count the found files.
function countArchives() { function countArchives() {
totalArchives=$(cat ${dirTemp}/${listCompTemp} | wc -l) totalArchives=$(cat ${dirTemp}/${listCompTemp} | wc -l)
echo ${totalArchives} echo ${totalArchives}
} }
# Function to show files with spaces. # Function to show files with spaces.
# Syntax: showFileWithSpace <file number> # Syntax: showFileWithSpace <file number>
function showFileWithSpace() { function showFileWithSpace() {
FileName=$(cat ${dirTemp}/${listTemp} | head -${1} | tail -1) FileName=$(cat ${dirTemp}/${listTemp} | head -${1} | tail -1)
FileNoExtension=$(echo $FileName | cut -d "." -f 1) FileNoExtension=$(echo $FileName | cut -d "." -f 1)
echo $FileNoExtension > ${dirTemp}/name.tmp echo $FileNoExtension > ${dirTemp}/name.tmp
sed -i 's/_/ /g' ${dirTemp}/name.tmp sed -i 's/_/ /g' ${dirTemp}/name.tmp
DisplayName=$(cat ${dirTemp}/name.tmp) DisplayName=$(cat ${dirTemp}/name.tmp)
rm -rf ${dirTemp}/name.tmp rm -rf ${dirTemp}/name.tmp
echo ${DisplayName} echo ${DisplayName}
} }
# Function to show the name of the file. # Function to show the name of the file.
# Syntax: showFile <file number> # Syntax: showFile <file number>
function showFile() { function showFile() {
archive=$(cat ${dirTemp}/${listTemp} | head -${1} | tail -1) archive=$(cat ${dirTemp}/${listTemp} | head -${1} | tail -1)
echo ${archive} echo ${archive}
} }
# Function to show full file path. # Function to show full file path.
# Syntax: showPathFile <file number> # Syntax: showPathFile <file number>
function showPathFile() { function showPathFile() {
pathFile=$(cat ${dirTemp}/${listCompTemp} | head -${1} | tail -1) pathFile=$(cat ${dirTemp}/${listCompTemp} | head -${1} | tail -1)
echo ${pathFile} echo ${pathFile}
} }
# Function to send file to server. # Function to send file to server.
# Syntax: sendFile <password> <file path> <user> <server> <server path> [file name] # Syntax: sendFile <password> <file path> <user> <server> <server path> [file name]
function sendFile() { function sendFile() {
correct=0 correct=0
countSend=0 countSend=0
while [ ${correct} -eq 0 ] ; do while [ ${correct} -eq 0 ] ; do
#sshpass -p ${1} scp ${2} ${3}@${4}:${5} &> /dev/null #sshpass -p ${1} scp ${2} ${3}@${4}:${5} &> /dev/null
comandOne="sshpass -p ${1} rsync -azL -e" comandOne="sshpass -p ${1} rsync -azL -e"
comandTwo="--progress ${2} ${3}@${4}:${5}" comandTwo="--progress ${2} ${3}@${4}:${5}"
${comandOne} "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" ${comandTwo} 2> /dev/null ${comandOne} "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" ${comandTwo} 2> /dev/null
sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
OUTPUT=$? OUTPUT=$?
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "Failure to send ${2}" echo "Failure to send ${2}"
echo "Retrying..." echo "Retrying..."
sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null sshpass -p ${1} ssh ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
sleep 5 sleep 5
countSend=$(expr ${countSend} + 1) countSend=$(expr ${countSend} + 1)
if [ ${countSend} -eq 5 ] ; then if [ ${countSend} -eq 5 ] ; then
correct=1 correct=1
fi fi
else else
correct=1 correct=1
fi fi
done done
} }
# Function to check local and server checksum. # Function to check local and server checksum.
# Syntax: checkChecksum <password> <local file path> <user> <server> <server file path> # Syntax: checkChecksum <password> <local file path> <user> <server> <server file path>
function checkChecksum() { function checkChecksum() {
correct=0 correct=0
countChecksum=0 countChecksum=0
echo -n "Checking checksum... " && sleep 4 echo -n "Checking checksum... " && sleep 4
echo "" echo ""
while [ ${correct} -eq 0 ] ; do while [ ${correct} -eq 0 ] ; do
checksumServer=$(sshpass -p ${1} ssh ${3}@${4} md5sum ${5} 2> /dev/null) checksumServer=$(sshpass -p ${1} ssh ${3}@${4} md5sum ${5} 2> /dev/null)
OUTPUT=$? OUTPUT=$?
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "Failed to get checksum for ${5}" echo "Failed to get checksum for ${5}"
echo "Retrying..." echo "Retrying..."
sleep 5 sleep 5
countChecksum=$(expr ${countChecksum} + 1) countChecksum=$(expr ${countChecksum} + 1)
if [ ${countChecksum} -eq 5 ] ; then if [ ${countChecksum} -eq 5 ] ; then
correct=1 correct=1
fi fi
else else
checksumLocal=$(md5sum ${2}) checksumLocal=$(md5sum ${2})
echo "Local checksum: $checksumLocal" echo "Local checksum: $checksumLocal"
echo "Server checksum: $checksumServer" echo "Server checksum: $checksumServer"
correct=1 correct=1
fi fi
done done
} }
# Function to show config # Function to show config
function showConfig() { function showConfig() {
configAvailable=0 configAvailable=0
echo "" echo ""
echo "* ks-upv (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-upv (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
if [ -f ${dirConfig}/USER ] ; then if [ -f ${dirConfig}/USER ] ; then
showUser=$(cat ${dirConfig}/USER) showUser=$(cat ${dirConfig}/USER)
echo "- Server User: ${showUser}" echo "- Server User: ${showUser}"
configAvailable=1 configAvailable=1
fi fi
if [ -f ${dirConfig}/PASS ] ; then if [ -f ${dirConfig}/PASS ] ; then
showPassword=$(cat ${dirConfig}/PASS) showPassword=$(cat ${dirConfig}/PASS)
echo "- Server Password: ${showPassword}" echo "- Server Password: ${showPassword}"
configAvailable=1 configAvailable=1
fi fi
if [ -f ${dirConfig}/SERVER ] ; then if [ -f ${dirConfig}/SERVER ] ; then
showServer=$(cat ${dirConfig}/SERVER) showServer=$(cat ${dirConfig}/SERVER)
echo "- URL (or IP) Server: ${showServer}" echo "- URL (or IP) Server: ${showServer}"
configAvailable=1 configAvailable=1
fi fi
if [ -f ${dirConfig}/DIR_SERVER ] ; then if [ -f ${dirConfig}/DIR_SERVER ] ; then
showDirServer=$(cat ${dirConfig}/DIR_SERVER) showDirServer=$(cat ${dirConfig}/DIR_SERVER)
echo "- Destination Path (Server): ${showDirServer}" echo "- Destination Path (Server): ${showDirServer}"
configAvailable=1 configAvailable=1
fi fi
if [ -f ${dirConfig}/DIR ] ; then if [ -f ${dirConfig}/DIR ] ; then
showDirLocal=$(cat ${dirConfig}/DIR) showDirLocal=$(cat ${dirConfig}/DIR)
echo "- Scan Path (Local): ${showDirLocal}" echo "- Scan Path (Local): ${showDirLocal}"
configAvailable=1 configAvailable=1
fi fi
if [ ${configAvailable} -eq 0 ] ; then if [ ${configAvailable} -eq 0 ] ; then
echo "* The configuration file does not exist!" echo "* The configuration file does not exist!"
fi fi
echo "" echo ""
exit exit
} }
# Function to edit the configuration file # Function to edit the configuration file
function editConfig() { function editConfig() {
editConfig=0 editConfig=0
while [ ${editConfig} -eq 0 ] ; do while [ ${editConfig} -eq 0 ] ; do
clear clear
editUser=$(cat ${dirConfig}/USER 2> /dev/null) editUser=$(cat ${dirConfig}/USER 2> /dev/null)
editPassword=$(cat ${dirConfig}/PASS 2> /dev/null) editPassword=$(cat ${dirConfig}/PASS 2> /dev/null)
editServer=$(cat ${dirConfig}/SERVER 2> /dev/null) editServer=$(cat ${dirConfig}/SERVER 2> /dev/null)
editDirServer=$(cat ${dirConfig}/DIR_SERVER 2> /dev/null) editDirServer=$(cat ${dirConfig}/DIR_SERVER 2> /dev/null)
editDirLocal=$(cat ${dirConfig}/DIR 2> /dev/null) editDirLocal=$(cat ${dirConfig}/DIR 2> /dev/null)
echo "" echo ""
echo "* ks-upv (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-upv (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo " 1 - Edit User (${editUser})" echo " 1 - Edit User (${editUser})"
echo " 2 - Edit Password (${editPassword})" echo " 2 - Edit Password (${editPassword})"
echo " 3 - Edit Server (${editServer})" echo " 3 - Edit Server (${editServer})"
echo " 4 - Edit Dest. Path (${editDirServer})" echo " 4 - Edit Dest. Path (${editDirServer})"
echo " 5 - Edit Local Path (${editDirLocal})" echo " 5 - Edit Local Path (${editDirLocal})"
echo "" echo ""
echo " 6 - Exit" echo " 6 - Exit"
echo "" echo ""
echo -n "* Choose an option: " ; read EDIT echo -n "* Choose an option: " ; read EDIT
echo "" echo ""
if [ "${EDIT}" == "1" ] ; then if [ "${EDIT}" == "1" ] ; then
echo -n "* Enter the server user: " ; read USER echo -n "* Enter the server user: " ; read USER
user=${USER} user=${USER}
echo ${user} > ${dirConfig}/USER echo ${user} > ${dirConfig}/USER
elif [ "${EDIT}" == "2" ] ; then elif [ "${EDIT}" == "2" ] ; then
echo -n "* Enter the server key: " ; read PASS echo -n "* Enter the server key: " ; read PASS
password=${PASS} password=${PASS}
echo ${password} > ${dirConfig}/PASS echo ${password} > ${dirConfig}/PASS
elif [ "${EDIT}" == "3" ] ; then elif [ "${EDIT}" == "3" ] ; then
echo -n "* Enter the server URL: " ; read SERVER echo -n "* Enter the server URL: " ; read SERVER
server=${SERVER} server=${SERVER}
echo ${server} > ${dirConfig}/SERVER echo ${server} > ${dirConfig}/SERVER
elif [ "${EDIT}" == "4" ] ; then elif [ "${EDIT}" == "4" ] ; then
echo -n "* Enter the path on the server: " ; read DIR_SERVER echo -n "* Enter the path on the server: " ; read DIR_SERVER
dirServer=${DIR_SERVER} dirServer=${DIR_SERVER}
echo ${dirServer} > ${dirConfig}/DIR_SERVER echo ${dirServer} > ${dirConfig}/DIR_SERVER
elif [ "${EDIT}" == "5" ] ; then elif [ "${EDIT}" == "5" ] ; then
echo -n "* Enter the local path to scan: " ; read DIR echo -n "* Enter the local path to scan: " ; read DIR
dirLocal=${DIR} dirLocal=${DIR}
echo ${dirLocal} > ${dirConfig}/DIR echo ${dirLocal} > ${dirConfig}/DIR
elif [ "${EDIT}" == "6" ] ; then elif [ "${EDIT}" == "6" ] ; then
editConfig=1 editConfig=1
else else
echo "+ Invalid option!" echo "+ Invalid option!"
echo -n "- Press ENTER to continue " ; read CONTINUE echo -n "- Press ENTER to continue " ; read CONTINUE
fi fi
done done
exit exit
} }
# Function to show version # Function to show version
function showVersion() { function showVersion() {
echo "" echo ""
echo "* ks-upv (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-upv (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
exit exit
} }
# Function to show help # Function to show help
function showHelp() { function showHelp() {
echo "" echo ""
echo "* ks-upv (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-upv (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
echo "- Upload videos file(s) to server with rynsc+ssh" echo "- Upload videos file(s) to server with rynsc+ssh"
echo "" echo ""
echo "+ Syntax:" echo "+ Syntax:"
echo "" echo ""
echo " $ ks-upv -i - Start upload" echo " $ ks-upv -i - Start upload"
echo " $ ks-upv -r - Remove configuration" echo " $ ks-upv -r - Remove configuration"
echo " $ ks-upv -c - Show configuration" echo " $ ks-upv -c - Show configuration"
echo " $ ks-upv -e - Edit configuration" echo " $ ks-upv -e - Edit configuration"
echo " $ ks-upv -v - Show version" echo " $ ks-upv -v - Show version"
echo " $ ks-upv -h - Show help" echo " $ ks-upv -h - Show help"
echo "" echo ""
exit exit
} }
# Function to check if all the necessary tools # Function to check if all the necessary tools
# for the execution are installed. # for the execution are installed.
function checkDependencies() { function checkDependencies() {
dependence=0 dependence=0
echo -n "* Checking necessary tools... " echo -n "* Checking necessary tools... "
sleep 3 && echo "" sleep 3 && echo ""
sshpass -h &> /dev/null sshpass -h &> /dev/null
OUTPUT=$? OUTPUT=$?
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "* The 'sshpass' tool is not installed!" echo "* The 'sshpass' tool is not installed!"
dependence=1 dependence=1
fi fi
md5sum --help &> /dev/null md5sum --help &> /dev/null
OUTPUT=$? OUTPUT=$?
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "* The 'md5sum' tool is not installed!" echo "* The 'md5sum' tool is not installed!"
dependence=1 dependence=1
fi fi
rsync --version &> /dev/null rsync --version &> /dev/null
OUTPUT=$? OUTPUT=$?
if [ ${OUTPUT} -ne 0 ] ; then if [ ${OUTPUT} -ne 0 ] ; then
echo "* The 'rsync' tool is not installed!" echo "* The 'rsync' tool is not installed!"
dependence=1 dependence=1
fi fi
if [ -f /usr/bin/scp ] ; then if [ -f /usr/bin/scp ] ; then
echo "OK" > /dev/null echo "OK" > /dev/null
else else
echo "* The 'scp' tool is not installed!" echo "* The 'scp' tool is not installed!"
dependence=1 dependence=1
fi fi
if [ -f /usr/bin/ssh ] ; then if [ -f /usr/bin/ssh ] ; then
echo "OK" > /dev/null echo "OK" > /dev/null
else else
echo "* The 'ssh' tool is not installed!" echo "* The 'ssh' tool is not installed!"
dependence=1 dependence=1
fi fi
if [ ${dependence} -eq 0 ] ; then if [ ${dependence} -eq 0 ] ; then
echo "* Necessary tools installed!" echo "* Necessary tools installed!"
echo "" echo ""
else else
echo "" echo ""
exit exit
fi fi
} }
# Check if the configuration directory exists. # Check if the configuration directory exists.
if [ -d ${dirConfig} ] ; then if [ -d ${dirConfig} ] ; then
echo ${dirConfig} > /dev/null echo ${dirConfig} > /dev/null
else else
mkdir -p ${dirConfig} mkdir -p ${dirConfig}
fi fi
# Delete the existing configuration. # Delete the existing configuration.
if [ "$1" == "-r" ] ; then if [ "$1" == "-r" ] ; then
rm -rf ${dirConfig}/USER rm -rf ${dirConfig}/USER
rm -rf ${dirConfig}/PASS rm -rf ${dirConfig}/PASS
rm -rf ${dirConfig}/SERVER rm -rf ${dirConfig}/SERVER
rm -rf ${dirConfig}/DIR_SERVER rm -rf ${dirConfig}/DIR_SERVER
rm -rf ${dirConfig}/DIR rm -rf ${dirConfig}/DIR
exit exit
fi fi
# Show configuration file # Show configuration file
if [ "$1" == "-c" ] ; then if [ "$1" == "-c" ] ; then
showConfig showConfig
# Show configuration file # Show configuration file
elif [ "$1" == "-e" ] ; then elif [ "$1" == "-e" ] ; then
editConfig editConfig
# Show the version # Show the version
elif [ "$1" == "-v" ] ; then elif [ "$1" == "-v" ] ; then
showVersion showVersion
# Show the help # Show the help
elif [ "$1" == "-h" ] ; then elif [ "$1" == "-h" ] ; then
showHelp showHelp
# Init # Init
elif [ "$1" == "-i" ] ; then elif [ "$1" == "-i" ] ; then
# Start script # Start script
clear clear
echo "" echo ""
echo "* ks-upv (ks-tools) v${VERSION} (${M_DATE})" echo "* ks-upv (ks-tools) v${VERSION} (${M_DATE})"
echo "" echo ""
checkDependencies checkDependencies
# Ask the user and if it exists, read it from the config. # Ask the user and if it exists, read it from the config.
if [ -f ${dirConfig}/USER ] ; then if [ -f ${dirConfig}/USER ] ; then
user=$(cat ${dirConfig}/USER) user=$(cat ${dirConfig}/USER)
else else
echo -n "* Enter the server user: " ; read USER echo -n "* Enter the server user: " ; read USER
user=${USER} user=${USER}
echo ${user} > ${dirConfig}/USER echo ${user} > ${dirConfig}/USER
fi fi
# Ask the password and if it exists, read it from the config. # Ask the password and if it exists, read it from the config.
if [ -f ${dirConfig}/PASS ] ; then if [ -f ${dirConfig}/PASS ] ; then
password=$(cat ${dirConfig}/PASS) password=$(cat ${dirConfig}/PASS)
else else
echo -n "* Enter the server key: " ; read PASS echo -n "* Enter the server key: " ; read PASS
password=${PASS} password=${PASS}
echo ${password} > ${dirConfig}/PASS echo ${password} > ${dirConfig}/PASS
fi fi
# Ask the server URL and if it exists, read it from the config. # Ask the server URL and if it exists, read it from the config.
if [ -f ${dirConfig}/SERVER ] ; then if [ -f ${dirConfig}/SERVER ] ; then
server=$(cat ${dirConfig}/SERVER) server=$(cat ${dirConfig}/SERVER)
else else
echo -n "* Enter the server URL: " ; read SERVER echo -n "* Enter the server URL: " ; read SERVER
server=${SERVER} server=${SERVER}
echo ${server} > ${dirConfig}/SERVER echo ${server} > ${dirConfig}/SERVER
fi fi
# Ask the path on the server and if it exists, read it from the config. # Ask the path on the server and if it exists, read it from the config.
if [ -f ${dirConfig}/DIR_SERVER ] ; then if [ -f ${dirConfig}/DIR_SERVER ] ; then
dirServer=$(cat ${dirConfig}/DIR_SERVER) dirServer=$(cat ${dirConfig}/DIR_SERVER)
else else
echo -n "* Enter the path on the server: " ; read DIR_SERVER echo -n "* Enter the path on the server: " ; read DIR_SERVER
dirServer=${DIR_SERVER} dirServer=${DIR_SERVER}
echo ${dirServer} > ${dirConfig}/DIR_SERVER echo ${dirServer} > ${dirConfig}/DIR_SERVER
fi fi
# Ask the local path and if it exists, read it from the config. # Ask the local path and if it exists, read it from the config.
if [ -f ${dirConfig}/DIR ] ; then if [ -f ${dirConfig}/DIR ] ; then
dirLocal=$(cat ${dirConfig}/DIR) dirLocal=$(cat ${dirConfig}/DIR)
else else
echo -n "* Enter the local path to scan: " ; read DIR echo -n "* Enter the local path to scan: " ; read DIR
dirLocal=${DIR} dirLocal=${DIR}
echo ${dirLocal} > ${dirConfig}/DIR echo ${dirLocal} > ${dirConfig}/DIR
fi fi
# Call the functions to perform the whole process. # Call the functions to perform the whole process.
echo -n "* Scanning ${dirLocal} " && sleep 4 echo -n "* Scanning ${dirLocal} " && sleep 4
echo "" echo ""
if [ -d ${dirLocal} ] ; then if [ -d ${dirLocal} ] ; then
listArchives "${dirLocal}" listArchives "${dirLocal}"
totalFiles=$(countArchives) totalFiles=$(countArchives)
count=1 count=1
echo "+ ${totalFiles} video file(s) found!" echo "+ ${totalFiles} video file(s) found!"
echo "" echo ""
while [ ${count} -le ${totalFiles} ] ; do while [ ${count} -le ${totalFiles} ] ; do
fullNameFile=$(showFile ${count}) fullNameFile=$(showFile ${count})
fullPathFile=$(showPathFile ${count}) fullPathFile=$(showPathFile ${count})
echo "Uploading '${fullNameFile}' " echo "Uploading '${fullNameFile}' "
sendFile ${password} ${fullPathFile} ${user} ${server} ${dirServer} ${fullNameFile} sendFile ${password} ${fullPathFile} ${user} ${server} ${dirServer} ${fullNameFile}
checkChecksum ${password} ${fullPathFile} ${user} ${server} ${dirServer}/${fullNameFile} checkChecksum ${password} ${fullPathFile} ${user} ${server} ${dirServer}/${fullNameFile}
echo "" echo ""
count=$(expr ${count} + 1) count=$(expr ${count} + 1)
done done
else else
echo "* Directory ${dirLocal} does not exist!" echo "* Directory ${dirLocal} does not exist!"
echo "" echo ""
exit exit
fi fi
# Show help # Show help
else else
showHelp showHelp
fi fi