2021-03-06 12:54:52 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#################################################################################
|
|
|
|
# ks-mp4s-folder (ks-tools) - Convert videos from folder to MP4 format (Series) #
|
2021-03-23 14:05:48 +01:00
|
|
|
# Date: 23-03-2021 #
|
2021-03-06 12:54:52 +01:00
|
|
|
# Author: q3aql #
|
|
|
|
# Contact: q3aql@protonmail.ch #
|
|
|
|
#################################################################################
|
2021-03-23 14:05:48 +01:00
|
|
|
VERSION="6.9"
|
|
|
|
M_DATE="230321"
|
2021-03-06 12:54:52 +01:00
|
|
|
|
|
|
|
# Variables
|
|
|
|
tempFile="/tmp/ks-mp4s-folder.txt"
|
|
|
|
tempFileTest="/tmp/ks-mp4s-folder-test.txt"
|
2021-03-09 10:46:33 +01:00
|
|
|
formatFiles="mp4 avi mpg mpeg mov wmv mkv ogv webm rm flv vob ts"
|
2021-03-06 12:54:52 +01:00
|
|
|
|
|
|
|
# Show help when folder is empty
|
|
|
|
if [ -z "${1}" ] ; then
|
|
|
|
echo ""
|
|
|
|
echo "* ks-mp4s-folder (ks-tools) v${VERSION} (${M_DATE})"
|
|
|
|
echo ""
|
|
|
|
echo "- Convert videos from folder to MP4 format (Series)"
|
|
|
|
echo ""
|
2021-03-22 19:01:31 +01:00
|
|
|
echo "+ Syntax: "
|
2021-03-06 12:54:52 +01:00
|
|
|
echo ""
|
|
|
|
echo " $ ks-mp4s-folder </path/folder> [subs]"
|
|
|
|
echo ""
|
|
|
|
echo " + Examples: "
|
|
|
|
echo " $ ks-mp4s-folder /data/Westworld"
|
|
|
|
echo " $ ks-mp4s-folder /data/Daredevil subs"
|
|
|
|
echo ""
|
|
|
|
echo "* Notes:"
|
|
|
|
echo ""
|
|
|
|
echo " + The option 'subs' apply detection & rendering the forced subtitles."
|
|
|
|
echo " + You must not use spaces in folders and video files."
|
|
|
|
echo ""
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check if folder exist
|
|
|
|
if [ -d "${1}" ] ; then
|
|
|
|
echo null > /dev/null
|
|
|
|
else
|
|
|
|
echo ""
|
|
|
|
echo "* ks-mp4s-folder (ks-tools) v${VERSION} (${M_DATE})"
|
|
|
|
echo ""
|
|
|
|
echo "+ The folder '${1}' does not exist!"
|
|
|
|
echo ""
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Scan videos files format
|
|
|
|
clear
|
|
|
|
echo ""
|
|
|
|
echo "* ks-mp4s-folder (ks-tools) v${VERSION} (${M_DATE})"
|
|
|
|
echo ""
|
|
|
|
echo "- Convert videos from folder to MP4 format (Series)"
|
|
|
|
echo ""
|
|
|
|
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
|
|
|
|
done
|
|
|
|
|
|
|
|
# Init the conversion files
|
|
|
|
num_files=$(cat ${tempFile} | wc -l)
|
|
|
|
if [ ${num_files} -eq 0 ] ; then
|
|
|
|
echo ""
|
|
|
|
echo "+ No video file(s) found in folder '${1}"
|
|
|
|
echo ""
|
|
|
|
exit
|
|
|
|
else
|
|
|
|
echo ""
|
|
|
|
echo "* Files to convert (${1}):"
|
|
|
|
convert_files=1
|
|
|
|
if [ "${2}" == "subs" ] ; then
|
|
|
|
subtitles_enabled=1
|
|
|
|
subtitles_show="with subtitles"
|
|
|
|
else
|
|
|
|
subtitles_enabled=0
|
|
|
|
subtitles_show="without subtitles"
|
|
|
|
fi
|
|
|
|
while [ ${convert_files} -le ${num_files} ] ; do
|
|
|
|
show_file=$(cat ${tempFile} | head -${convert_files} | tail -1)
|
|
|
|
echo " + ${show_file} (${subtitles_show})"
|
|
|
|
convert_files=$(expr ${convert_files} + 1)
|
|
|
|
done
|
|
|
|
echo ""
|
|
|
|
echo "* The output folder will be '${1}/to-mp4'"
|
|
|
|
# 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-mp4 && rm -rf to-mp4/*
|
|
|
|
while [ ${convert_files} -le ${num_files} ] ; do
|
|
|
|
show_file=$(cat ${tempFile} | head -${convert_files} | tail -1)
|
|
|
|
if [ ${subtitles_enabled} -eq 1 ] ; then
|
|
|
|
fname=$(echo "${show_file}" | cut -d "." -f 1)
|
|
|
|
ks-mp4s-wrapper --conv-with-sub "${show_file}" "to-mp4/${fname}"
|
|
|
|
else
|
|
|
|
fname=$(echo "${show_file}" | cut -d "." -f 1)
|
|
|
|
ks-mp4s-wrapper --conv "${show_file}" "to-mp4/${fname}"
|
|
|
|
fi
|
|
|
|
convert_files=$(expr ${convert_files} + 1)
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
fi
|