Skip to content

Instantly share code, notes, and snippets.

@oglops
Last active February 27, 2017 16:56
Show Gist options
  • Select an option

  • Save oglops/700373fecf5ffca67f59dfd90f4b9499 to your computer and use it in GitHub Desktop.

Select an option

Save oglops/700373fecf5ffca67f59dfd90f4b9499 to your computer and use it in GitHub Desktop.
Upload images to imgur vai api xml v3 "anonymously" with album, with kde dolphin action servicemenus

用于imgur上传图片的dolphin servicemenu菜单

  • 可以选择一个或多个文件
  • Actions->Upload to Imgur,上传成功之后自动在浏览器中打开direct link
  • Actions->Upload to Imgur - Detail Page,上传成功之后自动在浏览器中打开带post options的link
  • Actions->Upload to Imgur - Album,上传成功之后自动在浏览器中打开album
  • InitialPreference决定这三个菜单的出现顺序
  • 如果选择了多个文件,前两个菜单是每个图片上传成功后,逐个打开图片链接
  • 使用的clientid 3e7a4deb7ac67da来自大神Ceryn官方链接,觉得不适的话可以自己注册个帐号用自己的
  • 全部都是以"匿名"方式上传(当然用的还是别人的clientid,不要上传不和谐的东西喔,会分分钟被请喝茶的),如果想管理上传的图片,需要略微修改一下,加上你的账户信息

效果图

screenshot

[Desktop Entry]
Type=Service
ServiceTypes=KonqPopupMenu/Plugin
MimeType=image/*;
Actions=DoAction
InitialPreference=8
[Desktop Action DoAction]
Name=Upload to Imgur - Album
Icon=utilities-terminal
Exec=/home/oglop/github/scripts/upload-imgur-album.sh %U;
[Desktop Entry]
Type=Service
ServiceTypes=KonqPopupMenu/Plugin
MimeType=image/*;
Actions=DoAction
InitialPreference=9
[Desktop Action DoAction]
Name=Upload to Imgur - Detail Page
Icon=utilities-terminal
Exec=/home/oglop/github/scripts/upload-imgur-detail.sh %U;
[Desktop Entry]
Type=Service
ServiceTypes=KonqPopupMenu/Plugin
MimeType=image/*;
Actions=DoAction
InitialPreference=10
[Desktop Action DoAction]
Name=Upload to Imgur
Icon=utilities-terminal
Exec=/home/oglop/github/scripts/upload-imgur.sh %U;
#!/bin/env bash
clientid="3e7a4deb7ac67da"
# create album
album_response="$(curl -sH "Authorization: Client-ID $clientid" -F "title=" https://api.imgur.com/3/album)"
id="$(echo $album_response| pcregrep -o '(?<="id":")[^\"]*')"
deletehash="$(echo $album_response| pcregrep -o '(?<="deletehash":")[^\"]*')"
album_link="http://imgur.com/a/$id"
echo album id: $id
echo album deletehash: $deletehash
echo album link: $album_link
# upload images to album
for i in "$@";do
image_response="$(curl -# -s -F "image"=@"$i" -H "Authorization: Client-ID $clientid" -F album=$deletehash -F title="$(basename "$i")" https://api.imgur.com/3/upload.xml)"
printf "\n============ $i ============\n"
echo link: "$(pcregrep -o '(?<=link>)[^<]*' <<< ${image_response})"
echo deletehash: "$(pcregrep -o '(?<=deletehash>)[^<]*' <<< ${image_response})"
done
# open album in browser
xdg-open $album_link
#!/bin/env bash
imgur(){
for i in "$@";do
curl -# -F "image"=@"$i" -F title="$(basename "$i")" -H "Authorization: Client-ID 3e7a4deb7ac67da" https://api.imgur.com/3/upload.xml|\
pcregrep -o '(?<=link>)[^<]*' | sed 's/^.*imgur\.com\//http:\/\/imgur.com\//g;s/\.[^.]*$//' | xargs xdg-open
done
}
imgur "$@"
#!/bin/env bash
imgur(){
for i in "$@";do
curl -# -F "image"=@"$i" -F title="$(basename "$i")" -H "Authorization: Client-ID 3e7a4deb7ac67da" https://api.imgur.com/3/upload.xml|\
pcregrep -o '(?<=link>)[^<]*' | xargs xdg-open
done
}
imgur "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment