99 lines
2.8 KiB
Bash
99 lines
2.8 KiB
Bash
#/bin/sh
|
|
CURRENT_DATE=$(date +%Y%m%d_%H%M)
|
|
bold=$(tput bold)
|
|
normal=$(tput sgr0)
|
|
|
|
# $1 = video file / $2 = result file
|
|
get_mediainfo() {
|
|
echo "Processing " "$1" "..."
|
|
echo -ne "\" "$1" \", " >> "$2"
|
|
mediainfo --Inform="Video;%Format%, %Format_Profile%, %CodecID%" "$1" >> "$2"
|
|
}
|
|
|
|
gather_data() {
|
|
echo "Gathering data..."
|
|
|
|
echo "Test path => " "$1"
|
|
|
|
RESULT_PATH=./$1/videoinfo-"$CURRENT_DATE".csv
|
|
PWD=$(pwd $1)/$1
|
|
|
|
echo "$PWD"
|
|
echo "$RESULT_PATH"
|
|
|
|
echo "$PWD" >> "$RESULT_PATH"
|
|
echo 'File, Format, Format Profile, Codec ID' >> "$RESULT_PATH"
|
|
find "$1" -type f \( -iname \*.mkv -o -iname \*.mp4 -o -iname \*.avi \) | while read file;
|
|
do
|
|
get_mediainfo "$(pwd $1)/$file" "$RESULT_PATH"
|
|
done
|
|
echo "Finished! Result file is located at ${bold}$RESULT_PATH${normal}."
|
|
|
|
exit
|
|
}
|
|
|
|
gather_data_continue() {
|
|
echo "Continue gather data of file ${bold}$1${normal}..."
|
|
|
|
LAST_LINE=$(tail -n 1 $1)
|
|
LAST_FILE=$(echo $LAST_LINE | sed 's/^\"\(.*\)\".*$/\1/g')
|
|
|
|
# where to find the files...
|
|
FIRST_LINE=$(head -n 1 $1)
|
|
|
|
# remove last line of file (might print error on WSL, hence the error suppression)
|
|
sed -i '$d' $1 2>/dev/null
|
|
|
|
FOUND_FILE=0
|
|
find $FIRST_LINE -type f \( -iname \*.mkv -o -iname \*.mp4 -o -iname \*.avi \) | while read file;
|
|
do
|
|
if [[ $file == $LAST_FILE ]]; then
|
|
FOUND_FILE=1
|
|
fi
|
|
|
|
if [[ $FOUND_FILE == 1 ]]; then
|
|
get_mediainfo "$file" $1
|
|
fi
|
|
done
|
|
echo "Finished! Result file is located at ${bold}$1${normal}."
|
|
}
|
|
|
|
continue_gather() {
|
|
if [[ $1 == "" ]]; then
|
|
echo "No input file. Please input CSV file generated by this program."
|
|
elif [[ -f $1 ]]; then
|
|
gather_data_continue $1
|
|
else
|
|
echo "File ${bold}$1${normal} does not exist."
|
|
fi
|
|
}
|
|
|
|
show_usage() {
|
|
echo -e "This tool generates a CSV file with useful video data\n"
|
|
echo -e "Options:"
|
|
echo -e "./video-info.sh [-h, --help]"
|
|
echo -e "\t\tDisplays help and usage.\n"
|
|
echo -e "./video-info.sh DIRECTORY"
|
|
echo -e "\t\tCreates a CSV file from all the video files from the directory.\n"
|
|
echo -e "./video-info.sh [-c, --continue] FILE"
|
|
echo -e "\t\tIf the gathering was interrupted, use this option to resume."
|
|
echo -e "\t\tTakes the incompletely generated CSV file as a parameter.\n"
|
|
echo -e "There are some limitations as this is a pretty simple tool. If you have any issue,"
|
|
echo -e "please read the README file."
|
|
}
|
|
|
|
if [[ $1 == "" ]] || [[ $1 == "--help" ]] || [[ $1 == "-h" ]]; then
|
|
show_usage
|
|
exit
|
|
elif [[ $1 == "-c" ]] || [[ $1 == "--continue" ]]; then
|
|
continue_gather $2
|
|
else
|
|
if [[ -d $1 ]]; then
|
|
echo "Gather data"
|
|
gather_data "$1"
|
|
else
|
|
echo -e "Directory ${bold}$1${normal} does not exist. Showing usage...\n"
|
|
show_usage
|
|
fi
|
|
fi
|