SplitVideo/splitVideoGUI

94 lines
1.8 KiB
Plaintext
Raw Permalink Normal View History

2020-09-23 19:51:42 +02:00
#!/bin/bash
#
# Thanks to ...
# the guys at puri.sm for their article about yad:
# * [https://wp.puri.sm/posts/easy-librem-5-app-development-take-a-screenshot/]()
#
# as well as this website:
# * http://smokey01.com/yad/
#
function doStuff(){
# :param $1: user-input
# Parse user input
SRC=`echo $1 | cut -d '|' -f1`
H=`echo $1 | cut -d '|' -f2`
M=`echo $1 | cut -d '|' -f3`
S=`echo $1 | cut -d '|' -f4`
# Print input to stdout
printf "SRC:\t%s\n" "$SRC"
printf "Time:\t%s:%s:%s\n" "$H" "$M" "$S"
# Calculate time in seconds
# H(ours) + M(inutes) + S(econds) -> S(econds)
HS="$(( 3600 * $H ))"
MS="$(( 60 * $M ))"
S="$(( $HS + $MS + $S ))"
printf "Seconds: %s\n" "$S"
# Split Video at specific time
splitVideo "$SRC" "$S"
errno="$?"
# inform user of result
case "$errno" in
"0")
TITLE="SUCCESS"
TEXT="Done! Check out the _a.mkv and _b.mkv files next to your input file."
;;
*)
TITLE="ERROR"
TEXT="An error occured with code $errno."
;;
esac
echo "$TEXT" | yad --title="$TITLE" --wrap --text-info
# return exitCode of splitVideo
return "$errno"
}
function main(){
# TODO check if yad installed
# Get user input via yad (GUI)
INPUT=`yad --title "splitVideo" --text="Split video at specific time" --form \
--field=video:SFL \
--field=hours:NUM \
--field=minutes:NUM \
--field=seconds:NUM \
"splitMeUp.mp4" "1" "15" "5" --focus-field=1`
case "$?" in
"0")
echo "User pressed 'OK'"
doStuff "$INPUT"
exit "$?"
;;
"1")
echo "User pressed 'cancel'"
exit 0
;;
"252")
echo "User closed window."
exit 0
;;
*)
echo "An unexpected error has occurred: Code $?"
exit 1
;;
esac
}
main "$@"