Last active
January 3, 2016 13:19
-
-
Save nna774/8468487 to your computer and use it in GitHub Desktop.
https://aur.archlinux.org/packages/gyazo/ (http://yaa.no-ip.org/~yaa/ddata/gyazo) がfirefox 決め打ちだったからgoogle-chrome を使うようにしたもの どうせなら設定ファイル使うようにしたほうがいいんだろうけどめんどう。。。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# setting | |
browser_cmd = 'google-chrome-stable' | |
clipboard_cmd = 'xclip' | |
require 'net/http' | |
# get id | |
idfile = ENV['HOME'] + "/.gyazo.id" | |
id = '' | |
if File.exist?(idfile) then | |
id = File.read(idfile).chomp | |
end | |
# capture png file | |
tmpfile = "/tmp/image_upload#{$$}.png" | |
imagefile = ARGV[0] | |
if imagefile && File.exist?(imagefile) then | |
system "convert '#{imagefile}' '#{tmpfile}'" | |
else | |
system "import '#{tmpfile}'" | |
end | |
if !File.exist?(tmpfile) then | |
exit | |
end | |
imagedata = File.read(tmpfile) | |
File.delete(tmpfile) | |
# upload | |
boundary = '----BOUNDARYBOUNDARY----' | |
HOST = 'gyazo.com' | |
CGI = '/upload.cgi' | |
UA = 'Gyazo/1.0' | |
data = <<EOF | |
--#{boundary}\r | |
content-disposition: form-data; name="id"\r | |
\r | |
#{id}\r | |
--#{boundary}\r | |
content-disposition: form-data; name="imagedata"; filename="gyazo.com"\r | |
\r | |
#{imagedata}\r | |
--#{boundary}--\r | |
EOF | |
header ={ | |
'Content-Length' => data.length.to_s, | |
'Content-type' => "multipart/form-data; boundary=#{boundary}", | |
'User-Agent' => UA | |
} | |
env = ENV['http_proxy'] | |
if env then | |
uri = URI(env) | |
proxy_host, proxy_port = uri.host, uri.port | |
else | |
proxy_host, proxy_port = nil, nil | |
end | |
Net::HTTP::Proxy(proxy_host, proxy_port).start(HOST,80) {|http| | |
res = http.post(CGI,data,header) | |
url = res.response.body | |
puts url | |
if system "which #{clipboard_cmd} >/dev/null 2>&1" then | |
system "echo -n '#{url}' | #{clipboard_cmd}" | |
end | |
system "#{browser_cmd} '#{url}'" | |
# save id | |
newid = res.response['X-Gyazo-Id'] | |
if newid and newid != "" then | |
if !File.exist?(File.dirname(idfile)) then | |
Dir.mkdir(File.dirname(idfile)) | |
end | |
if File.exist?(idfile) then | |
File.rename(idfile, idfile+Time.new.strftime("_%Y%m%d%H%M%S.bak")) | |
end | |
File.open(idfile,"w").print(newid) | |
end | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gyazo/ 0000754 0001750 0001750 00000000000 12266127223 010661 5 ustar nona nona gyazo/PKGBUILD 0000644 0001750 0001750 00000001207 12266132007 012002 0 ustar nona nona # Contributor: Andrij Kondratiev [email protected], NoNameA 774 [email protected] | |
pkgname=gyazo | |
pkgver=1 | |
pkgrel=2 | |
pkgdesc="Launch the Gyazo app and drag your mouse to grab the screen. " | |
arch=('any') | |
url="http://gyazo.com/" | |
license=('GPL') | |
groups=(multimedia) | |
depends=('ruby' 'xclip' 'imagemagick') | |
makedepends=() | |
optdepends=() | |
provides=() | |
conflicts=() | |
replaces=() | |
backup=() | |
options=() | |
install= | |
source=(https://gist.github.com/nna774/8468487/raw/37fa9be99400e626adebfe0853c9f5923952e1d2/gyazo) | |
noextract=() | |
md5sums=('a8312fecbb569d7b5b955b9e4b801c50') | |
package() { | |
mkdir -p $pkgdir/usr/bin/ | |
install -m 0777 "$srcdir/gyazo" "$pkgdir/usr/bin/" | |
} | |