viddl 0.0.12 → 0.0.13

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ed0b351b03d9f36a4e05e58e75f7888f5b00705
4
- data.tar.gz: dcb78be7dda34560ebce6251209a136e959b100d
3
+ metadata.gz: 0a8ffecdc2be6152fcf551d440aaacf10456e35c
4
+ data.tar.gz: a97703c433bdc2cac2db3e05ac62dd65cd36c8d9
5
5
  SHA512:
6
- metadata.gz: 0dc717bcadda5d0ddd2c3dc6b2ab3ffbc3a2006df6209354aef9d45bdec40727b7f67a354c8642f4c031e0f68ad93fd4113083bf706eb2fe3e68f5d594765225
7
- data.tar.gz: ecba5952e475aa9c162e6c3f1a06a86bf4f5f892d5c96109538fe9fffe1613e17cb2ee38d4982bd98093a3472892d160357baff85987ad5a5fd5da5cba154856
6
+ metadata.gz: 19bb0115958d5c97d22985cb1503bb6517d85af4b5b2bad97325e9fca05e08e08485af9c7a1e33c5e38f35290fc23c7344c58e299cd86f70587e1146efa816fb
7
+ data.tar.gz: 281143db5b201ef2f8c2dd6b465a55ec9631e30c0119c661ee06ec2cd0d80849f548bcc61fbbdaa3194fda7f8db7ff4ede82373973ceffd191e64fc739fc270f
data/bin/viddl CHANGED
@@ -67,7 +67,11 @@ opts = OptionParser.new do |opts|
67
67
 
68
68
  opts.on_tail("--help", "Show this message") { help(opts) }
69
69
 
70
- # file
70
+ # storage
71
+
72
+ opts.on("--download-path=PATH", "Download path") do |path|
73
+ options[:download_path] = path
74
+ end
71
75
 
72
76
  opts.on("-oPATH", "--output-path=PATH", "Output path") do |path|
73
77
  options[:output_path] = path
@@ -17,6 +17,6 @@ module Viddl
17
17
 
18
18
  extend self
19
19
 
20
- VERSION = "0.0.12"
20
+ VERSION = "0.0.13"
21
21
 
22
22
  end
@@ -11,6 +11,8 @@ module Viddl
11
11
  # Download a video using the given url
12
12
  # @param [String] url
13
13
  # @param [Hash] options
14
+ # @option options [String, File] :download_path Path where download should be stored (default: system temp directory)
15
+ # @option options [String] :flags Flags to pass to youtube-dl
14
16
  # @return [Video::Instance]
15
17
  def download(url, options = {})
16
18
  video = Instance.new(url)
@@ -7,13 +7,16 @@ module Viddl
7
7
  class Download
8
8
 
9
9
  # download is stored to temp dir before processing
10
- TEMPDIR = Dir.tmpdir
10
+ DEFAULT_TEMPDIR = Dir.tmpdir
11
11
  # download format is forced to mp4 to optimize for quickness
12
12
  FORMAT_ARG = "-f 'best[ext=mp4]'"
13
13
 
14
+ attr_reader :paths
15
+
14
16
  # Download the given video
15
17
  # @param [Video::Instance] video
16
18
  # @param [Hash] options
19
+ # @option options [String, File] :download_path Path where download should be stored (default: system temp directory)
17
20
  # @option options [String] :flags Flags to pass to youtube-dl
18
21
  # @return [Download]
19
22
  def self.process(video, options = {})
@@ -30,23 +33,53 @@ module Viddl
30
33
 
31
34
  # Download the video file
32
35
  # @param [Hash] options
36
+ # @option options [String, File] :download_path Path where download should be stored (default: system temp directory)
33
37
  # @option options [String] :flags Flags to pass to youtube-dl
34
38
  # @return [Boolean]
35
39
  def process(options = {})
36
40
  cmd = command_line(options)
37
41
  result = Kernel.system(cmd)
38
- raise(result.to_s) unless result
42
+ if result
43
+ @paths = Dir["#{path}*"]
44
+ else
45
+ raise(result.to_s)
46
+ end
39
47
  true
40
48
  end
41
49
 
42
50
  private
43
51
 
52
+ # The path where the download should be written
53
+ # @param [Hash] options
54
+ # @option options [String, File] :download_path Path where download should be stored (default: system temp directory)
55
+ # @return [String]
56
+ def path(options = {})
57
+ @download_path ||= build_path(options)
58
+ end
59
+
60
+ # Build the download path
61
+ # @param [Hash] options
62
+ # @option options [String, File] :download_path Path where download should be stored (default: system temp directory)
63
+ # @return [String]
64
+ def build_path(options = {})
65
+ if options[:download_path].nil?
66
+ "#{DEFAULT_TEMPDIR}/#{@video.id}"
67
+ elsif File.directory?(options[:download_path])
68
+ "#{options[:download_path]}/#{@video.id}"
69
+ else
70
+ options[:download_path]
71
+ end
72
+ end
73
+
44
74
  # Command line to download the video file
45
75
  # @param [Hash] options
76
+ # @option options [String, File] :download_path Path where download should be stored (default: system temp directory)
46
77
  # @option options [String] :flags Flags to pass to youtube-dl
47
78
  # @return [String]
48
79
  def command_line(options = {})
49
- "youtube-dl #{@video.source_url} #{FORMAT_ARG} #{options[:flags]} -o '#{TEMPDIR}/#{@video.id}s.%(ext)s'"
80
+ download_path = path(options)
81
+ output_flag = "-o '#{download_path}.%(ext)s'"
82
+ "youtube-dl #{@video.source_url} #{FORMAT_ARG} #{options[:flags]} #{output_flag}"
50
83
  end
51
84
 
52
85
  end
@@ -31,25 +31,27 @@ module Viddl
31
31
  # @option options [Pathname, String] :output_path path where clip will be written. Can be directory or filename
32
32
  # @return [Array<Clip>]
33
33
  def create_clip(options = {})
34
- source_filenames.map do |filename|
35
- Clip.process(filename, options)
34
+ download_paths.map do |path|
35
+ Clip.process(path, options)
36
36
  end
37
37
  end
38
38
 
39
39
  # Download the video source
40
40
  # @param [Hash] options
41
+ # @option options [String, File] :download_path Path where download should be stored (default: system temp directory)
42
+ # @option options [String] :flags Flags to pass to youtube-dl
41
43
  # @return [Download]
42
44
  def process_download(options = {})
43
45
  @download = Download.process(self, options)
44
46
  end
45
47
 
46
- # The downloaded source filenames
47
- # @return [Array<String>]
48
- def source_filenames
48
+ # The downloaded files to work from
49
+ # @return [Array<String>, Array<File>]
50
+ def download_paths
49
51
  if @download.nil?
50
52
  raise "File must be downloaded"
51
53
  else
52
- @source_filenames = Dir["#{Download::TEMPDIR}/#{@id}*"]
54
+ @download.paths
53
55
  end
54
56
  end
55
57
 
@@ -3,7 +3,7 @@ require "helper"
3
3
  describe Viddl::Video::Clip do
4
4
 
5
5
  before(:each) do
6
- @source_file = "#{Viddl::Video::Download::TEMPDIR}/6g4dkBF5anU.mkv"
6
+ @source_file = "#{Viddl::Video::Download::DEFAULT_TEMPDIR}/6g4dkBF5anU.mkv"
7
7
  @clip = Viddl::Video::Clip.new(@source_file)
8
8
  end
9
9
 
@@ -25,16 +25,37 @@ describe Viddl::Video::Download do
25
25
 
26
26
  context "#command_line" do
27
27
 
28
- before(:each) do
29
- @result = @download.send(:command_line)
30
- end
28
+ context "with no download_path specified" do
29
+
30
+ before(:each) do
31
+ @result = @download.send(:command_line)
32
+ end
33
+
34
+ it "includes url" do
35
+ expect(@result).to(include(@source_url))
36
+ end
37
+
38
+ it "includes temp dir" do
39
+ expect(@result).to(include("#{Viddl::Video::Download::DEFAULT_TEMPDIR}/"))
40
+ end
31
41
 
32
- it "includes url" do
33
- expect(@result).to(include(@source_url))
34
42
  end
35
43
 
36
- it "includes temp dir" do
37
- expect(@result).to(include("#{Viddl::Video::Download::TEMPDIR}/"))
44
+ context "with download_path specified" do
45
+
46
+ before(:each) do
47
+ @path = "assets"
48
+ @result = @download.send(:command_line, download_path: "assets")
49
+ end
50
+
51
+ it "includes url" do
52
+ expect(@result).to(include(@source_url))
53
+ end
54
+
55
+ it "includes download_path" do
56
+ expect(@result).to(include(@path))
57
+ end
58
+
38
59
  end
39
60
 
40
61
  end
@@ -17,14 +17,14 @@ describe Viddl::Video::Instance do
17
17
 
18
18
  end
19
19
 
20
- context "#source_filenames" do
20
+ context "#download_paths" do
21
21
 
22
22
  context "with associated download" do
23
23
 
24
- it "pulls filenames from directory" do
24
+ it "delegates to download" do
25
25
  @download = Viddl::Video::Download.new(@video)
26
- expect(Dir).to(receive(:[]))
27
- @result = @video.source_filenames
26
+ expect(@download).to(receive(:paths))
27
+ @result = @video.download_paths
28
28
  end
29
29
 
30
30
  end
@@ -33,7 +33,7 @@ describe Viddl::Video::Instance do
33
33
 
34
34
  it "raises" do
35
35
  expect {
36
- @video.source_filenames
36
+ @video.download_paths
37
37
  }.to(raise_error(RuntimeError))
38
38
  end
39
39
 
@@ -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(["#{Viddl::Video::Download::TEMPDIR}/#{@video_id}.mkv"]))
48
+ expect(@video).to(receive(:download_paths).and_return(["#{Viddl::Video::Download::DEFAULT_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.12
4
+ version: 0.0.13
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-19 00:00:00.000000000 Z
11
+ date: 2017-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake