viddl 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a5ef695a66a63b6bf813c4ac3e9c2b09bf1352f7
4
- data.tar.gz: 416f77293151ec5e371cff6565d5ae4d20829320
3
+ metadata.gz: 6b07f12926474b14cea4f3d36255ccfcd0d9b12b
4
+ data.tar.gz: 2058b3dc1af7197158eacdddffbf88e979383c0e
5
5
  SHA512:
6
- metadata.gz: adc667e5bb6c177f82ce737548936e320871807f6e9af733e448f1cbadf8cb506671363f43b70cc4f02b4363d21d8821fa874bf383b268816f45543f72a75279
7
- data.tar.gz: 18dc4a555419f405a2d7e251a36eebe85c5623ec47215af5533b5ba145b89fa0468fdce229166df59df98eba0bef62a35ac106f44657bb6b2452da588022982c
6
+ metadata.gz: 99e34cc08878f9e6c6193925bb6456481fb28ec07689c608f0b0e6f66e5d9c9fd75da9f5f267b16f23d0cd2ec78a206465751c54456e097b8ad825c7e4412bc2
7
+ data.tar.gz: 0d498f7807d838375aecf08408b329ba61704846d364a39008b22c320aa19ec8c338f5006e1ce18717d63b5f3a5b1c6d1101b1cec0f3523c98273b91cbbf74ad
data/README.md CHANGED
@@ -96,7 +96,8 @@ options = {
96
96
  height: 40
97
97
  },
98
98
  width: 640,
99
- height: 480
99
+ height: 480,
100
+ output_path: "assets/video"
100
101
  }
101
102
 
102
103
  video = Viddl::Video.download("https://www.youtube.com/watch?v=6g4dkBF5anU")
data/bin/viddl CHANGED
@@ -67,6 +67,12 @@ opts = OptionParser.new do |opts|
67
67
 
68
68
  opts.on_tail("--help", "Show this message") { help(opts) }
69
69
 
70
+ # file
71
+
72
+ opts.on("-oPATH", "--output-path=PATH", "Output path") do |path|
73
+ options[:output_path] = path
74
+ end
75
+
70
76
  end
71
77
  opts.parse!
72
78
 
@@ -17,6 +17,6 @@ module Viddl
17
17
 
18
18
  extend self
19
19
 
20
- VERSION = "0.0.4"
20
+ VERSION = "0.0.5"
21
21
 
22
22
  end
@@ -23,6 +23,7 @@ module Viddl
23
23
  # @option options [Integer, String] :width The desired width to resize to
24
24
  # @option options [Integer, String] :height The desired height to resize to
25
25
  # @option options [Hash] :crop The desired crop parameters (:x, :y, :width, :height)
26
+ # @option options [Pathname, String] :output_path Path where clip will be written
26
27
  # @return [Clip]
27
28
  def self.process(path, options = {})
28
29
  clip = new(path)
@@ -44,14 +45,15 @@ module Viddl
44
45
  # @option options [Integer, String] :width The desired width to resize to
45
46
  # @option options [Integer, String] :height The desired height to resize to
46
47
  # @option options [Hash] :crop The desired crop parameters (:x, :y, :width, :height)
48
+ # @option options [Pathname, String] :output_path Path where clip will be written
47
49
  # @return [Boolean]
48
50
  def process(options = {})
49
51
  command = command_line(options)
50
52
  Kernel.system(command)
51
53
  end
52
54
 
53
- # Path of the created clip
54
- # @return [Pathname]
55
+ # Path of the created clip. Is nil until file exists
56
+ # @return [Pathname, nil]
55
57
  def path
56
58
  if !@path.nil? && File.exists?(@path)
57
59
  @path
@@ -69,6 +71,7 @@ module Viddl
69
71
  # @option options [Integer, String] :width The desired width to resize to
70
72
  # @option options [Integer, String] :height The desired height to resize to
71
73
  # @option options [Hash] :crop The desired crop parameters (:x, :y, :width, :height)
74
+ # @option options [Pathname, String] :output_path Path where clip will be written
72
75
  # @return [String]
73
76
  def command_line(options = {})
74
77
  if options.values.compact.empty?
@@ -118,18 +121,24 @@ module Viddl
118
121
  # @option options [Integer, String] :width The desired width to resize to
119
122
  # @option options [Integer, String] :height The desired height to resize to
120
123
  # @option options [Hash] :crop The desired crop parameters (:x, :y, :width, :height)
124
+ # @option options [Pathname, String] :output_path Path where clip will be written
121
125
  # @return [String]
122
126
  def populate_output_path(options = {})
123
127
  base = @source_path.scan(/#{Download::TEMPDIR}\/(.*)/).flatten.first
124
128
  result = base
125
129
  if !options.values.flatten.compact.empty?
126
130
  name, ext = *base.split(".")
127
- tokens = ""
128
- MODULES.each do |mod|
129
- token = mod.filename_token(options)
130
- tokens += "-#{token}" unless token.nil?
131
+ result = if options[:output_path].nil? || File.directory?(options[:output_path])
132
+ tokens = ""
133
+ MODULES.each do |mod|
134
+ token = mod.filename_token(options)
135
+ tokens += "-#{token}" unless token.nil?
136
+ end
137
+ path = "#{options[:output_path]}/" unless options[:output_path].nil?
138
+ "#{path}#{name}#{tokens}.#{ext}"
139
+ elsif !options[:output_path].nil?
140
+ "#{options[:output_path]}.#{ext}"
131
141
  end
132
- result = "#{name}#{tokens}.#{ext}"
133
142
  end
134
143
  @path = Pathname.new(result)
135
144
  end
@@ -27,6 +27,7 @@ module Viddl
27
27
  # @option options [Integer, String] :width The desired width to resize to
28
28
  # @option options [Integer, String] :height The desired height to resize to
29
29
  # @option options [Hash] :crop The desired crop parameters (:x, :y, :width, :height)
30
+ # @option options [Pathname, String] :output_path path where clip will be written. Can be directory or filename
30
31
  # @return [Array<Clip>]
31
32
  def create_clip(options = {})
32
33
  source_filenames.map do |filename|
@@ -335,6 +335,35 @@ describe Viddl::Video::Clip do
335
335
 
336
336
  end
337
337
 
338
+ context "with output path" do
339
+
340
+ context "with valid directory" do
341
+
342
+ it "includes directory" do
343
+ expect(File).to(receive(:directory?).and_return(true))
344
+ options = {
345
+ output_path: "this/isadir"
346
+ }
347
+ path = @clip.send(:populate_output_path, options)
348
+ expect(path.to_s).to(eq("this/isadir/6g4dkBF5anU.mkv"))
349
+ end
350
+
351
+ end
352
+
353
+ context "with path/filename" do
354
+
355
+ it "includes path/filename" do
356
+ expect(File).to(receive(:directory?).and_return(false))
357
+ options = {
358
+ output_path: "thisis/afile"
359
+ }
360
+ path = @clip.send(:populate_output_path, options)
361
+ expect(path.to_s).to(eq("thisis/afile.mkv"))
362
+ end
363
+
364
+ end
365
+ end
366
+
338
367
  context "crop options" do
339
368
 
340
369
  context "valid" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: viddl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ari Russo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-17 00:00:00.000000000 Z
11
+ date: 2017-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake