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

View File

@ -41,96 +41,96 @@ fi
ffmpeg_test=$(ffmpeg --help 2>&1)
error_ffmpeg=$?
if [ ${error_ffmpeg} -ne 0 ] ; then
echo ""
echo "* ks-crop (ks-tools) v${VERSION} (${M_DATE})"
echo ""
echo "+ The 'ffmpeg' tool is not installed!"
echo ""
exit
echo ""
echo "* ks-crop (ks-tools) v${VERSION} (${M_DATE})"
echo ""
echo "+ The 'ffmpeg' tool is not installed!"
echo ""
exit
fi
# Function to remove extension from file
# Syntax: removeExtension "<text>"
function removeExtension() {
wordToConvert=${1}
ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt"
mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null
echo "${wordToConvert}" > ${ksToolsSedFile}
# Remove extensions
sed -i 's/.avi//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mp4//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mkv//g' "${ksToolsSedFile}" &> /dev/null
sed -i "s/.mov//g" "${ksToolsSedFile}" &> /dev/null
sed -i 's/.vob//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mpg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mpeg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.wmv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.ogv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.webm//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.flv//g' "${ksToolsSedFile}" &> /dev/null
# Show file without extension
wordToConvert=$(cat ${ksToolsSedFile})
echo ${wordToConvert}
wordToConvert=${1}
ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt"
mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null
echo "${wordToConvert}" > ${ksToolsSedFile}
# Remove extensions
sed -i 's/.avi//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mp4//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mkv//g' "${ksToolsSedFile}" &> /dev/null
sed -i "s/.mov//g" "${ksToolsSedFile}" &> /dev/null
sed -i 's/.vob//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mpg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mpeg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.wmv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.ogv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.webm//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.flv//g' "${ksToolsSedFile}" &> /dev/null
# Show file without extension
wordToConvert=$(cat ${ksToolsSedFile})
echo ${wordToConvert}
}
# Function to show files with spaces.
# Syntax: showFileWithSpace <file number>
function showFileWithSpace() {
echo "${1}" > ${dirTemp}/name.tmp
sed -i 's/_/ /g' ${dirTemp}/name.tmp
DisplayName=$(cat ${dirTemp}/name.tmp)
rm -rf ${dirTemp}/name.tmp
echo ${DisplayName}
echo "${1}" > ${dirTemp}/name.tmp
sed -i 's/_/ /g' ${dirTemp}/name.tmp
DisplayName=$(cat ${dirTemp}/name.tmp)
rm -rf ${dirTemp}/name.tmp
echo ${DisplayName}
}
# Function to show menu again when syntax is wrong
function show_menu() {
echo ""
echo "* ks-crop (ks-tools) v${VERSION} (${M_DATE})"
echo ""
echo "- Crop or change aspect ratio of a video"
echo ""
echo "+ Config:"
echo ""
echo " - Resolutions: "
echo " + ${to4_3} (4:3)"
echo " + ${to16_9} (16:9)"
echo " + ${to5_4} (5:4)"
echo " + ${toImax} (IMAX)"
echo " - Video codec: ${vcodec}"
echo " - Bitrate video: ${b_vcodec}"
echo " - Preset: ${v_preset}"
echo " - Audio codec: ${acodec}"
echo " - Default Audio: ${default_lang_audio}"
echo " - Container: ${v_ext}"
echo ""
echo "+ Syntax: "
echo ""
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 -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 ""
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 -5:4-aspect <video-file> --> Change aspect to 5:4 (stretched)"
echo ""
echo " + Examples: "
echo " ks-crop -16:9-crop /data/movies/Example.mkv"
echo " ks-crop -4:3-aspect /data/movies/Video.avi"
echo ""
exit
echo ""
echo "* ks-crop (ks-tools) v${VERSION} (${M_DATE})"
echo ""
echo "- Crop or change aspect ratio of a video"
echo ""
echo "+ Config:"
echo ""
echo " - Resolutions: "
echo " + ${to4_3} (4:3)"
echo " + ${to16_9} (16:9)"
echo " + ${to5_4} (5:4)"
echo " + ${toImax} (IMAX)"
echo " - Video codec: ${vcodec}"
echo " - Bitrate video: ${b_vcodec}"
echo " - Preset: ${v_preset}"
echo " - Audio codec: ${acodec}"
echo " - Default Audio: ${default_lang_audio}"
echo " - Container: ${v_ext}"
echo ""
echo "+ Syntax: "
echo ""
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 -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 ""
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 -5:4-aspect <video-file> --> Change aspect to 5:4 (stretched)"
echo ""
echo " + Examples: "
echo " ks-crop -16:9-crop /data/movies/Example.mkv"
echo " ks-crop -4:3-aspect /data/movies/Video.avi"
echo ""
exit
}
# Function to show error reading file
# Syntax: errorReadingFile <file>
function errorReadingFile() {
echo ""
echo "* ks-crop (ks-tools) v${VERSION} (${M_DATE})"
echo ""
echo "* The file '${1}' does not exist!"
echo ""
exit
echo ""
echo "* ks-crop (ks-tools) v${VERSION} (${M_DATE})"
echo ""
echo "* The file '${1}' does not exist!"
echo ""
exit
}
# 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")
codec_h265_hevc="${codec_h265}${codec_hevc}${yuv420p10le}"
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
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
# Show menu with bad syntax
if [ "${1}" == "-16:9-crop" ] ; then
echo > /dev/null
echo > /dev/null
elif [ "${1}" == "-4:3-crop" ] ; then
echo > /dev/null
echo > /dev/null
elif [ "${1}" == "-5:4-crop" ] ; then
echo > /dev/null
echo > /dev/null
elif [ "${1}" == "-imax-crop" ] ; then
echo > /dev/null
echo > /dev/null
elif [ "${1}" == "-16:9-aspect" ] ; then
echo > /dev/null
echo > /dev/null
elif [ "${1}" == "-4:3-aspect" ] ; then
echo > /dev/null
echo > /dev/null
elif [ "${1}" == "-5:4-aspect" ] ; then
echo > /dev/null
echo > /dev/null
else
show_menu
show_menu
fi
if [ -f "${2}" ] ; then
echo "detected" > /dev/null
echo "detected" > /dev/null
else
errorReadingFile "${2}"
errorReadingFile "${2}"
fi
# Detect resolution of video file
@ -187,345 +187,345 @@ expr ${calculate_crop} + 1 &> /tmp/ks-tools.error
ih_error="$?"
if [ ${ih_error} -eq 0 ] ; then
ih_size="${calculate_crop}"
ih_size="${calculate_crop}"
else
ih_size="0"
ih_size="0"
fi
# Function to crop videos
function crop_video() {
echo ""
echo "* Information of ${inputFile}:"
echo ""
echo "+ Video Tracks:"
${p_ffmpeg} "${inputFile}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | cut -d "," -f 1
echo ""
echo "+ Audio Tracks:"
${p_ffmpeg} "${inputFile}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d "," -f 1
echo ""
# 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)
if [ -z "${video_default}" ] ; then
video_default="0:0"
else
video_default_patch=$(echo ${video_default} | cut -c4)
if [ "${video_default_patch}" == ":" ] ; then
video_default=$(echo ${video_default} | cut -c1-3)
else
video_default="${video_default}"
fi
fi
# Ask for video
echo -n "* (Default: ${video_default}) Type the number of video track: " ; read video_track
if [ -z "${video_track}" ] ; then
video_track="${video_default}"
else
video_track="${video_track}"
fi
# 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)
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)
if [ -z "${audio_default}" ] ; then
audio_default="0:1"
else
audio_default_patch=$(echo ${audio_default} | cut -c4)
if [ "${audio_default_patch}" == ":" ] ; then
audio_default=$(echo ${audio_default} | cut -c1-3)
else
audio_default="${audio_default}"
fi
fi
else
audio_default_patch=$(echo ${audio_default} | cut -c4)
if [ "${audio_default_patch}" == ":" ] ; then
audio_default=$(echo ${audio_default} | cut -c1-3)
else
audio_default="${audio_default}"
fi
fi
# Ask for audio
echo -n "* (Default: ${audio_default}) Type the number of audio track: " ; read audio_track
if [ -z "${audio_track}" ] ; then
audio_track="${audio_default}"
else
audio_track="${audio_track}"
fi
# Ask for bitrate video
bitrate_default="${b_vcodec}"
echo -n "* (Default: ${b_vcodec}) Type the bitrate (${vcodec}): " ; read bitrate_video
if [ -z "${bitrate_video}" ] ; then
b_vcodec="${bitrate_default}"
else
b_vcodec="${bitrate_video}"
fi
# Reload p_conversion variable
if [ -z "${codec_h265_hevc}" ] ; then
p_conversion="-c:v ${vcodec} -profile:v high -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec}"
else
p_conversion="-c:v ${vcodec} -profile:v high -pix_fmt yuv420p -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec}"
fi
# Ask for patched
echo -n "* (Default: n) Do you want apply '-max_muxing_queue_size 9999' patch? (y/n): " ; read patch_thread
if [ "${patch_thread}" == "y" ] ; then
patch_thread="y"
else
patch_thread="n"
fi
echo ""
echo "* Information of ${inputFile}:"
echo ""
echo "+ Video Tracks:"
${p_ffmpeg} "${inputFile}" 2>&1 | grep Stream | tr -s " " | grep "Video:" | cut -d "," -f 1
echo ""
echo "+ Audio Tracks:"
${p_ffmpeg} "${inputFile}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d "," -f 1
echo ""
# 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)
if [ -z "${video_default}" ] ; then
video_default="0:0"
else
video_default_patch=$(echo ${video_default} | cut -c4)
if [ "${video_default_patch}" == ":" ] ; then
video_default=$(echo ${video_default} | cut -c1-3)
else
video_default="${video_default}"
fi
fi
# Ask for video
echo -n "* (Default: ${video_default}) Type the number of video track: " ; read video_track
if [ -z "${video_track}" ] ; then
video_track="${video_default}"
else
video_track="${video_track}"
fi
# 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)
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)
if [ -z "${audio_default}" ] ; then
audio_default="0:1"
else
audio_default_patch=$(echo ${audio_default} | cut -c4)
if [ "${audio_default_patch}" == ":" ] ; then
audio_default=$(echo ${audio_default} | cut -c1-3)
else
audio_default="${audio_default}"
fi
fi
else
audio_default_patch=$(echo ${audio_default} | cut -c4)
if [ "${audio_default_patch}" == ":" ] ; then
audio_default=$(echo ${audio_default} | cut -c1-3)
else
audio_default="${audio_default}"
fi
fi
# Ask for audio
echo -n "* (Default: ${audio_default}) Type the number of audio track: " ; read audio_track
if [ -z "${audio_track}" ] ; then
audio_track="${audio_default}"
else
audio_track="${audio_track}"
fi
# Ask for bitrate video
bitrate_default="${b_vcodec}"
echo -n "* (Default: ${b_vcodec}) Type the bitrate (${vcodec}): " ; read bitrate_video
if [ -z "${bitrate_video}" ] ; then
b_vcodec="${bitrate_default}"
else
b_vcodec="${bitrate_video}"
fi
# Reload p_conversion variable
if [ -z "${codec_h265_hevc}" ] ; then
p_conversion="-c:v ${vcodec} -profile:v high -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec}"
else
p_conversion="-c:v ${vcodec} -profile:v high -pix_fmt yuv420p -b:v ${b_vcodec} -preset ${v_preset} -c:a ${acodec}"
fi
# Ask for patched
echo -n "* (Default: n) Do you want apply '-max_muxing_queue_size 9999' patch? (y/n): " ; read patch_thread
if [ "${patch_thread}" == "y" ] ; then
patch_thread="y"
else
patch_thread="n"
fi
# Check diferent modes
if [ "${modeCrop}" == "16:9-crop" ] ; then
inputFileOut=$(removeExtension ${inputFile})
# Show commands for conversion
echo ""
echo "* COMMAND THAT WILL BE EXECUTED:"
echo ""
inputFileSave="${inputFile}"
ih_sizeSave="${ih_size}"
if [ ${ih_size} -eq 0 ] ; then
if [ "${patch_thread}" == "y" ] ; then
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 ""
inputFile="${inputFileOut}-resize.${v_ext}"
ih_size="360"
else
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 ""
inputFile="${inputFileOut}-resize.${v_ext}"
ih_size="360"
fi
else
echo " # File detected with resolution" ${resolution_detected} "(ih ${ih_size})"
fi
echo " # Crop '${inputFile}' from 4:3/IMAX to 16:9 (1.77:1)"
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}\""
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}\""
fi
# Execute commands for conversion
echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit
else
inputFile="${inputFileSave}"
ih_size="${ih_sizeSave}"
inputFileOut=$(removeExtension ${inputFile})
if [ ${ih_size} -eq 0 ] ; 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}"
inputFile="${inputFileOut}-resize.${v_ext}"
ih_size="360"
else
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -s 1920x1440 ${p_conversion} "${inputFileOut}-resize.${v_ext}"
inputFile="${inputFileOut}-resize.${v_ext}"
ih_size="360"
fi
fi
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}"
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}"
fi
fi
elif [ "${modeCrop}" == "4:3-crop" ] ; then
inputFileOut=$(removeExtension ${inputFile})
# Show commands for conversion
echo ""
echo "* COMMAND THAT WILL BE EXECUTED:"
echo ""
echo " # File detected with resolution" ${resolution_detected}
echo " # Crop '${inputFile}' from 16:9 to 4:3 (1.33:1)"
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}\""
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}\""
fi
# Execute commands for conversion
echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit
else
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}"
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}"
fi
fi
elif [ "${modeCrop}" == "5:4-crop" ] ; then
inputFileOut=$(removeExtension ${inputFile})
# Show commands for conversion
echo ""
echo "* COMMAND THAT WILL BE EXECUTED:"
echo ""
echo " # File detected with resolution" ${resolution_detected}
echo " # Crop '${inputFile}' from 16:9 to 5:4 (1.25:1)"
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}\""
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}\""
fi
# Execute commands for conversion
echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit
else
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}"
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}"
fi
fi
elif [ "${modeCrop}" == "imax-crop" ] ; then
inputFileOut=$(removeExtension ${inputFile})
# Show commands for conversion
echo ""
echo "* COMMAND THAT WILL BE EXECUTED:"
echo ""
echo " # File detected with resolution" ${resolution_detected}
echo " # Crop '${inputFile}' from 16:9 to IMAX (1.43:1)"
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}\""
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}\""
fi
# Execute commands for conversion
echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit
else
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}"
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}"
fi
fi
elif [ "${modeCrop}" == "16:9-aspect" ] ; then
inputFileOut=$(removeExtension ${inputFile})
# Show commands for conversion
echo ""
echo "* COMMAND THAT WILL BE EXECUTED:"
echo ""
echo " # File detected with resolution" ${resolution_detected}
echo " # Change '${inputFile}' aspect to 16:9 (stretched)"
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}\""
else
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 16:9 -s ${resolution} ${p_conversion} \"${inputFileOut}-aspect.${v_ext}\""
fi
# Execute commands for conversion
echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit
else
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}"
else
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 16:9 -s ${resolution} ${p_conversion} "${inputFileOut}-aspect.${v_ext}"
fi
fi
elif [ "${modeCrop}" == "4:3-aspect" ] ; then
inputFileOut=$(removeExtension ${inputFile})
# Show commands for conversion
echo ""
echo "* COMMAND THAT WILL BE EXECUTED:"
echo ""
echo " # File detected with resolution" ${resolution_detected}
echo " # Change '${inputFile}' aspect to 4:3 (stretched)"
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}\""
else
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 4:3 -s ${resolution} ${p_conversion} \"${inputFileOut}-aspect.${v_ext}\""
fi
# Execute commands for conversion
echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit
else
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}"
else
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 4:3 -s ${resolution} ${p_conversion} "${inputFileOut}-aspect.${v_ext}"
fi
fi
elif [ "${modeCrop}" == "5:4-aspect" ] ; then
inputFileOut=$(removeExtension ${inputFile})
# Show commands for conversion
echo ""
echo "* COMMAND THAT WILL BE EXECUTED:"
echo ""
echo " # File detected with resolution" ${resolution_detected}
echo " # Change '${inputFile}' aspect to 5:4 (stretched)"
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}\""
else
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 5:4 -s ${resolution} ${p_conversion} \"${inputFileOut}-aspect.${v_ext}\""
fi
# Execute commands for conversion
echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit
else
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}"
else
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 5:4 -s ${resolution} ${p_conversion} "${inputFileOut}-aspect.${v_ext}"
fi
fi
else
show_menu
fi
# Check diferent modes
if [ "${modeCrop}" == "16:9-crop" ] ; then
inputFileOut=$(removeExtension ${inputFile})
# Show commands for conversion
echo ""
echo "* COMMAND THAT WILL BE EXECUTED:"
echo ""
inputFileSave="${inputFile}"
ih_sizeSave="${ih_size}"
if [ ${ih_size} -eq 0 ] ; then
if [ "${patch_thread}" == "y" ] ; then
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 ""
inputFile="${inputFileOut}-resize.${v_ext}"
ih_size="360"
else
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 ""
inputFile="${inputFileOut}-resize.${v_ext}"
ih_size="360"
fi
else
echo " # File detected with resolution" ${resolution_detected} "(ih ${ih_size})"
fi
echo " # Crop '${inputFile}' from 4:3/IMAX to 16:9 (1.77:1)"
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}\""
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}\""
fi
# Execute commands for conversion
echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit
else
inputFile="${inputFileSave}"
ih_size="${ih_sizeSave}"
inputFileOut=$(removeExtension ${inputFile})
if [ ${ih_size} -eq 0 ] ; 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}"
inputFile="${inputFileOut}-resize.${v_ext}"
ih_size="360"
else
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -s 1920x1440 ${p_conversion} "${inputFileOut}-resize.${v_ext}"
inputFile="${inputFileOut}-resize.${v_ext}"
ih_size="360"
fi
fi
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}"
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}"
fi
fi
elif [ "${modeCrop}" == "4:3-crop" ] ; then
inputFileOut=$(removeExtension ${inputFile})
# Show commands for conversion
echo ""
echo "* COMMAND THAT WILL BE EXECUTED:"
echo ""
echo " # File detected with resolution" ${resolution_detected}
echo " # Crop '${inputFile}' from 16:9 to 4:3 (1.33:1)"
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}\""
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}\""
fi
# Execute commands for conversion
echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit
else
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}"
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}"
fi
fi
elif [ "${modeCrop}" == "5:4-crop" ] ; then
inputFileOut=$(removeExtension ${inputFile})
# Show commands for conversion
echo ""
echo "* COMMAND THAT WILL BE EXECUTED:"
echo ""
echo " # File detected with resolution" ${resolution_detected}
echo " # Crop '${inputFile}' from 16:9 to 5:4 (1.25:1)"
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}\""
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}\""
fi
# Execute commands for conversion
echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit
else
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}"
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}"
fi
fi
elif [ "${modeCrop}" == "imax-crop" ] ; then
inputFileOut=$(removeExtension ${inputFile})
# Show commands for conversion
echo ""
echo "* COMMAND THAT WILL BE EXECUTED:"
echo ""
echo " # File detected with resolution" ${resolution_detected}
echo " # Crop '${inputFile}' from 16:9 to IMAX (1.43:1)"
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}\""
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}\""
fi
# Execute commands for conversion
echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit
else
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}"
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}"
fi
fi
elif [ "${modeCrop}" == "16:9-aspect" ] ; then
inputFileOut=$(removeExtension ${inputFile})
# Show commands for conversion
echo ""
echo "* COMMAND THAT WILL BE EXECUTED:"
echo ""
echo " # File detected with resolution" ${resolution_detected}
echo " # Change '${inputFile}' aspect to 16:9 (stretched)"
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}\""
else
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 16:9 -s ${resolution} ${p_conversion} \"${inputFileOut}-aspect.${v_ext}\""
fi
# Execute commands for conversion
echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit
else
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}"
else
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 16:9 -s ${resolution} ${p_conversion} "${inputFileOut}-aspect.${v_ext}"
fi
fi
elif [ "${modeCrop}" == "4:3-aspect" ] ; then
inputFileOut=$(removeExtension ${inputFile})
# Show commands for conversion
echo ""
echo "* COMMAND THAT WILL BE EXECUTED:"
echo ""
echo " # File detected with resolution" ${resolution_detected}
echo " # Change '${inputFile}' aspect to 4:3 (stretched)"
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}\""
else
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 4:3 -s ${resolution} ${p_conversion} \"${inputFileOut}-aspect.${v_ext}\""
fi
# Execute commands for conversion
echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit
else
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}"
else
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 4:3 -s ${resolution} ${p_conversion} "${inputFileOut}-aspect.${v_ext}"
fi
fi
elif [ "${modeCrop}" == "5:4-aspect" ] ; then
inputFileOut=$(removeExtension ${inputFile})
# Show commands for conversion
echo ""
echo "* COMMAND THAT WILL BE EXECUTED:"
echo ""
echo " # File detected with resolution" ${resolution_detected}
echo " # Change '${inputFile}' aspect to 5:4 (stretched)"
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}\""
else
echo " ${p_ffmpeg} \"${inputFile}\" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 5:4 -s ${resolution} ${p_conversion} \"${inputFileOut}-aspect.${v_ext}\""
fi
# Execute commands for conversion
echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit
else
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}"
else
${p_ffmpeg} "${inputFile}" ${f_conversion} -map ${video_track} -map ${audio_track} -aspect 5:4 -s ${resolution} ${p_conversion} "${inputFileOut}-aspect.${v_ext}"
fi
fi
else
show_menu
fi
}
# Syntax: ks-crop <option> </absolute/path/video.mkv>
if [ -z "${1}" ] ; then
show_menu
exit
show_menu
exit
fi
if [ -f "${2}" ] ; then
echo "detected" > /dev/null
echo "detected" > /dev/null
else
errorReadingFile "${2}"
errorReadingFile "${2}"
fi
# Define variables for crop_video function
if [ "${1}" == "-16:9-crop" ] ; then
modeCrop="16:9-crop"
resolution="${to16_9}"
crop_video
modeCrop="16:9-crop"
resolution="${to16_9}"
crop_video
elif [ "${1}" == "-4:3-crop" ] ; then
modeCrop="4:3-crop"
resolution="${to4_3}"
crop_video
modeCrop="4:3-crop"
resolution="${to4_3}"
crop_video
elif [ "${1}" == "-5:4-crop" ] ; then
modeCrop="5:4-crop"
resolution="${to5_4}"
crop_video
modeCrop="5:4-crop"
resolution="${to5_4}"
crop_video
elif [ "${1}" == "-imax-crop" ] ; then
modeCrop="imax-crop"
resolution="${toImax}"
crop_video
modeCrop="imax-crop"
resolution="${toImax}"
crop_video
elif [ "${1}" == "-16:9-aspect" ] ; then
modeCrop="16:9-aspect"
resolution="${to16_9}"
crop_video
modeCrop="16:9-aspect"
resolution="${to16_9}"
crop_video
elif [ "${1}" == "-4:3-aspect" ] ; then
modeCrop="4:3-aspect"
resolution="${to4_3}"
crop_video
modeCrop="4:3-aspect"
resolution="${to4_3}"
crop_video
elif [ "${1}" == "-5:4-aspect" ] ; then
modeCrop="5:4-aspect"
resolution="${to5_4}"
crop_video
modeCrop="5:4-aspect"
resolution="${to5_4}"
crop_video
else
show_menu
show_menu
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)
error_ffmpeg=$?
if [ ${error_ffmpeg} -ne 0 ] ; then
echo ""
echo "* ks-mp3 (ks-tools) v${VERSION} (${M_DATE})"
echo ""
echo "+ The 'ffmpeg' tool is not installed!"
echo ""
exit
echo ""
echo "* ks-mp3 (ks-tools) v${VERSION} (${M_DATE})"
echo ""
echo "+ The 'ffmpeg' tool is not installed!"
echo ""
exit
fi
# Funcion to show the name of file/folder from full path
# Syntax: extractFolderOrFile <full/path/file.txt>
function extractFolderOrFile() {
pathToExtract="${1}/"
findFolder=0
count=1
nameFolder=$(echo ${pathToExtract} | cut -d "/" -f ${count})
count=$(expr $count + 1)
while [ ${findFolder} -eq 0 ] ; do
nameFolderTemp=$(echo ${pathToExtract} | cut -d "/" -f ${count})
if [ -z "${nameFolderTemp}" ] ; then
findFolder=1
else
nameFolder="${nameFolderTemp}"
count=$(expr $count + 1)
fi
done
echo "${nameFolder}"
pathToExtract="${1}/"
findFolder=0
count=1
nameFolder=$(echo ${pathToExtract} | cut -d "/" -f ${count})
count=$(expr $count + 1)
while [ ${findFolder} -eq 0 ] ; do
nameFolderTemp=$(echo ${pathToExtract} | cut -d "/" -f ${count})
if [ -z "${nameFolderTemp}" ] ; then
findFolder=1
else
nameFolder="${nameFolderTemp}"
count=$(expr $count + 1)
fi
done
echo "${nameFolder}"
}
# Function to remove extension from file
# Syntax: removeExtension "<text>"
function removeExtension() {
wordToConvert=${1}
ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt"
mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null
echo "${wordToConvert}" > ${ksToolsSedFile}
# Remove extensions
sed -i 's/.avi//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mp4//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mkv//g' "${ksToolsSedFile}" &> /dev/null
sed -i "s/.mov//g" "${ksToolsSedFile}" &> /dev/null
sed -i 's/.vob//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mpg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mpeg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.wmv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.ogv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.webm//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.flv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mp3//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mp2//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.oga//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.ogg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.ac3//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.aac//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.flac//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.wav//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.opus//g' "${ksToolsSedFile}" &> /dev/null
# Show file without extension
wordToConvert=$(cat ${ksToolsSedFile})
echo ${wordToConvert}
wordToConvert=${1}
ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt"
mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null
echo "${wordToConvert}" > ${ksToolsSedFile}
# Remove extensions
sed -i 's/.avi//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mp4//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mkv//g' "${ksToolsSedFile}" &> /dev/null
sed -i "s/.mov//g" "${ksToolsSedFile}" &> /dev/null
sed -i 's/.vob//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mpg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mpeg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.wmv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.ogv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.webm//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.flv//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mp3//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.mp2//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.oga//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.ogg//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.ac3//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.aac//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.flac//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.wav//g' "${ksToolsSedFile}" &> /dev/null
sed -i 's/.opus//g' "${ksToolsSedFile}" &> /dev/null
# Show file without extension
wordToConvert=$(cat ${ksToolsSedFile})
echo ${wordToConvert}
}
# Function to show files with spaces.
# Syntax: showFileWithSpace <file number>
function showFileWithSpace() {
echo "${1}" > ${dirTemp}/name.tmp
sed -i 's/_/ /g' ${dirTemp}/name.tmp
DisplayName=$(cat ${dirTemp}/name.tmp)
rm -rf ${dirTemp}/name.tmp
cutDisplayName=$(echo ${DisplayName} | cut -c1)
if [ "${cutDisplayName}" == "-" ] ; then
DisplayName=$(echo ${DisplayName} | cut -c2-100)
else
cutDisplayName=$(echo ${DisplayName} | cut -c2)
if [ "${cutDisplayName}" == "-" ] ; then
DisplayName=$(echo ${DisplayName} | cut -c3-100)
else
cutDisplayName=$(echo ${DisplayName} | cut -c3)
if [ "${cutDisplayName}" == "-" ] ; then
DisplayName=$(echo ${DisplayName} | cut -c4-100)
fi
fi
fi
echo ${DisplayName}
echo "${1}" > ${dirTemp}/name.tmp
sed -i 's/_/ /g' ${dirTemp}/name.tmp
DisplayName=$(cat ${dirTemp}/name.tmp)
rm -rf ${dirTemp}/name.tmp
cutDisplayName=$(echo ${DisplayName} | cut -c1)
if [ "${cutDisplayName}" == "-" ] ; then
DisplayName=$(echo ${DisplayName} | cut -c2-100)
else
cutDisplayName=$(echo ${DisplayName} | cut -c2)
if [ "${cutDisplayName}" == "-" ] ; then
DisplayName=$(echo ${DisplayName} | cut -c3-100)
else
cutDisplayName=$(echo ${DisplayName} | cut -c3)
if [ "${cutDisplayName}" == "-" ] ; then
DisplayName=$(echo ${DisplayName} | cut -c4-100)
fi
fi
fi
echo ${DisplayName}
}
# Syntax: ks-mp3 </absolute/path/song.ogg> </path/prefix_name>
if [ -z "${1}" ] ; then
echo ""
echo "* ks-mp3 (ks-tools) v${VERSION} (${M_DATE})"
echo ""
echo "- Convert video/audio file(s) to MP3 (Audio) Format"
echo ""
echo "+ Config:"
echo ""
echo " - Audio codec: ${acodec}"
echo " - Bitrate audio: ${b_acodec}"
echo " - Container: ${v_ext}"
echo ""
echo "+ Syntax: "
echo ""
echo " $ ks-mp3 </absolute/path/song.ogg> </path/prefix_name>"
echo ""
echo " + Example: ks-mp3 /data/songs/Example.ogg /data/converted/Example"
echo ""
exit
echo ""
echo "* ks-mp3 (ks-tools) v${VERSION} (${M_DATE})"
echo ""
echo "- Convert video/audio file(s) to MP3 (Audio) Format"
echo ""
echo "+ Config:"
echo ""
echo " - Audio codec: ${acodec}"
echo " - Bitrate audio: ${b_acodec}"
echo " - Container: ${v_ext}"
echo ""
echo "+ Syntax: "
echo ""
echo " $ ks-mp3 </absolute/path/song.ogg> </path/prefix_name>"
echo ""
echo " + Example: ks-mp3 /data/songs/Example.ogg /data/converted/Example"
echo ""
exit
fi
if [ -f "${1}" ] ; then
echo "detected" > /dev/null
echo "detected" > /dev/null
else
echo ""
echo "* ks-mp3 (ks-tools) v${VERSION} (${M_DATE})"
echo ""
echo "* The file '${1}' does not exist!"
echo ""
exit
echo ""
echo "* ks-mp3 (ks-tools) v${VERSION} (${M_DATE})"
echo ""
echo "* The file '${1}' does not exist!"
echo ""
exit
fi
# Conversion parameters
@ -153,132 +153,132 @@ p_ffmpeg="ffmpeg -i"
# Init conversion file
current_date=$(date +%Y)
if [ -z "${2}" ] ; then
echo ""
echo "* ks-mp3 (ks-tools) v${VERSION} (${M_DATE})"
echo ""
echo "- Convert video/audio file(s) to MP3 (Audio) Format"
echo ""
echo "+ Config:"
echo ""
echo " - Audio codec: ${acodec}"
echo " - Bitrate audio: ${b_acodec}"
echo " - Container: ${v_ext}"
echo ""
echo "+ Syntax: "
echo ""
echo " $ ks-mp3 </absolute/path/song.ogg> </path/prefix_name>"
echo ""
echo " + Example: ks-mp3 /data/songs/Example.ogg /data/converted/Example"
echo ""
exit
echo ""
echo "* ks-mp3 (ks-tools) v${VERSION} (${M_DATE})"
echo ""
echo "- Convert video/audio file(s) to MP3 (Audio) Format"
echo ""
echo "+ Config:"
echo ""
echo " - Audio codec: ${acodec}"
echo " - Bitrate audio: ${b_acodec}"
echo " - Container: ${v_ext}"
echo ""
echo "+ Syntax: "
echo ""
echo " $ ks-mp3 </absolute/path/song.ogg> </path/prefix_name>"
echo ""
echo " + Example: ks-mp3 /data/songs/Example.ogg /data/converted/Example"
echo ""
exit
else
echo ""
echo "* Information of ${1}:"
echo ""
echo "+ Audio Tracks:"
${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d "," -f 1
echo ""
echo ""
echo "* Information of ${1}:"
echo ""
echo "+ Audio Tracks:"
${p_ffmpeg} "${1}" 2>&1 | grep Stream | tr -s " " | grep "Audio:" | cut -d "," -f 1
echo ""
# 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)
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)
if [ -z "${audio_default}" ] ; then
audio_default="0:1"
else
audio_default_patch=$(echo ${audio_default} | cut -c4)
if [ "${audio_default_patch}" == ":" ] ; then
audio_default=$(echo ${audio_default} | cut -c1-3)
else
audio_default="${audio_default}"
fi
fi
else
audio_default_patch=$(echo ${audio_default} | cut -c4)
if [ "${audio_default_patch}" == ":" ] ; then
audio_default=$(echo ${audio_default} | cut -c1-3)
else
audio_default="${audio_default}"
fi
fi
# Ask for audio
echo -n "* (Default: ${audio_default}) Type the number of audio track: " ; read audio_track
if [ -z "${audio_track}" ] ; then
audio_track="${audio_default}"
else
audio_track="${audio_track}"
fi
# 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)
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)
if [ -z "${audio_default}" ] ; then
audio_default="0:1"
else
audio_default_patch=$(echo ${audio_default} | cut -c4)
if [ "${audio_default_patch}" == ":" ] ; then
audio_default=$(echo ${audio_default} | cut -c1-3)
else
audio_default="${audio_default}"
fi
fi
else
audio_default_patch=$(echo ${audio_default} | cut -c4)
if [ "${audio_default_patch}" == ":" ] ; then
audio_default=$(echo ${audio_default} | cut -c1-3)
else
audio_default="${audio_default}"
fi
fi
# Ask for audio
echo -n "* (Default: ${audio_default}) Type the number of audio track: " ; read audio_track
if [ -z "${audio_track}" ] ; then
audio_track="${audio_default}"
else
audio_track="${audio_track}"
fi
# Ask for METADATA
echo ""
echo "* METADATA configuration:"
echo ""
# Prepare name title by default
FullPath="${1}"
name_title_default=$(extractFolderOrFile "${FullPath}")
name_title_default=$(removeExtension "${name_title_default}")
name_title_default=$(showFileWithSpace "${name_title_default}")
# Ask name title, year and genre
echo -n "* (Default: ${name_title_default}) Type name of title: " ; read name_title
if [ -z "${name_title}" ] ; then
name_title="${name_title_default}"
else
name_title="${name_title}"
fi
echo -n "* (Default: Album-Disc) Type name of album: " ; read album_file
if [ -z "${album_file}" ] ; then
album_title="Album-Disc"
else
album_title="${album_file}"
fi
echo -n "* (Default: 01) Type number of track: " ; read track_file
if [ -z "${track_file}" ] ; then
track_num="01"
else
track_num="${track_file}"
fi
echo -n "* (Default: Artist) Type name of artist: " ; read artist_file
if [ -z "${artist_file}" ] ; then
artist_title="Artist"
else
artist_title="${artist_file}"
fi
echo -n "* (Default: ${current_date}) Type the year: " ; read year_file
if [ -z "${year_file}" ] ; then
year_num="${current_date}"
else
year_num="${year_file}"
fi
echo -n "* (Default: Pop) Type the genre: " ; read genre_file
if [ -z "${genre_file}" ] ; then
genre_file="Pop"
else
genre_file="${genre_file}"
fi
# Ask for METADATA
echo ""
echo "* METADATA configuration:"
echo ""
# Prepare name title by default
FullPath="${1}"
name_title_default=$(extractFolderOrFile "${FullPath}")
name_title_default=$(removeExtension "${name_title_default}")
name_title_default=$(showFileWithSpace "${name_title_default}")
# Ask name title, year and genre
echo -n "* (Default: ${name_title_default}) Type name of title: " ; read name_title
if [ -z "${name_title}" ] ; then
name_title="${name_title_default}"
else
name_title="${name_title}"
fi
echo -n "* (Default: Album-Disc) Type name of album: " ; read album_file
if [ -z "${album_file}" ] ; then
album_title="Album-Disc"
else
album_title="${album_file}"
fi
echo -n "* (Default: 01) Type number of track: " ; read track_file
if [ -z "${track_file}" ] ; then
track_num="01"
else
track_num="${track_file}"
fi
echo -n "* (Default: Artist) Type name of artist: " ; read artist_file
if [ -z "${artist_file}" ] ; then
artist_title="Artist"
else
artist_title="${artist_file}"
fi
echo -n "* (Default: ${current_date}) Type the year: " ; read year_file
if [ -z "${year_file}" ] ; then
year_num="${current_date}"
else
year_num="${year_file}"
fi
echo -n "* (Default: Pop) Type the genre: " ; read genre_file
if [ -z "${genre_file}" ] ; then
genre_file="Pop"
else
genre_file="${genre_file}"
fi
# 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_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}"
if [ -z "${audio_5_7_1}" ] ; then
stereo_params="-ac 2"
else
stereo_params="-ac 2 -clev 3dB -slev -6dB"
fi
# 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_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}"
if [ -z "${audio_5_7_1}" ] ; then
stereo_params="-ac 2"
else
stereo_params="-ac 2 -clev 3dB -slev -6dB"
fi
# Show commands for conversion
echo ""
echo "* COMMANDS THAT WILL BE EXECUTED:"
echo ""
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}\""
# Show commands for conversion
echo ""
echo "* COMMANDS THAT WILL BE EXECUTED:"
echo ""
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}\""
# Execute commands for conversion
echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit
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}"
fi
# Execute commands for conversion
echo ""
echo -n "* (Default: y) Do you want run the conversion? (y/n): " ; read run_commands_ffmpeg
if [ "${run_commands_ffmpeg}" == "n" ] ; then
exit
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}"
fi
fi

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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