updated on Sun Jan 15 20:01:04 UTC 2012
[aur-mirror.git] / tpu / tpu
blobee51946b40b9cdd7c4e012df2e4e44b3c58d60b7
1 #!/bin/bash
3 ########################################################
4 # TinyPicUploader (tpu) 0.2 #
5 # Author: Arm the Homeless <ratm@archlinux.us> #
6 # Description: Uploads to TinyPic. Read name. =P #
7 # Syntax: tpu [FILE] #
8 ########################################################
10 if [ $# -eq 0 ]; then
11 echo "TinyPicUploader
12 Usage: tpu file [file, ...]
14 Uploads files to TinyPic and prints the result urls.
15 If directories are given they will be recursed for images.
17 exit 1
20 function upload {
21 if [ -d $1 ]; then
22 echo "-- $1 --"
23 for each in $(ls -d $1/*); do upload $each; done
24 elif [ -f $1 ] && [ -r $1 ] && [ $(file -L -b --mime-type $1 | grep 'image') ]; then
25 timestamp=$(date +'%s%N')
26 workfile="/tmp/tinypic.$timestamp"
27 curl -L -s -F "the_file=@$1" -F file_type=image -F action=upload "http://s4.tinypic.com/upload.php" -H "Expect:" -o $workfile
28 uploaded=$(grep 'name="pic"' $workfile | sed 's/.*value="\([^"]*\).*/\1/')
29 if [ $uploaded ]; then
30 ival=$(grep 'name="ival"' $workfile | sed 's/.*value="\([^"]*\).*/\1/')
31 echo "http://i$ival.tinypic.com/$uploaded.jpg"
32 else echo "$1 failed"
34 rm $workfile
38 (for arg in $*; do upload $arg; done; echo "-- done --")|zenity --title="TinyPicUploader" --text-info