[ "$1" == "-D" ] && DEBUG=1 && shift 1
PS4='$SECONDS $LINENO: '
DOW=$(date +%a)
TODAY=$(date +%m/%d)
DOM=$(date +%d)
OS=$(uname -s)
NAME=${0##*/}
LOG=~/etc/${HOSTNAME}.log
R=$(tput setaf 1)
BR=$(tput setaf 1; tput bold)
G=$(tput setaf 2)
BG=$(tput setaf 2; tput bold)
Y=$(tput setaf 3)
BY=$(tput setaf 3; tput bold)
B=$(tput setaf 4)
BM=$(tput setaf 5; tput bold)
C=$(tput setaf 6)
BC=$(tput setaf 6; tput bold)
BL=$(tput setaf 7; tput bold)
BLD=$(tput bold)
N=$(tput sgr0)
SIT=$(tput sitm)
RIT=$(tput ritm)
UL=$(tput smul)
NL=$(tput rmul)
RV=$(tput rev)
ROWS=$(tput lines)
COLS=$(tput cols)
bl(){
[ "$DEBUG" == "1" ] && set -x
echo ""
}
html(){
vim -f +"syn on" +"set nonu" +"set foldenable!" +"set nospell" +"run! syntax/2html.vim" +"wq" +"q" $1
}
log(){
[ "$DEBUG" == "1" ] && set -x
if [ "$#" -eq 0 ]
then
echo $BC
vd $LOG 2>/dev/null ||tail -7 $LOG
echo $N
else
echo -e "$(date '+%D%t%T')\t${NAME}\t$*">>"$LOG"
fi
}
pause(){
[ "$DEBUG" == "1" ] && set -x
[ "$1" == "-nt" ] && TMOUT="" && shift
echo "$BY";
if [ $# -gt 0 ]
then
read -t $1 -r -p "${C}Hit any key (${BY}$1${C} second timeout)${N}" -n 1 FOO;
else
read -r -p "${C}Hit any key${N}" -n 1 FOO;
fi;
bl
}
xtitle(){
printf "\033]0;%s\007" "$*"
}
if [ "$1" == "-E" ]
then
vim $0
sed -i -e "7s/.*/# Updated....: $(date)/" $0
html $0
cp $0 /var/www/unix
mv $0.html /var/www/unix
cp $0 /var/gopher/scripts
exit
fi
if [ "$1" == "-h" ] || [ "$1" == "--help" ]
then
fmt -s -w $(tput cols) <<END
$NAME # list media, displays mp4's and mp3's in a directory and gives run time
${BG}lm${N} ${BY}{/path}${N}
# no option performs listing in current directory
{/path} # performs function on path noted
${UL}List mp4 files first and then mp3 files.${N}
END
exit
fi
command -v bash >/dev/null || sudo apt install bash -qyy
command -v ffmpeg >/dev/null || sudo apt install ffmpeg -yyq
command -v exiftool >/dev/null || sudo apt install libimage-exiftool-perl -yyq
command -v exa >/dev/null || sudo apt install exa -yyq
[ "$DEBUG" == "1" ] && set -x
[ "$#" -eq 1 ] && [ -d $1 ] && cd $1
if [ $(ls -A *.mp? *.m4v 2>/dev/null|wc -l) -lt 1 ]
then
exa --header --icons --tree --level=1 -l --group-directories-first
exit 1
fi
for f in $(\ls -S -r *.mp?)
do
chmod a-x *.mp?
ffmpeg -i "$f" 2>&1 | grep --color=always Duration | cut -d " " -f 4 | sed s/,// | tr -d "\n" && echo -n " " && exa --icons "$f";
done
bl
echo "${BY}Total: $(exiftool -n -q -p '${Duration;our $sum;$_=ConvertDuration($sum+=$_) }' ./*.mp4 2>/dev/null| tail -n1)$N"
bl
[ -f /tmp/$$ ] && rm /tmp/$$ >/dev/null 2>&1 || :