lib/wgif/cli.rb in wgif-0.0.1 vs lib/wgif/cli.rb in wgif-0.2.0
- old
+ new
@@ -33,10 +33,15 @@
opts.on('-w pixels',
'--width pixels',
'Width of the gif in pixels. (Default 500px)') {
|gs| @options[:dimensions] = gs
}
+ opts.on('-u',
+ '--upload',
+ 'Upload finished GIF to Imgur') {
+ |u| @options[:upload] = !!u
+ }
opts.on_tail('-h',
'--help',
'Print help information.') {
print_help
@@ -63,17 +68,22 @@
def make_gif(cli_args)
WGif::Installer.new.run if cli_args[0] == 'install'
require 'wgif/downloader'
require 'wgif/gif_maker'
+ require 'wgif/uploader'
rescue_errors do
args = parse_args cli_args
validate_args(args)
video = Downloader.new.get_video(args[:url])
clip = video.trim(args[:trim_from], args[:duration])
frames = clip.to_frames(frames: args[:frames])
GifMaker.new.make_gif(frames, args[:output], args[:dimensions])
+ if args[:upload]
+ url = Uploader.new('d2321b02db7ba15').upload(args[:output])
+ puts "Finished. GIF uploaded to Imgur at #{url}"
+ end
end
end
private
@@ -88,9 +98,15 @@
print_error 'Please specify an output file.'
rescue WGif::VideoNotFoundException
print_error "WGif can't find a valid YouTube video at that URL."
rescue WGif::ClipEncodingException
print_error "WGif encountered an error transcoding the video."
+ rescue WGif::ImgurException => e
+ print_error <<-error
+WGif couldn't upload your GIF to Imgur. The Imgur error was:
+
+#{e}
+error
rescue SystemExit => e
raise e
rescue Exception => e
print_error <<-error
Something went wrong creating your GIF. The details: