#!/bin/sh

##### Remainer
# This script figures out how much longer it'll
# take for your precious video to be converted.
# Can't you be paitent for a change?
# Honestly...Just sit down and wait.
# It'll be done when it's done.

## Grab the current video percentage and start time.
percent=$1
starttime=$2
decimal=$3

if [ "$decimal" = "comma" ]
then
percent=`echo $percent | sed -e 's/,/\./g'`
fi
## I forgot how this works.
## I was a lot smarter when I first wrote it...
## It does something like calculate how long it's been converting,
## and doing some math stuff, multiplies something by
## some percentage derivative. It usually works.
nowtime=`/bin/date +%s | cut -c 5-`
spenttime=`echo "$nowtime - $starttime" | bc`
smallpercent=`echo $percent`
leftpercent1=`echo 1 - $smallpercent | bc`
leftpercent=`echo $leftpercent1 / $smallpercent | bc -l`
spentleft1=`echo "$spenttime * $leftpercent" / 60 | bc -l`
spentleft=`echo 0$spentleft1`

finalnumber=$spentleft
#finalnumber=`echo $spentleft | awk -F . '{print $1}'`

if [ "$decimal" = "comma" ]
then
echo $finalnumber + 1 | bc | sed -e 's/\./,/g' | cut -c 1-7
else
echo $finalnumber + 1 | bc | cut -c 1-7
fi
exit 0