Advertising
- up2pcn
- 2012 year 5 month 5 day Saturday 03:50:32 MDT
- #!/usr/bin/env bash
- #
- # up2pcn
- # uploads pics to pics.cheggit.nl using curl
- # version 0.2 + Dumppix & freeimage.us patch
- #
- # Copyright (c) 2009-2011 by upgrader
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
- # USA.
- #
- # Changelog :
- # * 2009/11/15 - First version
- # * 2011/06/15 - Fix - vars in bash4 - thanks vrak
- # Fix - find trouble - thanks happypenguin
- # Fix - minor code changes
- # New - added -s flag for purists - thanks vrak
- #
- # Dumppix patch (ishirog)
- # * 2011/07/27 - New - added -d flag to support dummpix.com
- #
- # freeimage.us patch (ishirog)
- # * 2012/02/01 - New - added -e flag to support freeimage.us
- #
- # ToDo :
- # * Add alternative imagehost (this will be a shitload of work)
- set -e
- # config vars. don't touch if you don't know what you're doing!
- ALLOWED_FILES="GIF\|JPG\|PNG\|SWF"
- QUIET="-#"
- DEFAULTPICHOST="http://pics.cheggit.nl"
- DEFAULTSUBMIT="-F action=Upload\ Image"
- DEFAULTMAXSIZE="2000k"
- DEFAULTMAXFILES="7"
- DEFAULTGREPOPT='\[url=\([^[:space:]]*\)\[/url\]'
- DUMPPIXPICHOST="http://dumppix.com/upload.php"
- DUMPPIXSUBMIT=""
- DUMPPIXMAXSIZE="8000k"
- DUMPPIXMAXFILES="20"
- DUMPPIXGREPOPT='^\[url.*'
- EMPPICHOST="http://xxx.freeimage.us/upload.php"
- EMPSUBMIT="-F typ=m"
- EMPMAXSIZE="8000k"
- EMPMAXFILES="7"
- EMPGREPOPT='\"\[url=http.*thumb\.php.*]'
- PICHOST=${DEFAULTPICHOST}
- MAXSIZE=${DEFAULTMAXSIZE}
- MAXFILES=${DEFAULTMAXFILES}
- SUBMIT=${DEFAULTSUBMIT}
- # regexps to format (standard) output
- SEDOPT='s/\[url=//g;s/\]\(.*\)//g'
- # help and usage text
- usage() {
- local P=$(basename $0)
- cat <<EOF
- This script uploads pictures to pics.cheggit.nl using cURL.
- Usage: $P [options] <file(s) or directory>
- Options:
- The script will always return the URLs of the pictures uploaded. If you're
- fine with that, you won't have to bother with the options. If you prefer the
- Quickpaste option, you might want to take a closer look here.
- -b BBCode: [img]yourfile[/img]
- -h Show this text.
- -l HTML version of -b
- -q Quickpaste BBCode (thumbnail with link to original) for each
- file.
- -t HTML version of -q.
- -s Script talks too much? Try this.
- -d Upload to dumppix.com
- -c Upload to pics.cheggit.nl (default)
- -e Upload to freeimage.us
- Options will probably be extended in future versions, so if you're missing
- something, suggest it!
- Examples:
- Upload a single image:
- \$ $P mypicture.png
- Upload all supported image files in a directory:
- \$ $P ~/mypics
- Upload all .jpg files in directory:
- \$ $P *.jpg
- For more examples and help, go to the cheggit forums!
- <http://cheggit.net/forum/read.php?29,98046>.
- EOF
- }
- # This is where we start working :)
- # First, let's see if we've got all programs we require
- for prog in curl grep sed mktemp; do
- if ! type -pf "$prog" ; then
- ERROR="Required program $prog not found!"
- fi >/dev/null
- done
- if [ -n "$ERROR" ]
- then
- echo $ERROR
- exit 1
- fi
- # process options
- if [ $# -eq 0 ]
- then
- usage
- exit 1
- fi
- while getopts ":bhlqtscde" Option
- do
- case $Option in
- b ) FORMAT=bbcode ;;
- l ) FORMAT=html ;;
- q ) FORMAT=quickbbcd ;;
- t ) FORMAT=quickhtml ;;
- s ) QUIET="-s" ;;
- c ) PICHOST=${DEFAULTPICHOST}; MAXSIZE=${DEFAULTMAXSIZE}; MAXFILES=${DEFAULTMAXFILES}; SUBMIT=${DEFAULTSUBMIT};;
- d ) PICHOST=${DUMPPIXPICHOST}; MAXSIZE=${DUMPPIXMAXSIZE}; MAXFILES=${DUMPPIXMAXFILES}; SUBMIT=${DUMPPIXSUBMIT};;
- e ) PICHOST=${EMPPICHOST}; MAXSIZE=${EMPMAXSIZE}; MAXFILES=${EMPMAXFILES}; SUBMIT=${EMPSUBMIT};;
- h ) usage ; exit 0 ;;
- * ) usage ; exit 1 ;;
- esac
- done
- shift $(( $OPTIND - 1 ))
- if [ "${PICHOST}" = "${DEFAULTPICHOST}" ]; then
- case $FORMAT in
- bbcode ) SEDOPT='s/\[url=/\[img\]/g;s/\]\[img\]\(.*\)/\[\/img\]/g' ;; #'
- html ) SEDOPT='s/\[url=/<img src=\"/g;s/\]\[img\]\(.*\)/\" \/>/g' ;;
- quickbbcd) SEDOPT='/^#/d' ;;
- quickhtml) SEDOPT='s/\[url=/<a href=\"/g;s/\]\[img\]/\"><img src="/g;s/\[\/img\]\[\/url\]/\" \/><\/a>/g' ;;
- esac
- GREPOPT="${DEFAULTGREPOPT}"
- elif [ "${PICHOST}" = "${DUMPPIXPICHOST}" ]; then
- case $FORMAT in
- bbcode ) SEDOPT='s/\[url=.*\[img]/\[img]/;s/\[\/url]//;s/_thumb\./\./' ;;
- html ) SEDOPT='s/\[url=.*\[img]/\[img]/;s/\[\/url]//;s/\[img]/<img src=\"/;s/\[\/img]/\" \/>/;s/_thumb\./\./' ;;
- quickbbcd) SEDOPT='/^#/d' ;;
- quickhtml) SEDOPT='s/\[url=/<a href=\"/g;s/\]\[img\]/\"><img src="/g;s/\[\/img\]\[\/url\]/\" \/><\/a>/g' ;;
- esac
- GREPOPT="${DUMPPIXGREPOPT}"
- elif [ "${PICHOST}" = "${EMPPICHOST}" ]; then
- case $FORMAT in
- bbcode ) SEDOPT='s/.//;s/^[^]]*]//;s/\[\/url.*//;s/thumb\.php/image.php/' ;;
- html ) SEDOPT='s/.//;s/^[^]]*]//;s/\[\/url.*//;s/thumb\.php/image.php/;s/\[img]/<img src=\"/;s/\[\/img]/\" \/>/' ;;
- quickbbcd) SEDOPT='s/.//;s/.*value=.//;s/\".*//' ;;
- quickhtml) SEDOPT='s/.//;s/.*value=.//;s/\".*//;s/\[url=/<a href=\"/;s/\]/\">/;s/\[img]/<img src=\"/;s/\[\/img]/\" \/>/;s/\[\/url]/<\/a>/' ;;
- *) SEDOPT='s/.//;s/.*\[url=//;s/\].*//;s/share.php/image.php/' ;;
- esac
- GREPOPT="${EMPGREPOPT}"
- fi
- # define maxdepth for find that makes LIST.
- # set to 0 unless a directory is given
- MAXDEPTH=0
- if [ -d "$1" ]
- then
- MAXDEPTH=1
- fi
- # we don't want ifs to fuck us with whitespaces
- OLDIFS=$IFS
- IFS=$'\n'
- # make list array of files to upload, get only files with max filesize and allowed filetypes
- LIST=($(find "$@" -maxdepth $MAXDEPTH -size -$MAXSIZE -type f | grep -i $ALLOWED_FILES))
- ListLen=${#LIST[@]}
- # reset ifs to old var
- IFS=$OLDIFS
- # locate curl and create tempfile
- CURL=$(which curl)
- TMPFILE=$(mktemp /tmp/up2pcn.XXXXXXXXXX) || exit 1
- EMPFILE=$(mktemp /tmp/up2pcn.XXXXXXXXXX) || exit 1
- Loops=$[$ListLen/$MAXFILES]
- if [ $[$ListLen%$MAXFILES] != 0 ]
- then
- Loops=$[$Loops+1]
- fi
- # let's upload some files!
- if [ $QUIET = "-#" ]
- then
- echo "Uploading $ListLen file(s) in $Loops cycle(s)..."
- fi
- Counter=0
- FString=""
- for file in "${LIST[@]}"
- do
- if [ $Counter -eq $MAXFILES ]
- then
- `eval $CURL -4 ${QUIET} -H "Expect:" ${FString} ${SUBMIT} ${PICHOST} >> ${TMPFILE}`
- Counter=0
- FString=""
- sleep 1 # give the server a second to relax ;)
- if [ "${PICHOST}" = "${EMPPICHOST}" ]; then
- echo >> ${TMPFILE}
- fi
- fi
- Counter=$[$Counter+1]
- if [ "${PICHOST}" = "${DEFAULTPICHOST}" ]; then
- FString=$FString"-F image_file$Counter=\"@$file\" "
- elif [ "${PICHOST}" = "${DUMPPIXPICHOST}" ]; then
- FString=$FString"-F userfile[$Counter]=\"@$file\" "
- elif [ "${PICHOST}" = "${EMPPICHOST}" ]; then
- FString=$FString"-F f_$Counter=\"@$file\" "
- fi
- done
- # upload the files that haven't been uploaded already
- if [ "$FString" != "" ]
- then
- `eval $CURL -4 ${QUIET} -H "Expect:" ${FString} ${SUBMIT} ${PICHOST} >> ${TMPFILE}`
- if [ "${PICHOST}" = "${EMPPICHOST}" ]; then
- echo >> ${TMPFILE}
- fi
- fi
- # let's create some nice output!
- if [ $QUIET = "-#" ]
- then
- echo "Done! Cheggit!"
- fi
- if [ "${PICHOST}" = "${EMPPICHOST}" ]; then
- cat $TMPFILE | sed -e 's/.*URL=//' -e 's/.>//' | while read i; do curl -s "$i" ; done > ${EMPFILE}
- mv ${EMPFILE} ${TMPFILE}
- fi
- cat $TMPFILE | grep -o "$GREPOPT" | sed "$SEDOPT"
- rm -rf $TMPFILE
- exit $?
advertising
Update the Post
Either update this post and resubmit it with changes, or make a new post.
You may also comment on this post.
Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.