Skip to content

Instantly share code, notes, and snippets.

@oglops
Last active Aug 29, 2015
Embed
What would you like to do?
用gyfcat来上传 用法 gif-batch.sh -wc 或者 -rc
#!/usr/bin/env bash
# the convert call depends on whether you have h264 support in
# convert -list format
# if you don't have it , then record to -vcodec huffyuv
# if you see convert: Not enough pixel data `/tmp/x.avi' @ avi.c/ReadAVIImage/1243.
# maybe try removing -vcodec completely and use uncompressed avi
if [ $# -ne 1 ]; then
echo -e "Usage: \n\t git-batch.sh -wruc\n\n"
exit 0
fi
control_c()
# run if user hits control-c
{
echo -en "\n*** Ouch! Exiting ***\n"
# cleanup
exit $?
}
# trap keyboard interrupt (control-c)
trap control_c SIGINT
while getopts "wruc" OPTION; do
case $OPTION in
w) echo recording window
RECORD_WINDOW=true
FFCAST_PARAM="-w"
# ;& # this means continue to execute the next block without testing its pattern
;&
r) echo recording
TMP_AVI=$(mktemp /tmp/outXXXXXXXXXX.avi)
TMP_GIF=$(mktemp /tmp/outXXXXXXXXXX.gif)
if [ "$RECORD_WINDOW" = true ] ; then
echo "recording window is true"
fi
RECORD_CMD=$(echo ffcast ${FFCAST_PARAM:--s} ffmpeg -y -r 20 $TMP_AVI \&\& convert -set delay 10 -layers Optimize $TMP_AVI $TMP_GIF)
echo Record command : $RECORD_CMD
eval $RECORD_CMD
export TMP_GIF=$TMP_GIF
# gwenview $TMP_GIF >/dev/null 2>&1
gthumb --viewer $TMP_GIF >/dev/null 2>&1
echo recorded gif : $TMP_GIF
# exit 0
;;&
u) maxsize=2048
TMP_GIF=$(ls -t /tmp/out*.gif | head -1)
actualsize=$(du -k $TMP_GIF | cut -f 1)
echo actialsize: $actualsize
if [ $actualsize -ge $maxsize ]
then
TMP_GIF2=$(mktemp /tmp/outXXXXXXXXXX.gif)
gifsicle -O2 --colors 64 $TMP_GIF > $TMP_GIF2
TMP_GIF = $TMP_GIF2
fi
echo 'uploading gif : '$TMP_GIF
# http://imgur.com/tools
~/scripts/imgurbash.sh $TMP_GIF
exit 0
;;&
c) # upload to gyfcat
echo Uploading to gyfcat
GYFCAT_KEY=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 1)
curl -i -F "key=$GYFCAT_KEY" -F "acl=private" -F "AWSAccessKeyId=AKIAIT4VU4B7G2LQYKZQ" -F "policy=eyAiZXhwaXJhdGlvbiI6ICIyMDIwLTEyLTAxVDEyOjAwOjAwLjAwMFoiLAogICAgICAgICAgICAiY29uZGl0aW9ucyI6IFsKICAgICAgICAgICAgeyJidWNrZXQiOiAiZ2lmYWZmZSJ9LAogICAgICAgICAgICBbInN0YXJ0cy13aXRoIiwgIiRrZXkiLCAiIl0sCiAgICAgICAgICAgIHsiYWNsIjogInByaXZhdGUifSwKCSAgICB7InN1Y2Nlc3NfYWN0aW9uX3N0YXR1cyI6ICIyMDAifSwKICAgICAgICAgICAgWyJzdGFydHMtd2l0aCIsICIkQ29udGVudC1UeXBlIiwgIiJdLAogICAgICAgICAgICBbImNvbnRlbnQtbGVuZ3RoLXJhbmdlIiwgMCwgNTI0Mjg4MDAwXQogICAgICAgICAgICBdCiAgICAgICAgICB9" -F "success_action_status=200" -F "signature=mk9t/U/wRN4/uU01mXfeTe2Kcoc=" -F "Content-Type=image/gif" -F "file=@$TMP_GIF" https://gifaffe.s3.amazonaws.com/
echo GYFCAT_KEY: $GYFCAT_KEY
echo transcoding ...
# maybe i shoudl use jq to parse json file
# http://stedolan.github.io/jq/
function jsonval {
temp=`echo $json | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w $prop`
echo ${temp##*|}
}
json=$(curl http://upload.gfycat.com/transcode/$GYFCAT_KEY --silent)
prop='gfyName'
gyfid=`jsonval`
prop='mp4Url'
mp4Url=`jsonval`
prop='webmUrl'
webmUrl=`jsonval`
prop='gifUrl'
gifUrl=`jsonval`
echo API Response: $json
echo
echo gyfid: $gyfid
echo mp4Url: $mp4Url
echo webmUrl: $webmUrl
echo gifUrl: $gifUrl
echo ---------------
echo gyfurl: http://gfycat.com/$gyfid
exit 0
;;
*) # echo "Incorrect options provided" exit 1 ;;
echo "done"
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment