wgif 0.5.1 → 0.5.2
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 +2 -0
- data/bin/wgif +1 -1
- data/lib/wgif.rb +1 -0
- data/lib/wgif/argument_parser.rb +12 -16
- data/lib/wgif/info_displayer.rb +7 -7
- data/lib/wgif/validator.rb +22 -0
- data/lib/wgif/version.rb +1 -1
- data/lib/wgif/video.rb +1 -1
- data/spec/regression/frame_order_spec.rb +2 -2
- data/spec/unit/wgif/argument_parser_spec.rb +11 -64
- data/spec/unit/wgif/cli_spec.rb +9 -8
- data/spec/unit/wgif/download_bar_spec.rb +1 -1
- data/spec/unit/wgif/downloader_spec.rb +14 -14
- data/spec/unit/wgif/gif_maker_spec.rb +4 -4
- data/spec/unit/wgif/info_displayer_spec.rb +1 -1
- data/spec/unit/wgif/uploader_spec.rb +2 -2
- data/spec/unit/wgif/validator_spec.rb +35 -0
- data/spec/unit/wgif/video_spec.rb +11 -11
- 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: 1a6f0bf2c4be9fa392a29d9ce4288c56a364fdb9
|
4
|
+
data.tar.gz: 54fb5cf82fec17aaea7d81533109ea02c6c29c8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffbd2b1b20e9a716e82d1210baf8fed2abc58a554e0ad27ce653ae8d8a629ca461900b18c5910a1b4ab118778450a1ba68de0e50f426db1d088aa203ab6a91a8
|
7
|
+
data.tar.gz: e9868668f1d15ed8bc8c908bbc12f670f8d8b0395312d069dfa4f55a12f336241857e48d8a70b3c5f955e3b03d8c7a5d2b688d7ea52383498be04b442e73a797
|
data/README.md
CHANGED
@@ -114,6 +114,8 @@ And here it is:
|
|
114
114
|
### "You shouldn't let poets lie to you."
|
115
115
|
|
116
116
|
## Changes
|
117
|
+
- v0.5.2, 2015/1/24: Use `/usr/bin/env ruby` in binary.
|
118
|
+
- v0.5.1, 2014/8/15: Lock down dependency versions.
|
117
119
|
- v0.5.0, 2014/8/15: Add support for sub-second timestamps in `--start` and `--duration` flags ([Issue #13](https://github.com/ecmendenhall/wgif/issues/13)).
|
118
120
|
- v0.4.0, 2014/5/30: Show file size with `--info` flag. (Thanks, [justalisteningman](https://github.com/justalisteningman)!)
|
119
121
|
- v0.3.1, 2014/5/10: Fixes frame order for gifs with more than 100 frames. ([Issue #14](https://github.com/ecmendenhall/wgif/issues/14))
|
data/bin/wgif
CHANGED
data/lib/wgif.rb
CHANGED
data/lib/wgif/argument_parser.rb
CHANGED
@@ -1,19 +1,17 @@
|
|
1
1
|
require 'optparse'
|
2
|
-
require 'wgif/
|
2
|
+
require 'wgif/validator'
|
3
3
|
|
4
4
|
module WGif
|
5
5
|
class ArgumentParser
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
DEFAULTS = {
|
8
|
+
trim_from: '00:00:00',
|
9
|
+
duration: 1.0,
|
10
|
+
dimensions: '480'
|
11
|
+
}
|
9
12
|
|
10
13
|
def initialize
|
11
14
|
@options = {}
|
12
|
-
@defaults = {
|
13
|
-
trim_from: '00:00:00',
|
14
|
-
duration: 1.0,
|
15
|
-
dimensions: '480'
|
16
|
-
}
|
17
15
|
@parser = OptionParser.new do |opts|
|
18
16
|
opts.on('-f N',
|
19
17
|
'--frames N',
|
@@ -61,16 +59,20 @@ module WGif
|
|
61
59
|
|
62
60
|
def parse(args)
|
63
61
|
options = parse_args(args)
|
64
|
-
|
62
|
+
validate(options)
|
65
63
|
options
|
66
64
|
end
|
67
65
|
|
66
|
+
def validate(args)
|
67
|
+
WGif::Validator.new(args).validate
|
68
|
+
end
|
69
|
+
|
68
70
|
def argument_summary
|
69
71
|
@parser.summarize
|
70
72
|
end
|
71
73
|
|
72
74
|
def parse_args(args)
|
73
|
-
options =
|
75
|
+
options = DEFAULTS.merge(parse_options args)
|
74
76
|
options.merge(url: args[0], output: args[1])
|
75
77
|
end
|
76
78
|
|
@@ -79,12 +81,6 @@ module WGif
|
|
79
81
|
@options
|
80
82
|
end
|
81
83
|
|
82
|
-
def validate_args(args)
|
83
|
-
fail WGif::InvalidUrlException unless args[:url] =~ URL
|
84
|
-
fail WGif::InvalidTimestampException unless args[:trim_from] =~ TIMESTAMP
|
85
|
-
fail WGif::MissingOutputFileException unless args[:output]
|
86
|
-
end
|
87
|
-
|
88
84
|
def print_help
|
89
85
|
puts 'Usage: wgif [YouTube URL] [output file] [options]', "\n"
|
90
86
|
puts argument_summary, "\n"
|
data/lib/wgif/info_displayer.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module WGif
|
2
2
|
class InfoDisplayer
|
3
3
|
|
4
|
-
GIGA_SIZE =
|
5
|
-
MEGA_SIZE =
|
4
|
+
GIGA_SIZE = 1_073_741_824.0
|
5
|
+
MEGA_SIZE = 1_048_576.0
|
6
6
|
KILO_SIZE = 1024.0
|
7
7
|
|
8
8
|
def display(file_name)
|
@@ -13,16 +13,16 @@ module WGif
|
|
13
13
|
def readable_file_size(size)
|
14
14
|
|
15
15
|
if size < KILO_SIZE
|
16
|
-
abb, div =
|
16
|
+
abb, div = 'Bytes', 1
|
17
17
|
elsif size < MEGA_SIZE
|
18
|
-
abb, div =
|
18
|
+
abb, div = 'KB', KILO_SIZE
|
19
19
|
elsif size < GIGA_SIZE
|
20
|
-
abb, div =
|
20
|
+
abb, div = 'MB', MEGA_SIZE
|
21
21
|
else
|
22
|
-
abb, div =
|
22
|
+
abb, div = 'GB', GIGA_SIZE
|
23
23
|
end
|
24
24
|
|
25
|
-
"%.3f #{abb}"
|
25
|
+
format "%.3f #{abb}", (size / div)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'wgif/exceptions'
|
2
|
+
|
3
|
+
module WGif
|
4
|
+
class Validator
|
5
|
+
URL = %r{\Ahttps?://.*\z}
|
6
|
+
TIMESTAMP = /\A\d{1,2}(?::\d{2})+(?:\.\d*)?\z/
|
7
|
+
|
8
|
+
def initialize(args)
|
9
|
+
@args = args
|
10
|
+
end
|
11
|
+
|
12
|
+
def validate
|
13
|
+
fail WGif::InvalidUrlException unless args[:url] =~ URL
|
14
|
+
fail WGif::InvalidTimestampException unless args[:trim_from] =~ TIMESTAMP
|
15
|
+
fail WGif::MissingOutputFileException unless args[:output]
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :args
|
21
|
+
end
|
22
|
+
end
|
data/lib/wgif/version.rb
CHANGED
data/lib/wgif/video.rb
CHANGED
@@ -17,7 +17,7 @@ module WGif
|
|
17
17
|
options = {
|
18
18
|
audio_codec: 'copy',
|
19
19
|
video_codec: 'copy',
|
20
|
-
custom: "-ss #{start_timestamp} -t 00:00:#{'%06.3f'
|
20
|
+
custom: "-ss #{start_timestamp} -t 00:00:#{format('%06.3f', duration)}"
|
21
21
|
}
|
22
22
|
transcode(@clip, "/tmp/wgif/#{@name}-clip.mov", options)
|
23
23
|
WGif::Video.new "#{@name}-clip", "/tmp/wgif/#{@name}-clip.mov"
|
@@ -13,7 +13,7 @@ describe 'frame order bug', regression: true do
|
|
13
13
|
'170']
|
14
14
|
WGif::CLI.new.make_gif(args)
|
15
15
|
frames = Dir.entries('/tmp/wgif/frames')
|
16
|
-
filenames = (1..170).map {|n| sprintf
|
17
|
-
expect(frames).to eq([
|
16
|
+
filenames = (1..170).map { |n| sprintf '%05d.png', n }
|
17
|
+
expect(frames).to eq(['.', '..'] + filenames)
|
18
18
|
end
|
19
19
|
end
|
@@ -4,49 +4,44 @@ require 'wgif/argument_parser'
|
|
4
4
|
describe WGif::ArgumentParser do
|
5
5
|
let(:parser) { described_class.new }
|
6
6
|
|
7
|
-
it 'parses a URL from command line args' do
|
8
|
-
args = parser.parse_args ['http://example.com']
|
9
|
-
args[:url].should eq('http://example.com')
|
10
|
-
end
|
11
|
-
|
12
7
|
it 'starts at 0s by default' do
|
13
8
|
args = parser.parse_args ['http://example.com']
|
14
|
-
args[:trim_from].
|
9
|
+
expect(args[:trim_from]).to eq('00:00:00')
|
15
10
|
end
|
16
11
|
|
17
|
-
it 'trims
|
12
|
+
it 'trims clips to 1s by default' do
|
18
13
|
args = parser.parse_args ['http://example.com']
|
19
|
-
args[:duration].
|
14
|
+
expect(args[:duration]).to eq(1)
|
20
15
|
end
|
21
16
|
|
22
17
|
it 'parses the short frame count option' do
|
23
18
|
options = parser.parse_options ['-f', '40']
|
24
|
-
options[:frames].
|
19
|
+
expect(options[:frames]).to eq(40)
|
25
20
|
end
|
26
21
|
|
27
22
|
it 'parses the long frame count option' do
|
28
23
|
options = parser.parse_options ['--frames', '40']
|
29
|
-
options[:frames].
|
24
|
+
expect(options[:frames]).to eq(40)
|
30
25
|
end
|
31
26
|
|
32
27
|
it 'parses the short start time option' do
|
33
28
|
options = parser.parse_options ['-s', '00:00:05']
|
34
|
-
options[:trim_from].
|
29
|
+
expect(options[:trim_from]).to eq('00:00:05')
|
35
30
|
end
|
36
31
|
|
37
32
|
it 'parses the long start time option' do
|
38
33
|
options = parser.parse_options ['--start', '00:00:05']
|
39
|
-
options[:trim_from].
|
34
|
+
expect(options[:trim_from]).to eq('00:00:05')
|
40
35
|
end
|
41
36
|
|
42
37
|
it 'parses the short duration option' do
|
43
38
|
options = parser.parse_options ['-d', '1.43']
|
44
|
-
options[:duration].
|
39
|
+
expect(options[:duration]).to eq(1.43)
|
45
40
|
end
|
46
41
|
|
47
42
|
it 'parses the long duration option' do
|
48
43
|
options = parser.parse_options ['--duration', '5.3']
|
49
|
-
options[:duration].
|
44
|
+
expect(options[:duration]).to eq(5.3)
|
50
45
|
end
|
51
46
|
|
52
47
|
it 'parses the short dimensions option' do
|
@@ -83,7 +78,7 @@ describe WGif::ArgumentParser do
|
|
83
78
|
options = parser.parse_options ['-i']
|
84
79
|
expect(options[:info]).to eq(true)
|
85
80
|
end
|
86
|
-
|
81
|
+
|
87
82
|
it 'parses the long output option' do
|
88
83
|
options = parser.parse_options ['--info']
|
89
84
|
expect(options[:info]).to eq(true)
|
@@ -112,52 +107,4 @@ describe WGif::ArgumentParser do
|
|
112
107
|
upload: true,
|
113
108
|
preview: true)
|
114
109
|
end
|
115
|
-
|
116
|
-
context 'validating args' do
|
117
|
-
|
118
|
-
it 'checks for a missing output file' do
|
119
|
-
args = parser.parse_args(['http://example.com'])
|
120
|
-
expect { parser.validate_args args }
|
121
|
-
.to raise_error(WGif::MissingOutputFileException)
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'checks for an invalid URL' do
|
125
|
-
args = parser.parse_args(['crazy nonsense', 'output.gif'])
|
126
|
-
expect { parser.validate_args args }
|
127
|
-
.to raise_error(WGif::InvalidUrlException)
|
128
|
-
end
|
129
|
-
|
130
|
-
it 'checks for an invalid timestamp' do
|
131
|
-
args = parser.parse_args([
|
132
|
-
'http://lol.wut',
|
133
|
-
'output.gif',
|
134
|
-
'-s',
|
135
|
-
'rofl'
|
136
|
-
])
|
137
|
-
expect { parser.validate_args args }
|
138
|
-
.to raise_error(WGif::InvalidTimestampException)
|
139
|
-
end
|
140
|
-
|
141
|
-
it 'returns true when args are OK' do
|
142
|
-
args = parser.parse_args([
|
143
|
-
'https://crazynonsense.info',
|
144
|
-
'output.gif'
|
145
|
-
])
|
146
|
-
expect { parser.validate_args args }.not_to raise_error
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
it 'parses and validates' do
|
151
|
-
expect { parser.parse(['http://lol.wut']) }
|
152
|
-
.to raise_error(WGif::MissingOutputFileException)
|
153
|
-
end
|
154
|
-
|
155
|
-
it 'returns parsed arguments' do
|
156
|
-
args = parser.parse(['http://lol.wut', 'out.gif'])
|
157
|
-
expect(args).to eq({dimensions: '480',
|
158
|
-
duration: 1.0,
|
159
|
-
output: 'out.gif',
|
160
|
-
trim_from: '00:00:00',
|
161
|
-
url: 'http://lol.wut'})
|
162
|
-
end
|
163
|
-
end
|
110
|
+
end
|
data/spec/unit/wgif/cli_spec.rb
CHANGED
@@ -26,7 +26,7 @@ describe WGif::CLI do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'catches invalid URLs' do
|
29
|
-
WGif::ArgumentParser.
|
29
|
+
allow_any_instance_of(WGif::ArgumentParser).to receive(:parse)
|
30
30
|
.and_raise(WGif::InvalidUrlException)
|
31
31
|
expect { cli.make_gif([]) }.to raise_error(SystemExit)
|
32
32
|
message = 'That looks like an invalid URL. Check the syntax.'
|
@@ -34,7 +34,7 @@ describe WGif::CLI do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'catches invalid timestamps' do
|
37
|
-
WGif::ArgumentParser.
|
37
|
+
allow_any_instance_of(WGif::ArgumentParser).to receive(:parse)
|
38
38
|
.and_raise(WGif::InvalidTimestampException)
|
39
39
|
expect { cli.make_gif([]) }.to raise_error(SystemExit)
|
40
40
|
message = 'That looks like an invalid timestamp. Check the syntax.'
|
@@ -42,7 +42,7 @@ describe WGif::CLI do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'catches missing output args' do
|
45
|
-
WGif::ArgumentParser.
|
45
|
+
allow_any_instance_of(WGif::ArgumentParser).to receive(:parse)
|
46
46
|
.and_raise(WGif::MissingOutputFileException)
|
47
47
|
expect { cli.make_gif([]) }.to raise_error(SystemExit)
|
48
48
|
message = 'Please specify an output file.'
|
@@ -50,7 +50,7 @@ describe WGif::CLI do
|
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'catches missing videos' do
|
53
|
-
WGif::ArgumentParser.
|
53
|
+
allow_any_instance_of(WGif::ArgumentParser).to receive(:parse)
|
54
54
|
.and_raise(WGif::VideoNotFoundException)
|
55
55
|
expect { cli.make_gif([]) }.to raise_error(SystemExit)
|
56
56
|
message = "WGif can't find a valid YouTube video at that URL."
|
@@ -58,7 +58,7 @@ describe WGif::CLI do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'catches encoding exceptions' do
|
61
|
-
WGif::ArgumentParser.
|
61
|
+
allow_any_instance_of(WGif::ArgumentParser).to receive(:parse)
|
62
62
|
.and_raise(WGif::ClipEncodingException)
|
63
63
|
expect { cli.make_gif([]) }.to raise_error(SystemExit)
|
64
64
|
message = 'WGif encountered an error transcoding the video.'
|
@@ -66,20 +66,21 @@ describe WGif::CLI do
|
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'catches upload errors' do
|
69
|
-
WGif::ArgumentParser.
|
69
|
+
allow_any_instance_of(WGif::ArgumentParser).to receive(:parse)
|
70
70
|
.and_raise(WGif::ImgurException, 'Imgur error')
|
71
71
|
expect { cli.make_gif([]) }.to raise_error(SystemExit)
|
72
72
|
expect_help_with_message(@mock_stdout.string, 'Imgur error')
|
73
73
|
end
|
74
74
|
|
75
75
|
it 'raises SystemExit when thrown' do
|
76
|
-
WGif::ArgumentParser.
|
76
|
+
allow_any_instance_of(WGif::ArgumentParser).to receive(:parse)
|
77
77
|
expect { cli.make_gif([]) }.to raise_error(SystemExit)
|
78
78
|
end
|
79
79
|
|
80
80
|
it 'Prints the backtrace for all other exceptions' do
|
81
81
|
exception = StandardError.new 'crazy error'
|
82
|
-
WGif::ArgumentParser.
|
82
|
+
allow_any_instance_of(WGif::ArgumentParser).to receive(:parse)
|
83
|
+
.and_raise(exception)
|
83
84
|
expect { cli.make_gif([]) }.to raise_error(SystemExit)
|
84
85
|
message = 'Something went wrong creating your GIF. The details:'
|
85
86
|
expect_help_with_message(@mock_stdout.string, message)
|
@@ -9,7 +9,7 @@ describe WGif::DownloadBar do
|
|
9
9
|
let(:mock_progress_bar) { double(ProgressBar) }
|
10
10
|
|
11
11
|
before do
|
12
|
-
ProgressBar.
|
12
|
+
allow(ProgressBar).to receive(:create).and_return(mock_progress_bar)
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'creates a ProgressBar with the correct format, smoothing, and size' do
|
@@ -9,46 +9,46 @@ describe WGif::Downloader do
|
|
9
9
|
before do
|
10
10
|
FileUtils.rm_rf('/tmp/wgif')
|
11
11
|
download_bar = double(WGif::DownloadBar).as_null_object
|
12
|
-
WGif::DownloadBar.
|
12
|
+
allow(WGif::DownloadBar).to receive(:new).and_return(download_bar)
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'retrieves a YouTube download URL' do
|
16
|
-
ViddlRb.
|
17
|
-
downloader.video_url
|
16
|
+
expect(ViddlRb).to receive(:get_urls).with(clip_url).and_return(['clip url'])
|
17
|
+
expect(downloader.video_url clip_url).to eq('clip url')
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'retrieves a YouTube video ID' do
|
21
|
-
downloader.video_id
|
21
|
+
expect(downloader.video_id clip_url).to eq('roflcopter')
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'throws an error if the video is not found' do
|
25
|
-
ViddlRb.
|
25
|
+
expect(ViddlRb).to receive(:get_urls).with(clip_url)
|
26
26
|
.and_return(['http://lol.wut'])
|
27
27
|
expect { downloader.get_video(clip_url) }
|
28
28
|
.to raise_error(WGif::VideoNotFoundException)
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'extracts a YouTube ID from a URL' do
|
32
|
-
downloader.video_id
|
32
|
+
expect(downloader.video_id 'http://lol.wut?v=id').to eq('id')
|
33
33
|
end
|
34
34
|
|
35
35
|
context 'downloading videos' do
|
36
36
|
|
37
37
|
before do
|
38
|
-
ViddlRb.
|
38
|
+
allow(ViddlRb).to receive(:get_urls).and_return([clip_url])
|
39
39
|
fake_request = double('Typhoeus::Request')
|
40
40
|
fake_response = double('Typhoeus::Response')
|
41
|
-
Typhoeus::Request.
|
41
|
+
expect(Typhoeus::Request).to receive(:new).once
|
42
42
|
.with(clip_url).and_return(fake_request)
|
43
|
-
fake_request.
|
44
|
-
fake_request.
|
45
|
-
fake_request.
|
46
|
-
fake_response.
|
43
|
+
expect(fake_request).to receive(:on_headers)
|
44
|
+
expect(fake_request).to receive(:on_body)
|
45
|
+
expect(fake_request).to receive(:run).and_return(fake_response)
|
46
|
+
expect(fake_response).to receive(:response_code).and_return(200)
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'downloads a clip' do
|
50
50
|
video = double(name: 'video')
|
51
|
-
WGif::Video.
|
51
|
+
expect(WGif::Video).to receive(:new)
|
52
52
|
.with('roflcopter', '/tmp/wgif/roflcopter').and_return(video)
|
53
53
|
downloader.get_video(clip_url)
|
54
54
|
end
|
@@ -62,7 +62,7 @@ describe WGif::Downloader do
|
|
62
62
|
context 'errors' do
|
63
63
|
|
64
64
|
it 'throws an exception when the download URL is not found' do
|
65
|
-
ViddlRb.
|
65
|
+
allow(ViddlRb).to receive(:get_urls).and_raise(RuntimeError)
|
66
66
|
expect { downloader.video_url('invalid url') }
|
67
67
|
.to raise_error(WGif::VideoNotFoundException)
|
68
68
|
end
|
@@ -8,13 +8,13 @@ describe WGif::GifMaker do
|
|
8
8
|
let(:images) { double(Magick::ImageList, each: nil) }
|
9
9
|
|
10
10
|
before do
|
11
|
-
Magick::ImageList.
|
11
|
+
allow(Magick::ImageList).to receive(:new).and_return(images)
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'converts a directory of frames to a gif' do
|
15
|
-
images.
|
16
|
-
images.
|
17
|
-
images.
|
15
|
+
expect(images).to receive(:coalesce)
|
16
|
+
expect(images).to receive(:optimize_layers)
|
17
|
+
expect(images).to receive(:write).with('bjork.gif')
|
18
18
|
gif_maker.make_gif([], 'bjork.gif', '500')
|
19
19
|
end
|
20
20
|
|
@@ -16,7 +16,7 @@ describe WGif::InfoDisplayer do
|
|
16
16
|
|
17
17
|
it 'prints out a file size to the command line' do
|
18
18
|
file_name = "fake_file_name.rb"
|
19
|
-
File.
|
19
|
+
allow(File).to receive(:size).with(file_name).and_return('1048576')
|
20
20
|
cache.display(file_name)
|
21
21
|
expect(@mock_stdout.string).to match(/1.000 MB/)
|
22
22
|
end
|
@@ -27,7 +27,7 @@ describe WGif::Uploader do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'sends an authorized POST request to Imgur with image file data' do
|
30
|
-
File.
|
30
|
+
allow(File).to receive(:open).and_yield(tempfile)
|
31
31
|
expect(Typhoeus).to receive(:post)
|
32
32
|
.with('https://api.imgur.com/3/image', request_params).and_return(success)
|
33
33
|
uploader.upload(tempfile.path)
|
@@ -40,7 +40,7 @@ describe WGif::Uploader do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'returns the url when successful' do
|
43
|
-
File.
|
43
|
+
allow(File).to receive(:open).and_yield(tempfile)
|
44
44
|
expect(Typhoeus).to receive(:post)
|
45
45
|
.with('https://api.imgur.com/3/image', request_params).and_return(success)
|
46
46
|
expect(uploader.upload(tempfile.path)).to eq('foo')
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'wgif/validator'
|
3
|
+
|
4
|
+
describe WGif::Validator do
|
5
|
+
let(:valid_args) do
|
6
|
+
{
|
7
|
+
url: 'https://crazynonsense.info',
|
8
|
+
output: 'output.gif',
|
9
|
+
trim_from: '00:00:01'
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'checks for a missing output file' do
|
14
|
+
args = valid_args.merge(output: nil)
|
15
|
+
expect { described_class.new(args).validate }
|
16
|
+
.to raise_error(WGif::MissingOutputFileException)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'checks for an invalid URL' do
|
20
|
+
args = valid_args.merge(url: 'crazy nonsense')
|
21
|
+
expect { described_class.new(args).validate }
|
22
|
+
.to raise_error(WGif::InvalidUrlException)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'checks for an invalid timestamp' do
|
26
|
+
args = valid_args.merge(trim_from: 'rofl')
|
27
|
+
expect { described_class.new(args).validate }
|
28
|
+
.to raise_error(WGif::InvalidTimestampException)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns true when args are OK' do
|
32
|
+
expect { described_class.new(valid_args).validate }
|
33
|
+
.not_to raise_error
|
34
|
+
end
|
35
|
+
end
|
@@ -5,20 +5,20 @@ describe WGif::Video do
|
|
5
5
|
let(:clip) { double(FFMPEG::Movie) }
|
6
6
|
|
7
7
|
before do
|
8
|
-
FFMPEG::Movie.
|
8
|
+
allow(FFMPEG::Movie).to receive(:new).and_return(clip)
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'has a name and filepath' do
|
12
|
-
clip.
|
12
|
+
expect(clip).to receive(:path).and_return('/tmp/wgif/bjork.mp4')
|
13
13
|
video = described_class.new 'bjork', '/tmp/wgif/bjork.mp4'
|
14
|
-
video.name.
|
15
|
-
video.clip.path.
|
14
|
+
expect(video.name).to eq('bjork')
|
15
|
+
expect(video.clip.path).to eq('/tmp/wgif/bjork.mp4')
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'sets up a logger' do
|
19
19
|
video = described_class.new 'bjork', '/tmp/wgif/bjork.mp4'
|
20
|
-
video.logger.instance_variable_get(:@logdev).filename
|
21
|
-
.
|
20
|
+
expect(video.logger.instance_variable_get(:@logdev).filename)
|
21
|
+
.to eq('/tmp/wgif/bjork.log')
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'redirects FFMPEG log output to a file' do
|
@@ -27,29 +27,29 @@ describe WGif::Video do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'is trimmable' do
|
30
|
-
clip.
|
30
|
+
expect(clip).to receive(:duration).and_return(5.0)
|
31
31
|
expect(clip).to receive(:transcode)
|
32
32
|
video = described_class.new 'bjork', '/tmp/wgif/bjork.mp4'
|
33
33
|
video = video.trim('00:00:00', 5.0)
|
34
|
-
video.clip.duration.
|
34
|
+
expect(video.clip.duration).to eq(5.0)
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'returns its frames' do
|
38
38
|
expect(clip).to receive(:transcode)
|
39
|
-
FileUtils.
|
39
|
+
allow(FileUtils).to receive(:rm)
|
40
40
|
fake_frames = ['one', 'two', 'three']
|
41
41
|
expect(Dir).to receive(:glob).with('/tmp/wgif/frames/*.png').twice
|
42
42
|
.and_return(fake_frames)
|
43
43
|
video = described_class.new 'bjork', '/tmp/wgif/bjork.mp4'
|
44
44
|
frames = video.to_frames
|
45
|
-
frames.count.
|
45
|
+
expect(frames.count).to eq(3)
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'returns a specific number of frames' do
|
49
49
|
frames = '/tmp/wgif/frames/%5d.png'
|
50
50
|
options = '-vf fps=5'
|
51
51
|
expect(clip).to receive(:transcode).with(frames, options)
|
52
|
-
FileUtils.
|
52
|
+
allow(FileUtils).to receive(:rm)
|
53
53
|
expect(clip).to receive(:duration).and_return 2
|
54
54
|
expect(Dir).to receive(:glob).with('/tmp/wgif/frames/*.png').twice
|
55
55
|
video = described_class.new 'bjork', '/tmp/wgif/bjork.mp4'
|
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.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Connor Mendenhall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rmagick
|
@@ -191,6 +191,7 @@ files:
|
|
191
191
|
- lib/wgif/info_displayer.rb
|
192
192
|
- lib/wgif/installer.rb
|
193
193
|
- lib/wgif/uploader.rb
|
194
|
+
- lib/wgif/validator.rb
|
194
195
|
- lib/wgif/version.rb
|
195
196
|
- lib/wgif/video.rb
|
196
197
|
- lib/wgif/video_cache.rb
|
@@ -205,6 +206,7 @@ files:
|
|
205
206
|
- spec/unit/wgif/info_displayer_spec.rb
|
206
207
|
- spec/unit/wgif/installer_spec.rb
|
207
208
|
- spec/unit/wgif/uploader_spec.rb
|
209
|
+
- spec/unit/wgif/validator_spec.rb
|
208
210
|
- spec/unit/wgif/video_cache_spec.rb
|
209
211
|
- spec/unit/wgif/video_spec.rb
|
210
212
|
- wgif.gemspec
|
@@ -245,5 +247,6 @@ test_files:
|
|
245
247
|
- spec/unit/wgif/info_displayer_spec.rb
|
246
248
|
- spec/unit/wgif/installer_spec.rb
|
247
249
|
- spec/unit/wgif/uploader_spec.rb
|
250
|
+
- spec/unit/wgif/validator_spec.rb
|
248
251
|
- spec/unit/wgif/video_cache_spec.rb
|
249
252
|
- spec/unit/wgif/video_spec.rb
|