viddl 0.0.3 → 0.0.4

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: c6c38487a2d7d5f254f6a2c578ee593a19869e92
4
- data.tar.gz: 7a23f5b3d8a6e3bb71c66c60db05f22dcb142e9b
3
+ metadata.gz: a5ef695a66a63b6bf813c4ac3e9c2b09bf1352f7
4
+ data.tar.gz: 416f77293151ec5e371cff6565d5ae4d20829320
5
5
  SHA512:
6
- metadata.gz: c394b34c44d1181ae5595f03ae5c66651154494b6e16c19537955bd412625d7ea46f578c5e0bb33bb4ffbdbae10c82a4737962124ca8ef3e4c3eabf903755b47
7
- data.tar.gz: 0b07f0783b4028f740d320d14bc09419415b30727807c347d0dbb8a22602d74666d93c64390921623873a514768d1fc55e09ac5aba68afe42226a6d7ce6af313
6
+ metadata.gz: adc667e5bb6c177f82ce737548936e320871807f6e9af733e448f1cbadf8cb506671363f43b70cc4f02b4363d21d8821fa874bf383b268816f45543f72a75279
7
+ data.tar.gz: 18dc4a555419f405a2d7e251a36eebe85c5623ec47215af5533b5ba145b89fa0468fdce229166df59df98eba0bef62a35ac106f44657bb6b2452da588022982c
data/README.md CHANGED
@@ -6,7 +6,17 @@ Use Viddl to quickly download, cut, crop and resize videos
6
6
 
7
7
  Viddl can be used at the [command line](#command-line) or in [Ruby](#ruby)
8
8
 
9
- It requires that both [youtube-dl](https://github.com/rg3/youtube-dl) and [ffmpeg](https://ffmpeg.org) are installed before using.
9
+ ## Installation
10
+
11
+ Viddl requires that both [youtube-dl](https://github.com/rg3/youtube-dl) and [ffmpeg](https://ffmpeg.org) are installed before using.
12
+
13
+ Install Viddl using gem
14
+
15
+ `gem install viddl`
16
+
17
+ or using Bundler by adding the following to your Gemfile
18
+
19
+ `gem "viddl"`
10
20
 
11
21
  ## Usage
12
22
 
@@ -17,6 +17,6 @@ module Viddl
17
17
 
18
18
  extend self
19
19
 
20
- VERSION = "0.0.3"
20
+ VERSION = "0.0.4"
21
21
 
22
22
  end
@@ -7,9 +7,7 @@ module Viddl
7
7
  # Validate that the system has all of its dependencies
8
8
  # @return [Boolean]
9
9
  def validate
10
- validate_ffmpeg
11
- validate_youtube_dl
12
- true
10
+ validate_ffmpeg && validate_youtube_dl
13
11
  end
14
12
 
15
13
  private
@@ -31,6 +29,7 @@ module Viddl
31
29
  if result.nil?
32
30
  raise("Viddl requires that youtube-dl be installed https://github.com/rg3/youtube-dl")
33
31
  end
32
+ true
34
33
  end
35
34
 
36
35
  end
@@ -1,3 +1,5 @@
1
+ require "pathname"
2
+
1
3
  require "viddl/video/clip/audio"
2
4
  require "viddl/video/clip/crop"
3
5
  require "viddl/video/clip/cut"
@@ -48,6 +50,14 @@ module Viddl
48
50
  Kernel.system(command)
49
51
  end
50
52
 
53
+ # Path of the created clip
54
+ # @return [Pathname]
55
+ def path
56
+ if !@path.nil? && File.exists?(@path)
57
+ @path
58
+ end
59
+ end
60
+
51
61
  private
52
62
 
53
63
  # Command line to create a clip from the source file and given options
@@ -64,7 +74,8 @@ module Viddl
64
74
  if options.values.compact.empty?
65
75
  # when there are no clip options, the source file can just be copied
66
76
  # over to the output file location without using ffmpeg
67
- "cp #{@source_path} #{output_path}"
77
+ populate_output_path
78
+ "cp #{@source_path} #{@path.to_s}"
68
79
  else
69
80
  formatted_opts = options_formatted(options)
70
81
 
@@ -79,7 +90,8 @@ module Viddl
79
90
  module_arg_string += " -vf '#{module_filters.join(",")}'"
80
91
  end
81
92
 
82
- "ffmpeg -i #{@source_path} #{module_arg_string} #{output_path(formatted_opts)}"
93
+ populate_output_path(formatted_opts)
94
+ "ffmpeg -i #{@source_path} #{module_arg_string} #{@path.to_s}"
83
95
  end
84
96
  end
85
97
 
@@ -98,7 +110,7 @@ module Viddl
98
110
  mod_options.inject(:merge)
99
111
  end
100
112
 
101
- # Path of the created clip
113
+ # Set the clip path
102
114
  # @param [Hash] options
103
115
  # @option options [Boolean] :audio Whether to include audio
104
116
  # @option options [Numeric] :start Time in the source file where the clip starts
@@ -107,7 +119,7 @@ module Viddl
107
119
  # @option options [Integer, String] :height The desired height to resize to
108
120
  # @option options [Hash] :crop The desired crop parameters (:x, :y, :width, :height)
109
121
  # @return [String]
110
- def output_path(options = {})
122
+ def populate_output_path(options = {})
111
123
  base = @source_path.scan(/#{Download::TEMPDIR}\/(.*)/).flatten.first
112
124
  result = base
113
125
  if !options.values.flatten.compact.empty?
@@ -119,7 +131,7 @@ module Viddl
119
131
  end
120
132
  result = "#{name}#{tokens}.#{ext}"
121
133
  end
122
- result
134
+ @path = Pathname.new(result)
123
135
  end
124
136
 
125
137
  end
@@ -1,11 +1,13 @@
1
+ require "tmpdir"
2
+
1
3
  module Viddl
2
4
 
3
5
  module Video
4
6
 
5
7
  class Download
6
8
 
7
- # download is stored to /tmp before processing
8
- TEMPDIR = "/tmp"
9
+ # download is stored to temp dir before processing
10
+ TEMPDIR = Dir.tmpdir
9
11
  # download format is forced to mp4 to optimize for quickness
10
12
  FORMAT_ARG = "-f 'best[ext=mp4]'"
11
13
 
@@ -2,7 +2,3 @@ $:.unshift(File.join("..", "lib"))
2
2
 
3
3
  require "rspec"
4
4
  require "viddl"
5
-
6
- #RSpec.configure do |c|
7
- # c.mock_with :rspec
8
- #end
@@ -3,7 +3,7 @@ require "helper"
3
3
  describe Viddl::Video::Clip do
4
4
 
5
5
  before(:each) do
6
- @source_file = "/tmp/6g4dkBF5anU.mkv"
6
+ @source_file = "#{Viddl::Video::Download::TEMPDIR}/6g4dkBF5anU.mkv"
7
7
  @clip = Viddl::Video::Clip.new(@source_file)
8
8
  end
9
9
 
@@ -297,13 +297,40 @@ describe Viddl::Video::Clip do
297
297
 
298
298
  end
299
299
 
300
- context "#output_path" do
300
+ context "#path" do
301
+
302
+ context "when file doesn't exist" do
303
+
304
+ it "returns nil" do
305
+ @clip.send(:populate_output_path)
306
+ path = @clip.path
307
+ expect(path).to(be_nil)
308
+ end
309
+
310
+ end
311
+
312
+ context "when file exists" do
313
+
314
+ it "returns nil" do
315
+ expect(File).to(receive(:exists?).and_return(true))
316
+ @clip.send(:populate_output_path)
317
+ path = @clip.path
318
+ expect(path).to_not(be_nil)
319
+ expect(path).to(be_kind_of(Pathname))
320
+ expect(path.to_s).to(eq("6g4dkBF5anU.mkv"))
321
+ end
322
+
323
+ end
324
+
325
+ end
326
+
327
+ context "#populate_output_path" do
301
328
 
302
329
  context "with no options" do
303
330
 
304
331
  it "matches source path file name" do
305
- path = @clip.send(:output_path)
306
- expect(path).to(eq("6g4dkBF5anU.mkv"))
332
+ path = @clip.send(:populate_output_path)
333
+ expect(path.to_s).to(eq("6g4dkBF5anU.mkv"))
307
334
  end
308
335
 
309
336
  end
@@ -321,8 +348,8 @@ describe Viddl::Video::Clip do
321
348
  height: 230
322
349
  }
323
350
  }
324
- path = @clip.send(:output_path, options)
325
- expect(path).to(eq("6g4dkBF5anU-cx200cy210cw220ch230.mkv"))
351
+ path = @clip.send(:populate_output_path, options)
352
+ expect(path.to_s).to(eq("6g4dkBF5anU-cx200cy210cw220ch230.mkv"))
326
353
  end
327
354
 
328
355
  end
@@ -337,8 +364,8 @@ describe Viddl::Video::Clip do
337
364
  options = {
338
365
  width: 640
339
366
  }
340
- path = @clip.send(:output_path, options)
341
- expect(path).to(eq("6g4dkBF5anU-w640.mkv"))
367
+ path = @clip.send(:populate_output_path, options)
368
+ expect(path.to_s).to(eq("6g4dkBF5anU-w640.mkv"))
342
369
  end
343
370
 
344
371
  end
@@ -349,8 +376,8 @@ describe Viddl::Video::Clip do
349
376
  options = {
350
377
  height: 480
351
378
  }
352
- path = @clip.send(:output_path, options)
353
- expect(path).to(eq("6g4dkBF5anU-h480.mkv"))
379
+ path = @clip.send(:populate_output_path, options)
380
+ expect(path.to_s).to(eq("6g4dkBF5anU-h480.mkv"))
354
381
  end
355
382
 
356
383
  end
@@ -362,8 +389,8 @@ describe Viddl::Video::Clip do
362
389
  width: 1280,
363
390
  height: 720
364
391
  }
365
- path = @clip.send(:output_path, options)
366
- expect(path).to(eq("6g4dkBF5anU-w1280h720.mkv"))
392
+ path = @clip.send(:populate_output_path, options)
393
+ expect(path.to_s).to(eq("6g4dkBF5anU-w1280h720.mkv"))
367
394
  end
368
395
 
369
396
  end
@@ -376,8 +403,8 @@ describe Viddl::Video::Clip do
376
403
  options = {
377
404
  audio: false
378
405
  }
379
- path = @clip.send(:output_path, options)
380
- expect(path).to(eq("6g4dkBF5anU-noaudio.mkv"))
406
+ path = @clip.send(:populate_output_path, options)
407
+ expect(path.to_s).to(eq("6g4dkBF5anU-noaudio.mkv"))
381
408
  end
382
409
 
383
410
  end
@@ -391,8 +418,8 @@ describe Viddl::Video::Clip do
391
418
  audio: true,
392
419
  start: 10
393
420
  }
394
- path = @clip.send(:output_path, options)
395
- expect(path).to(eq("6g4dkBF5anU-s10.mkv"))
421
+ path = @clip.send(:populate_output_path, options)
422
+ expect(path.to_s).to(eq("6g4dkBF5anU-s10.mkv"))
396
423
  end
397
424
 
398
425
  end
@@ -404,8 +431,8 @@ describe Viddl::Video::Clip do
404
431
  audio: true,
405
432
  duration: 1.5
406
433
  }
407
- path = @clip.send(:output_path, options)
408
- expect(path).to(eq("6g4dkBF5anU-d1.5.mkv"))
434
+ path = @clip.send(:populate_output_path, options)
435
+ expect(path.to_s).to(eq("6g4dkBF5anU-d1.5.mkv"))
409
436
  end
410
437
 
411
438
  end
@@ -418,8 +445,8 @@ describe Viddl::Video::Clip do
418
445
  duration: 12,
419
446
  start: 6
420
447
  }
421
- path = @clip.send(:output_path, options)
422
- expect(path).to(eq("6g4dkBF5anU-s6d12.mkv"))
448
+ path = @clip.send(:populate_output_path, options)
449
+ expect(path.to_s).to(eq("6g4dkBF5anU-s6d12.mkv"))
423
450
  end
424
451
 
425
452
  end
@@ -45,7 +45,7 @@ describe Viddl::Video::Instance do
45
45
 
46
46
  before(:each) do
47
47
  @download = Viddl::Video::Download.new(@video)
48
- expect(@video).to(receive(:source_filenames).and_return(["/tmp/#{@video_id}.mkv"]))
48
+ expect(@video).to(receive(:source_filenames).and_return(["#{Viddl::Video::Download::TEMPDIR}/#{@video_id}.mkv"]))
49
49
  end
50
50
 
51
51
  context "with no options" 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.3
4
+ version: 0.0.4
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-05 00:00:00.000000000 Z
11
+ date: 2017-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake