Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

As of today it stopped working #5

Open
lgbaldoni opened this issue Apr 3, 2016 · 10 comments
Open

As of today it stopped working #5

lgbaldoni opened this issue Apr 3, 2016 · 10 comments

Comments

@lgbaldoni
Copy link

new API perhaps?

@ruthtern
Copy link

luigino, yes
imgur is obsoleting the old API versions

Try changing 2 lines ...
apikey="ea6c0ef2987808e"
curl -H "Authorization: Client-ID $apikey" -F "image=@$file" \
https://api.imgur.com/3/upload.xml

@lgbaldoni
Copy link
Author

I must be doing something wrong, because this is what I see as output:

<?xml version="1.0" encoding="utf-8"?> <data type="array" success="0" status="400"><error>No image data was sent to the upload api</error><request>/3/upload.xml</request><method>POST</method></data> Delete page: <?xml version="1.0" encoding="utf-8"?> <data type="array" success="0" status="400"><error>No image data was sent to the upload api</error><request>/3/upload.xml</request><method>POST</method></data>

I'm modifying lines #29 and #78: is that correct?

@kusayuzayushko
Copy link

# parse the response and output our stuff
    url=$(echo $response | sed -r 's/.*<link>(.*)<\/link>.*/\1/')
    deleteurl=$(echo $response | sed -r 's/.*<link>(.*)<\/link>.*/\1/')

@lgbaldoni
Copy link
Author

parse the response and output our stuff

url=$(echo $response | sed -r 's/.*<link>(.*)<\/link>.*/\1/')
deleteurl=$(echo $response | sed -r 's/.*<link>(.*)<\/link>.*/\1/')

Same deal.

@setaur
Copy link

setaur commented May 17, 2016

I managed to push kusayuzayushko and ruthtern suggestions into working script:

#!/bin/bash

# imgur script by Bart Nagel <[email protected]>
# version 4.1
# I release this into the public domain. Do with it what you will.

# Required: curl
#
# Optional: xsel or xclip for automatically putting the URLs on the X selection 
# for easy pasting
#
# Instructions:
# Put it somewhere in your path and maybe rename it:
#   mv ~/Downloads/imgurbash.sh ~/bin/imgur
# Make it executable:
#   chmod +x ~/bin/imgur
# Optional, since Alan kindly provided an API key for this script: stick your 
# API key in the top:
#   vim ~/bin/imgur
# Upload an image:
#   imgur images/hilarious/manfallingover.jpg
# Upload multiple images:
#   imgur images/delicious/cake.png images/exciting/bungeejump.jpg
# The URLs will be displayed (and the delete page's URLs will be displayed on 
# stderr). If you have xsel or xclip the URLs will also be put on the X 
# selection, which you can usually paste with a middle click.

# API Key provided by [email protected]
apikey="ea6c0ef2987808e"

# function to output usage instructions
function usage {
    echo "Usage: $(basename $0) <filename> [<filename> [...]]" >&2
    echo "Upload images to imgur and output their new URLs to stdout. Each one's" >&2
    echo "delete page is output to stderr between the view URLs." >&2
    echo "If xsel or xclip is available, the URLs are put on the X selection for" >&2
    echo "easy pasting." >&2
}

# check API key has been entered
if [ "$apikey" = "Your API key" ]; then
    echo "You first need to edit the script and put your API key in the variable near the top." >&2
    exit 15
fi

# check arguments
if [ "$1" = "-h" -o "$1" = "--help" ]; then
    usage
    exit 0
elif [ $# == 0 ]; then
    echo "No file specified" >&2
    usage
    exit 16
fi

# check curl is available
type curl >/dev/null 2>/dev/null || {
    echo "Couln't find curl, which is required." >&2
    exit 17
}

clip=""
errors=false

# loop through arguments
while [ $# -gt 0 ]; do
    file="$1"
    shift

    # check file exists
    if [ ! -f "$file" ]; then
        echo "file '$file' doesn't exist, skipping" >&2
        errors=true
        continue
    fi

    # upload the image
    response=$(curl -H "Authorization: Client-ID $apikey" -F "image=@$file" \
            https://api.imgur.com/3/upload.xml)
    # the "Expect: " header is to get around a problem when using this through 
    # the Squid proxy. Not sure if it's a Squid bug or what.
    if [ $? -ne 0 ]; then
        echo "Upload failed" >&2
        errors=true
        continue
    elif [ $(echo $response | grep -c "<error_msg>") -gt 0 ]; then
        echo "Error message from imgur:" >&2
        echo $response | sed -r 's/.*<error_msg>(.*)<\/error_msg>.*/\1/' >&2
        errors=true
        continue
    fi

    # parse the response and output our stuff
    url=$(echo $response | sed -r 's/.*<link>(.*)<\/link>.*/\1/')
 deleteurl="http://i.imgur.com/delete/$(echo $response |\
 sed -r 's/.*<deletehash>(.*)<\/deletehash>.*/\1/')"
    echo $url
    echo "Delete page: $deleteurl" >&2

    # append the URL to a string so we can put them all on the clipboard later
    clip="$clip$url
"
done

# put the URLs on the clipboard if we have xsel or xclip
if [ $DISPLAY ]; then
    { type xsel >/dev/null 2>/dev/null && echo -n $clip | xsel; } \
        || { type xclip >/dev/null 2>/dev/null && echo -n $clip | xclip; } \
        || echo "Haven't copied to the clipboard: no xsel or xclip" >&2
else
    echo "Haven't copied to the clipboard: no \$DISPLAY" >&2
fi

if $errors; then
    exit 1
fi

@lgbaldoni
Copy link
Author

Love you man, but the delete page comes out as the image link...

@setaur
Copy link

setaur commented May 17, 2016

Right. Instead of

deleteurl=$(echo $response | sed -r 's/.*<link>(.*)<\/link>.*/\1/')

should be

deleteurl="http://i.imgur.com/delete/$(echo $response |\
 sed -r 's/.*<deletehash>(.*)<\/deletehash>.*/\1/')"

Now it should work fine. I updated also my previous post.

@lgbaldoni
Copy link
Author

All ok, thank you very much!

@setaur
Copy link

setaur commented May 25, 2016

I think luigino that you should leave this ticket open, because imgurbash.sh from this repository is still not updated.

@lgbaldoni
Copy link
Author

I think luigino that you should leave this ticket open, because imgurbash.sh from this repository is still not updated.

Done, but I suspect this project has been abandoned.

@lgbaldoni lgbaldoni reopened this May 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants