Git Product home page Git Product logo

imgurbash2's People

Contributors

cjbassi avatar ram-on avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

imgurbash2's Issues

Basic UI with e.g. zenity

Hey there,

Nice script!

Would you be interested in adding some basic GUI functionality? I had this implemented in my (never released) imgur upload bash script. Just some optional dialogs and a progress bar using zenity.

Cheers! :)

For reference, my script:

#!/bin/bash
## Upload an image to imgur - now with progress bar!
## upimgur v0.5 by haarp
## licensed under GPLv3 or newer
##
## Dependencies: curl (mandatory), ≥zenity-3.6.0 (if GUI is desired)
## Optional: xclip (for clipboard interaction)
##
## TODO: multiple files

AUTH="*purged*"

export DESKTOP_SESSION=xfce	# cause xdg-open is dumb (why the flying fuck is it using Links to open http?!)

print() {	# $1: text, $2: 'info' or 'question'
		# in question mode, returns 0 if 'yes', 1 if 'no' and 127 if no GUI
	if [[ $gui == "1" ]]; then
		mode=${2-info}

		zenity --title="${0##*/}" --$mode --no-markup --no-wrap --text="$1" --icon-name=clipman
		return $?
	else
		echo -e "$1"
		return 127
	fi
}
filechecks() {
	# https://help.imgur.com/hc/en-us/articles/115000083326-What-files-can-I-upload-What-is-the-size-limit-
	if <<< "$1" grep -qiE '\.(jpe?g|png|tiff)$'; then
		local max_size=20000000
	elif <<< "$1" grep -qiE '\.(gif|apng|mp4|mpeg|avi|webm)$'; then
		local max_size=200000000
	else
		print "File '$1' not a supported image format, aborting!"
		exit 1
	fi
	[[ $(stat -c%s "$1") -ge $max_size ]] && {
		print "File '$1' invalid (max. $(($max_size/1000/1000))MB), aborting!"
		exit 1
	}
}

command -v curl >/dev/null || {
	print "curl not found, aborting!"; exit 9
}
gui=1	# can't check TERM - Thunar uses `linux`, `dumb`, whatever it wants!
command -v zenity >/dev/null || gui=0

if [[ $1 == "" || $1 == "-h" || $1 == "--help" ]]; then
	print "Usage: ${0##*/} filename
	Upload an image to imgur and show the link
	If xclip is available, the URL is copied into the X clipboard."
	exit 0
else
	file="$1"
	filechecks "$file"
fi

# "Expect: " header works around a problem with the Squid proxy
if [[ $gui == "1" ]]; then
	rfile=$(mktemp --suffix=.curl)
	trap 'rm "$rfile" &>/dev/null' EXIT

	curl -# -F "image=@$file" -H "Authorization: Client-ID $AUTH" -H "Expect: " https://api.imgur.com/3/upload.xml -o "$rfile" 2>&1 | \
		stdbuf -o0 tr '\r' '\n' | \
		stdbuf -o0 grep -o "[0-9]*\.[0-9]" | \
		zenity --progress --title="${0##*/}" --text="Uploading..." --auto-close --auto-kill

	response=$(< "$rfile")
else
	response=$(curl -# -F "image=@$file" -H "Authorization: Client-ID $AUTH" -H "Expect: " https://api.imgur.com/3/upload.xml)
fi
rm "$rfile" &>/dev/null
link=$(<<< $response grep -o '<link>.*</link>' | sed -e 's:</*link>::g')
deletehash=$(<<< $response grep -o '<deletehash>.*</deletehash>' | sed -e 's:</*deletehash>::g')

[[ $link ]] || {
	print "Upload failed!
	$response"
	exit 2
}

clipmessage=""; question=""
[[ $DISPLAY ]] && command -v xclip &>/dev/null && \
	echo -n "$link" | xclip -selection clipboard && clipmessage="(copied into clipboard)"
[[ $gui == "1" ]] && prompt="open image URL now?"

print "$link
$clipmessage
deletehash: $deletehash

$prompt" question && xdg-open "$link"

Private album upload

Thanks for making this script! Very handy.

I'm coming from Windows, where I've been using ShareX. It allows you to give it an Imgur access token and upload all images to a private album of your choice. I like that because then I can nuke my system and still have all uploads in one place, and have an ability to delete any one of them, at any point in the future, and I'm super used to that now.

Imgur's auth is fairly simple, AFAIK. Just gotta point your user to a certain URL, with your client_id, and then the user is presented with a token which they can copy and save somewhere. Choosing an album is simple too, just picking an id out of a list.

I'm thinking an API like this could work:

imgurbash2 --login # sends you to the browser and waits for token input, saves it
imgurbash2 --list-albums # lists all private albums and their ids
imgurbash2 foo.png # the usual behavior, an anonymous upload
imgurbash2 --with-auth foo.png # same upload, but with the auth headers
imgurbash2 --with-auth --album bar foo.png # upload to a private album "bar"

If you don't like the statefulness of storing the token somewhere, I suppose the responsibility of storing it could be shifted to the user, and you'd just take a file path as an argument.

Would you be interested in adding such functionality? Or should I go for a PR, if I want this soon?

default config + missing notifications

Hi again,
I have some comments re. f7e81fd

  1. getting rid of default config definitions, and replacing them by manual config file initialisation (@ # if the configuration file does not exist, then initialize it) is a horrible idea; users who already have a config file but are missing certain elements (say COPY_URL_TO_CLIP) would now be tracking unexpected defaults: COPY_URL_TO_CLIP == true and similar checks would fail for them;
  2. I don't agree with the reasoning for removing notifications:

Removed popup notifications as they do not make any sense to have in
the first place

Imho feedback is good; otherwise how do we know:
a) whether command failed or succeeded
b) has the command returned or is it still running?

Any chance you'd consider reverting these 2 features?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.