Skip to content

Instantly share code, notes, and snippets.

@KittyKatt
Last active December 18, 2015 17:29
Show Gist options
  • Save KittyKatt/5819006 to your computer and use it in GitHub Desktop.
Save KittyKatt/5819006 to your computer and use it in GitHub Desktop.
screenshot taking and uploading tool
#!/usr/bin/env bash
# scrotshooter - screenshot taking and upload tool
# requires: curl, scrot
mydir="$HOME/Pictures/Screenshots"
shotfile=$(echo "screenshot-`date +'%Y-%m-%d_%H-%M-%S'`.png")
fileloc="$mydir/$shotfile"
while getopts ":d:" flags; do
case $flags in
d) destination="$OPTARG";;
esac
done
scrot -mcd3 "$fileloc"
if [[ -f "${fileloc}" ]]; then
printf ">>> Shot taken. Uploading..."
case "$destination" in
# image sharing sites
'imgur')
desturl='http://imgur.com/upload'
baseurl='http://imgur.com'
my_output=$(curl --silent -F name=file -F file="@${fileloc}" "${desturl}")
my_hash=$(echo "$my_output" | grep -Eo '\[\\".+\\"\]' | sed -e 's/^\[\\"//' -e 's/\\"\]//')
if [[ -n "${my_hash}" ]]; then
printf 'done.\n'
uploaded='true'
returnurl="${baseurl}/${my_hash}"
fi
;;
'pomf')
desturl='http://pomf.se/new/up.php'
baseurl='http://a.pomf.se'
my_output=$(curl --silent -F qqfile="@${fileloc}" "${desturl}")
if [[ "${my_output}" =~ '"success":true,' ]]; then
rfileloc=$(echo "$my_output" | awk -F '"' '{print $6}')
printf 'done.\n'
uploaded='true'
returnurl="${baseurl}/${rfileloc}"
fi
;;
# goput api is currently mia
# 'goput')
# desturl='http://goput.it/gp5/handle.php'
# my_output=$(curl --silent -F name=file1 -F file="@${fileloc}" "${desturl}")
# my_url=$(echo "$my_output" | grep -Eo 'value="http://.+"' | sed -e 's/^value="//' -e 's/"$//')
# if [[ -n "${my_url}" ]]; then
# printf 'done.\n'
# uploaded='true'
# returnurl="${my_url}"
# fi
#;;
'hmp')
desturl='http://hmp.me/ap/?uf=1'
baseurl='http://i.hmp.me/m'
my_output=$(curl --silent -F "a=@${fileloc};type=image/png" "${desturl}")
rfileloc=$(echo "$my_output" | grep -Eom 1 '[[:alnum:]]*\.(png|jpg|gif)')
if [[ -n "${rfileloc}" ]]; then
printf 'done.\n'
uploaded=true
returnurl="${baseurl}/${rfileloc}"
fi
;;
# local servers
'silvanus')
baseurl="http://screens.kittykatt.us"
hostdir="$HOME/sshfs/silvanus-srv/http/kittykatt.us/screens.kittykatt.us"
cp "$fileloc" $hostdir/
if [[ -f "${hostdir}/${shotfile}" ]]; then
printf 'done.\n'
uploaded='true'
returnurl="${baseurl}/${shotfile}"
fi
;;
?) echo 'Error! Unknown destination!'; exit 1;;
esac
if [[ "$uploaded" == "true" ]]; then
echo ">>> Local screenshot location: $fileloc"
echo ">>> Your screenshot can be viewed at ${returnurl}."
exit 0
else
printf 'Error! File not uploaded!\n'
exit 1
fi
else
printf "Error! File was not found!\n"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment