Upload image on ImgUr (anonymous) with history using commandline

Upload image on ImgUr (anonymous) with history using commandline. It requires sed and curl. .

@echo off
REM Set you API KEY http://imgur.com/register/api_anon
set apikey=your_apikey_here

REM Usage:
REM img file_path [title] 
REM img url [title] 
REM title and caption are optional, quote them if they contains spaces or strange characters

REM Set the path where are located curl.exe and sed.exe
REM is you use Cygwin, install the curl's package (sed is included by default in standard installation) and uncomment this line http://imgur.com/CioIf
REM PATH=%PATH%;C:\cygwin\bin

REM Removing quotes from parameters to avoid problems with curl
set image=%~1
set prefix=%image:~0,4%
set title=%~2
set caption=%~3

set historyfile="%~dp0imgur_history.txt"

echo imgur uploader via CURL version 1.0 by @gialloporpora
if "%image%"=="" goto help
if /i %1==help goto help
if /i %1==-h goto help
if /i %1==view goto showhistory
if /i %1==-v goto showhistory

REM /i case insensitive match
if /i %prefix%==http goto urlupload
if not exist %1 goto filenotfound
curl -F "title=%title%" -F "caption=%caption%" -F "image=@%image%" -F "key=%apikey%" http://api.imgur.com/2/upload.xml > curl.html
goto success

echo File not found
goto end

curl -d "image=%image%" -d "title=%title%" -d "caption=%caption%" -d "key=%apikey%" http://api.imgur.com/2/upload.xml > curl.html

sed -n -e "//{s/.*\(.*\)\(.*\)\(.*\).*\(.*\).*/Original image:\t\1\nImage page:\t\2\nThumbnail:\t\4\nDeletion Page:\t\3\n/;p}" curl.html > temp.txt
type temp.txt
date /T >> %historyfile%
time /T >> %historyfile%
echo Title: %title% >> %historyfile%
echo Caption: %caption% >> %historyfile%
type temp.txt >> %historyfile%
del temp.txt
del curl.html
goto end

echo Usage:
echo img filename [title] 
echo img url [title] 
echo title and caption are optional, if you use spaces inside them remember to quote them
echo * Type `img help' to show this help
echo * Type `img view' to show all your uploaded images
goto end

type %historyfile%

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s