wgif 0.0.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +15 -4
- data/lib/wgif.rb +1 -0
- data/lib/wgif/cli.rb +16 -0
- data/lib/wgif/exceptions.rb +3 -0
- data/lib/wgif/uploader.rb +38 -0
- data/lib/wgif/version.rb +1 -1
- data/spec/wgif/cli_spec.rb +16 -0
- data/spec/wgif/uploader_spec.rb +44 -0
- data/wgif.gemspec +1 -2
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c2b920dfa55567f79e781514cdbec115e06c044
|
4
|
+
data.tar.gz: 9e8dea99fdfd3f316538be45f6f5508e77470aed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2eeab9f6ee176bf8b412f72a722dfd9dcc8156107f760591602465a63bbee4f86dc8ae0ad7ba3d7c9c1ddbd0d282b763015eb5ba060ed61d8116be542811b9a5
|
7
|
+
data.tar.gz: e5c3125c238f0b92b25531371287170b87084ee7e80392521c32134f4c4e8082f03fd6a9bcee811f6bae6115b423310be3fd46fce64aacca6975d3b52310634a
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# WGif
|
2
|
-
](https://travis-ci.org/ecmendenhall/wgif)
|
3
3
|
|
4
4
|
WGif is a command line tool for creating animated GIFs from YouTube videos.
|
5
5
|
|
@@ -10,11 +10,12 @@ Usage: wgif [YouTube URL] [output file] [options]
|
|
10
10
|
-f, --frames N Number of frames in the final gif. (Default 20)
|
11
11
|
-s, --start HH:MM:SS Start creating gif from input video at this timestamp. (Default 00:00:00)
|
12
12
|
-d, --duration seconds Number of seconds of input video to capture. (Default 1)
|
13
|
+
-u, --upload Upload finished GIF to Imgur
|
13
14
|
-w, --width pixels Width of the gif in pixels. (Default 480px)
|
14
15
|
|
15
16
|
Example:
|
16
17
|
|
17
|
-
$ wgif https://www.youtube.com/watch?v=1A78yTvIY1k bjork.gif -s 00:03:30 -d 2 -w 400
|
18
|
+
$ wgif https://www.youtube.com/watch?v=1A78yTvIY1k bjork.gif -s 00:03:30 -d 2 -w 400 --upload
|
18
19
|
```
|
19
20
|
|
20
21
|
## Installation (Mac OS X)
|
@@ -33,7 +34,7 @@ $ gem build wgif.gemspec
|
|
33
34
|
and
|
34
35
|
|
35
36
|
```sh
|
36
|
-
$ gem install wgif-0.0.
|
37
|
+
$ gem install wgif-0.2.0.gem
|
37
38
|
```
|
38
39
|
|
39
40
|
to install the executable.
|
@@ -78,11 +79,21 @@ with the `-w` or `--width` flag:
|
|
78
79
|
$ wgif https://www.youtube.com/watch?v=1A78yTvIY1k bjork.gif --start 00:03:30 -d 2 -f 18 --width 350
|
79
80
|
```
|
80
81
|
|
82
|
+
And finally, now that everything's completed add the `--upload` flag to automatically post it to Imgur:
|
83
|
+
|
84
|
+
```sh
|
85
|
+
$ wgif https://www.youtube.com/watch?v=1A78yTvIY1k bjork.gif --start 00:03:30 -d 2 -f 18 --width 350 --upload
|
86
|
+
Finished. GIF uploaded to Imgur at http://i.imgur.com/iA28DuR.gif
|
87
|
+
```
|
88
|
+
|
81
89
|
And here it is:
|
82
90
|
|
83
|
-

|
84
92
|
### "You shouldn't let poets lie to you."
|
85
93
|
|
94
|
+
## Changes
|
95
|
+
- v0.2.0, 2014/4/11: Add automatic upload to Imgur with `--upload` flag.
|
96
|
+
|
86
97
|
## Contributions
|
87
98
|
Are welcome via pull request.
|
88
99
|
|
data/lib/wgif.rb
CHANGED
data/lib/wgif/cli.rb
CHANGED
@@ -35,6 +35,11 @@ module WGif
|
|
35
35
|
'Width of the gif in pixels. (Default 500px)') {
|
36
36
|
|gs| @options[:dimensions] = gs
|
37
37
|
}
|
38
|
+
opts.on('-u',
|
39
|
+
'--upload',
|
40
|
+
'Upload finished GIF to Imgur') {
|
41
|
+
|u| @options[:upload] = !!u
|
42
|
+
}
|
38
43
|
|
39
44
|
opts.on_tail('-h',
|
40
45
|
'--help',
|
@@ -65,6 +70,7 @@ module WGif
|
|
65
70
|
WGif::Installer.new.run if cli_args[0] == 'install'
|
66
71
|
require 'wgif/downloader'
|
67
72
|
require 'wgif/gif_maker'
|
73
|
+
require 'wgif/uploader'
|
68
74
|
rescue_errors do
|
69
75
|
args = parse_args cli_args
|
70
76
|
validate_args(args)
|
@@ -72,6 +78,10 @@ module WGif
|
|
72
78
|
clip = video.trim(args[:trim_from], args[:duration])
|
73
79
|
frames = clip.to_frames(frames: args[:frames])
|
74
80
|
GifMaker.new.make_gif(frames, args[:output], args[:dimensions])
|
81
|
+
if args[:upload]
|
82
|
+
url = Uploader.new('d2321b02db7ba15').upload(args[:output])
|
83
|
+
puts "Finished. GIF uploaded to Imgur at #{url}"
|
84
|
+
end
|
75
85
|
end
|
76
86
|
end
|
77
87
|
|
@@ -90,6 +100,12 @@ module WGif
|
|
90
100
|
print_error "WGif can't find a valid YouTube video at that URL."
|
91
101
|
rescue WGif::ClipEncodingException
|
92
102
|
print_error "WGif encountered an error transcoding the video."
|
103
|
+
rescue WGif::ImgurException => e
|
104
|
+
print_error <<-error
|
105
|
+
WGif couldn't upload your GIF to Imgur. The Imgur error was:
|
106
|
+
|
107
|
+
#{e}
|
108
|
+
error
|
93
109
|
rescue SystemExit => e
|
94
110
|
raise e
|
95
111
|
rescue Exception => e
|
data/lib/wgif/exceptions.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'typhoeus'
|
3
|
+
require 'wgif/exceptions'
|
4
|
+
|
5
|
+
module WGif
|
6
|
+
class Uploader
|
7
|
+
|
8
|
+
UPLOAD_ENDPOINT = 'https://api.imgur.com/3/image'
|
9
|
+
|
10
|
+
def initialize(client_id)
|
11
|
+
@client_id = client_id
|
12
|
+
end
|
13
|
+
|
14
|
+
def upload(filename)
|
15
|
+
File.open(filename, 'r') do |file|
|
16
|
+
response = Typhoeus.post(UPLOAD_ENDPOINT,
|
17
|
+
body: {image: file},
|
18
|
+
headers: auth_header)
|
19
|
+
raise WGif::ImgurException, error_message(response) unless response.success?
|
20
|
+
image_url(response)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def image_url(response)
|
27
|
+
JSON.parse(response.body)['data']['link']
|
28
|
+
end
|
29
|
+
|
30
|
+
def error_message(response)
|
31
|
+
JSON.parse(response.body)['data']['error']
|
32
|
+
end
|
33
|
+
|
34
|
+
def auth_header
|
35
|
+
{Authorization: "Client-ID #{@client_id}"}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/wgif/version.rb
CHANGED
data/spec/wgif/cli_spec.rb
CHANGED
@@ -59,6 +59,16 @@ describe WGif::CLI do
|
|
59
59
|
expect(options[:dimensions]).to eq("300")
|
60
60
|
end
|
61
61
|
|
62
|
+
it 'parses the short upload option' do
|
63
|
+
options = cli.parse_options ["-u"]
|
64
|
+
expect(options[:upload]).to eq(true)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'parses the long upload option' do
|
68
|
+
options = cli.parse_options ["--upload"]
|
69
|
+
expect(options[:upload]).to eq(true)
|
70
|
+
end
|
71
|
+
|
62
72
|
it 'handles args in wacky order' do
|
63
73
|
args = cli.parse_args([
|
64
74
|
"-d",
|
@@ -164,6 +174,12 @@ describe WGif::CLI do
|
|
164
174
|
expect_help_with_message(@mock_stdout.string, "WGif encountered an error transcoding the video.")
|
165
175
|
end
|
166
176
|
|
177
|
+
it 'catches upload errors' do
|
178
|
+
OptionParser.any_instance.stub(:parse!).and_raise(WGif::ImgurException, "Imgur error")
|
179
|
+
expect{ cli.make_gif([]) }.to raise_error(SystemExit)
|
180
|
+
expect_help_with_message(@mock_stdout.string, "Imgur error")
|
181
|
+
end
|
182
|
+
|
167
183
|
it 'raises SystemExit when thrown' do
|
168
184
|
OptionParser.any_instance.stub(:parse!).and_raise(SystemExit)
|
169
185
|
expect{ cli.make_gif([]) }.to raise_error(SystemExit)
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'typhoeus'
|
4
|
+
require 'wgif/uploader'
|
5
|
+
|
6
|
+
describe WGif::Uploader do
|
7
|
+
let(:api_key) { 'api-key' }
|
8
|
+
let(:uploader) { WGif::Uploader.new(api_key) }
|
9
|
+
let(:success) { Typhoeus::Response.new(
|
10
|
+
response_code: 200,
|
11
|
+
return_code: :ok,
|
12
|
+
body: {data: {link: 'foo'}}.to_json)
|
13
|
+
}
|
14
|
+
|
15
|
+
let(:failure) { Typhoeus::Response.new(
|
16
|
+
response_code: 400,
|
17
|
+
return_code: :error,
|
18
|
+
body: {data: {error: 'You should be ashamed of yourself.'}}.to_json )
|
19
|
+
}
|
20
|
+
let(:tempfile) { Tempfile.new('whatever') }
|
21
|
+
let(:request_params) { {body: {image: tempfile},
|
22
|
+
headers: {Authorization: "Client-ID #{api_key}"}} }
|
23
|
+
|
24
|
+
it 'sends an authorized POST request to Imgur with image file data' do
|
25
|
+
File.stub(:open).and_yield(tempfile)
|
26
|
+
expect(Typhoeus).to receive(:post).
|
27
|
+
with('https://api.imgur.com/3/image', request_params).and_return(success)
|
28
|
+
uploader.upload(tempfile.path)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'raises an exception if request is not successful' do
|
32
|
+
Typhoeus.stub(/http/).and_return(failure)
|
33
|
+
expect{ uploader.upload(tempfile.path) }.
|
34
|
+
to raise_error(WGif::ImgurException, 'You should be ashamed of yourself.')
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'returns the url when successful' do
|
38
|
+
File.stub(:open).and_yield(tempfile)
|
39
|
+
expect(Typhoeus).to receive(:post).
|
40
|
+
with('https://api.imgur.com/3/image', request_params).and_return(success)
|
41
|
+
expect(uploader.upload(tempfile.path)).to eq("foo")
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/wgif.gemspec
CHANGED
@@ -13,9 +13,8 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = "https://github.com/ecmendenhall/wgif"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
-
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.files = `git ls-files`.split($/) << 'lib/wgif/uploader.rb'
|
17
17
|
spec.executables = ["wgif"]
|
18
|
-
#spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
19
|
spec.require_paths = ["lib"]
|
21
20
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wgif
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Connor Mendenhall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rmagick
|
@@ -174,6 +174,7 @@ files:
|
|
174
174
|
- lib/wgif/exceptions.rb
|
175
175
|
- lib/wgif/gif_maker.rb
|
176
176
|
- lib/wgif/installer.rb
|
177
|
+
- lib/wgif/uploader.rb
|
177
178
|
- lib/wgif/version.rb
|
178
179
|
- lib/wgif/video.rb
|
179
180
|
- lib/wgif/video_cache.rb
|
@@ -183,6 +184,7 @@ files:
|
|
183
184
|
- spec/wgif/downloader_spec.rb
|
184
185
|
- spec/wgif/gif_maker_spec.rb
|
185
186
|
- spec/wgif/installer_spec.rb
|
187
|
+
- spec/wgif/uploader_spec.rb
|
186
188
|
- spec/wgif/video_cache_spec.rb
|
187
189
|
- spec/wgif/video_spec.rb
|
188
190
|
- wgif.gemspec
|
@@ -218,5 +220,6 @@ test_files:
|
|
218
220
|
- spec/wgif/downloader_spec.rb
|
219
221
|
- spec/wgif/gif_maker_spec.rb
|
220
222
|
- spec/wgif/installer_spec.rb
|
223
|
+
- spec/wgif/uploader_spec.rb
|
221
224
|
- spec/wgif/video_cache_spec.rb
|
222
225
|
- spec/wgif/video_spec.rb
|