youtube-dl.rb 0.3.0.2016.06.16 → 0.3.1.2016.06.16

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: 74be0f96111b3354e98fb70ee2ea266f1979164f
4
- data.tar.gz: 16847ea04ae98a7c93ecf6618026f1ef70d82412
3
+ metadata.gz: 48ee28869c55458c861f8a280af1fc4ab86dad21
4
+ data.tar.gz: b04682f8a13d5fa865a92ecc7c20409d311fc0cf
5
5
  SHA512:
6
- metadata.gz: a0532e24ebff562b0daea48b9380fb8b751602bba23f37449704b850c0e2a59cb186471c6526f2739e17268255f9d0231c15188c85c00804f92e50d2107fa71c
7
- data.tar.gz: 1baee97d5b6bcd2ac2af90dedc77b7cfecc54b4a94d451c52fcf91f71c50cee3b8526a104bbbf62c9eae37a61edf08da14f090aab91aa42a2403f2745d929708
6
+ metadata.gz: 06b8a17a9269a9691a5c408dc64a827ca100f3a04e98702c3aea6df39e175909312ad448332615836a707c8f38c8b5cea20e898a45295547ea76c42a593402b9
7
+ data.tar.gz: 0d0ac754552c1eba401ee68c220c8a9b6fe8b337c15de208b98d27737d379f52d7c3355764fe09426a322f62806c8296cc33d171ef23b08aff53fa6d357af3c1
data/.travis.yml CHANGED
@@ -2,14 +2,16 @@ before_install:
2
2
  - sudo chmod 755 ./vendor/bin/youtube-dl
3
3
  - sudo apt-get update -qq
4
4
 
5
+ bundler_args: --without extras
6
+
5
7
  rvm:
6
8
  - 2.0.0 # Too old stable
7
- - 2.1.8 # Old stable
8
- - 2.2.4 # Previous Stable
9
- - 2.3.0 # Current stable
9
+ - 2.1.9 # Old stable
10
+ - 2.2.5 # Previous Stable
11
+ - 2.3.1 # Current stable
10
12
  - ruby-head # MRI head
11
13
  - jruby # JRuby RVM default
12
- - jruby-9.0.4.0 # JRuby 9k series
14
+ - jruby-9.1.2.0 # JRuby 9k series
13
15
  - jruby-head # JRuby Head
14
16
  - rbx-2 # Rubinius stable
15
17
 
@@ -19,6 +21,7 @@ matrix:
19
21
  allow_failures:
20
22
  - rvm: jruby
21
23
  - rvm: jruby-head
24
+ - rvm: ruby-head
22
25
 
23
26
  notifications:
24
27
  slack: layer8x:cvixULdjCINfq7u9Zs1rS0VY
data/Gemfile CHANGED
@@ -2,3 +2,9 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in youtube-dl.rb.gemspec
4
4
  gemspec
5
+
6
+ group :extras do
7
+ gem 'pry'
8
+ gem 'pry-byebug'
9
+ gem 'm'
10
+ end
data/README.md CHANGED
@@ -9,6 +9,7 @@ Ruby wrapper for [youtube-dl](http://rg3.github.io/youtube-dl/).
9
9
  [![Inline docs](http://inch-ci.org/github/layer8x/youtube-dl.rb.svg?branch=master)](http://inch-ci.org/github/layer8x/youtube-dl.rb)
10
10
  [![Dependency Status](https://gemnasium.com/layer8x/youtube-dl.rb.svg)](https://gemnasium.com/layer8x/youtube-dl.rb)
11
11
 
12
+ [![Build history for master branch](https://buildstats.info/travisci/chart/layer8x/youtube-dl.rb?branch=master&buildCount=50)](https://travis-ci.org/layer8x/youtube-dl.rb/builds)
12
13
  [![Stories in Ready](https://badge.waffle.io/layer8x/youtube-dl.rb.svg?label=ready&title=Ready)](http://waffle.io/layer8x/youtube-dl.rb)
13
14
 
14
15
 
@@ -4,6 +4,9 @@ module YoutubeDL
4
4
  # @return [Hash] key value storage object
5
5
  attr_accessor :store
6
6
 
7
+ # @return [Array] array of keys that won't be saved to the options store
8
+ attr_accessor :banned_keys
9
+
7
10
  # Options initializer
8
11
  #
9
12
  # @param options [Hash] a hash of options
@@ -13,12 +16,15 @@ module YoutubeDL
13
16
  else
14
17
  @store = options.to_h
15
18
  end
19
+
20
+ @banned_keys = []
16
21
  end
17
22
 
18
23
  # Returns options as a hash
19
24
  #
20
25
  # @return [Hash] hash of options
21
26
  def to_hash
27
+ remove_banned
22
28
  @store
23
29
  end
24
30
  alias_method :to_h, :to_hash
@@ -50,6 +56,8 @@ module YoutubeDL
50
56
  # @yield [config] self
51
57
  def configure
52
58
  yield(self) if block_given?
59
+ remove_banned
60
+ self
53
61
  end
54
62
 
55
63
  # Get option with brackets syntax
@@ -57,6 +65,8 @@ module YoutubeDL
57
65
  # @param key [Object] key
58
66
  # @return [Object] value
59
67
  def [](key)
68
+ remove_banned
69
+ return nil if banned? key
60
70
  @store[key.to_sym]
61
71
  end
62
72
 
@@ -66,9 +76,23 @@ module YoutubeDL
66
76
  # @param value [Object] value
67
77
  # @return [Object] whatever Hash#= returns
68
78
  def []=(key, value)
79
+ remove_banned
80
+ return nil if banned? key
69
81
  @store[key.to_sym] = value
70
82
  end
71
83
 
84
+ # Merge options with given hash, removing banned keys, and returning a
85
+ # new instance of Options.
86
+ #
87
+ # @param hash [Hash] Hash to merge options with
88
+ # @return [YoutubeDL::Options] Merged Options instance
89
+ def with(hash)
90
+ merged = Options.new(@store.merge(hash.to_h))
91
+ merged.banned_keys = @banned_keys
92
+ merged.send(:remove_banned)
93
+ merged
94
+ end
95
+
72
96
  # Option getting and setting using ghost methods
73
97
  #
74
98
  # @param method [Symbol] method name
@@ -76,10 +100,13 @@ module YoutubeDL
76
100
  # @param block [Proc] implicit block given
77
101
  # @return [Object] the value of method in the options store
78
102
  def method_missing(method, *args, &_block)
103
+ remove_banned
79
104
  if method.to_s.include? '='
80
105
  method = method.to_s.tr('=', '').to_sym
106
+ return nil if banned? method
81
107
  @store[method] = args.first
82
108
  else
109
+ return nil if banned? method
83
110
  @store[method]
84
111
  end
85
112
  end
@@ -120,7 +147,15 @@ module YoutubeDL
120
147
  safe_copy
121
148
  end
122
149
 
123
- private
150
+ # Check if key is a banned key
151
+ #
152
+ # @param key [Object] key to check
153
+ # @return [Boolean] true if key is banned, false if not.
154
+ def banned?(key)
155
+ @banned_keys.include? key
156
+ end
157
+
158
+ private
124
159
 
125
160
  # Helper function to convert option keys into command-line-friendly parameters
126
161
  #
@@ -129,5 +164,10 @@ module YoutubeDL
129
164
  def paramize(key)
130
165
  key.to_s.tr('_', '-')
131
166
  end
167
+
168
+ # Helper to remove banned keys from store
169
+ def remove_banned
170
+ @store.delete_if { |key, value| banned? key }
171
+ end
132
172
  end
133
173
  end
@@ -1,5 +1,5 @@
1
1
  module YoutubeDL
2
2
  # Semantic Version as well as the bundled binary version.
3
3
  # "(major).(minor).(teeny).(pre-release).(binary-version)"
4
- VERSION = '0.3.0.2016.06.16'
4
+ VERSION = '0.3.1.2016.06.16'.freeze
5
5
  end
@@ -27,7 +27,8 @@ module YoutubeDL
27
27
  # @param options [Hash] Options to populate the everything with
28
28
  def initialize(url, options = {})
29
29
  @url = url
30
- @options = YoutubeDL::Options.new(options)
30
+ @options = YoutubeDL::Options.new(options.merge(default_options))
31
+ @options.banned_keys = banned_keys
31
32
  end
32
33
 
33
34
  # Download the video.
@@ -35,8 +36,7 @@ module YoutubeDL
35
36
  raise ArgumentError.new('url cannot be nil') if @url.nil?
36
37
  raise ArgumentError.new('url cannot be empty') if @url.empty?
37
38
 
38
- @download_options = YoutubeDL::Options.new(runner_options)
39
- set_information_from_json(YoutubeDL::Runner.new(url, @download_options).run)
39
+ set_information_from_json(YoutubeDL::Runner.new(url, runner_options).run)
40
40
  end
41
41
 
42
42
  alias_method :get, :download
@@ -45,7 +45,7 @@ module YoutubeDL
45
45
  #
46
46
  # @return [String] Filename downloaded to
47
47
  def filename
48
- @information._filename
48
+ self._filename
49
49
  end
50
50
 
51
51
  # Metadata information for the video, gotten from --print-json
@@ -62,7 +62,7 @@ module YoutubeDL
62
62
  # @param block [Proc] explict block
63
63
  # @return [Object] The value from @information
64
64
  def method_missing(method, *args, &block)
65
- value = information.send(method, *args, &block)
65
+ value = information[method]
66
66
 
67
67
  if value.nil?
68
68
  super
@@ -74,20 +74,37 @@ module YoutubeDL
74
74
  private
75
75
 
76
76
  # Add in other default options here.
77
- def runner_options
77
+ def default_options
78
78
  {
79
79
  color: false,
80
80
  progress: false,
81
81
  print_json: true
82
- }.merge(@options)
82
+ }
83
+ end
84
+
85
+ def banned_keys
86
+ [
87
+ :get_url,
88
+ :get_title,
89
+ :get_id,
90
+ :get_thumbnail,
91
+ :get_description,
92
+ :get_duration,
93
+ :get_filename,
94
+ :get_format
95
+ ]
96
+ end
97
+
98
+ def runner_options
99
+ YoutubeDL::Options.new(@options.to_h.merge(default_options))
83
100
  end
84
101
 
85
102
  def set_information_from_json(json) # :nodoc:
86
- @information = OpenStruct.new(JSON.parse(json))
103
+ @information = JSON.parse(json, symbolize_names: true)
87
104
  end
88
105
 
89
106
  def grab_information_without_download # :nodoc:
90
- set_information_from_json(YoutubeDL::Runner.new(url, runner_options.merge({skip_download: true})).run)
107
+ set_information_from_json(YoutubeDL::Runner.new(url, runner_options.with({skip_download: true})).run)
91
108
  end
92
109
  end
93
110
  end
@@ -13,16 +13,14 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = 'https://github.com/layer8x/youtube-dl.rb'
14
14
  spec.license = 'MIT'
15
15
 
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ #spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_dependency 'cocaine', '>=0.5.4'
22
22
 
23
23
  spec.add_development_dependency 'bundler', '>= 1.6'
24
- spec.add_development_dependency 'pry'
25
- spec.add_development_dependency 'm'
26
24
  spec.add_development_dependency 'rake', '~> 10.0'
27
25
  spec.add_development_dependency 'minitest', '~> 5.8.1'
28
26
  spec.add_development_dependency 'purdytest'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: youtube-dl.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0.2016.06.16
4
+ version: 0.3.1.2016.06.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - sapslaj
@@ -39,34 +39,6 @@ dependencies:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '1.6'
42
- - !ruby/object:Gem::Dependency
43
- name: pry
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- version: '0'
49
- type: :development
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: '0'
56
- - !ruby/object:Gem::Dependency
57
- name: m
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: '0'
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
42
  - !ruby/object:Gem::Dependency
71
43
  name: rake
72
44
  requirement: !ruby/object:Gem::Requirement
@@ -146,12 +118,6 @@ files:
146
118
  - lib/youtube-dl/support.rb
147
119
  - lib/youtube-dl/version.rb
148
120
  - lib/youtube-dl/video.rb
149
- - test/test_helper.rb
150
- - test/youtube-dl/options_test.rb
151
- - test/youtube-dl/runner_test.rb
152
- - test/youtube-dl/support_test.rb
153
- - test/youtube-dl/video_test.rb
154
- - test/youtube-dl_test.rb
155
121
  - vendor/bin/youtube-dl
156
122
  - vendor/bin/youtube-dl.exe
157
123
  - youtube-dl.rb.gemspec
@@ -179,10 +145,4 @@ rubygems_version: 2.5.1
179
145
  signing_key:
180
146
  specification_version: 4
181
147
  summary: youtube-dl wrapper for Ruby
182
- test_files:
183
- - test/test_helper.rb
184
- - test/youtube-dl/options_test.rb
185
- - test/youtube-dl/runner_test.rb
186
- - test/youtube-dl/support_test.rb
187
- - test/youtube-dl/video_test.rb
188
- - test/youtube-dl_test.rb
148
+ test_files: []
data/test/test_helper.rb DELETED
@@ -1,36 +0,0 @@
1
- if RUBY_PLATFORM == "java"
2
- require 'simplecov'
3
- SimpleCov.start
4
- else
5
- require "codeclimate-test-reporter"
6
- CodeClimate::TestReporter.start
7
- end
8
-
9
- $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
10
-
11
- gem 'minitest'
12
- require 'minitest/autorun'
13
- require 'minitest/spec'
14
- require 'purdytest' # minitest-colorize is broken in minitest version 5
15
- require 'pry'
16
- require 'fileutils'
17
- require 'yaml'
18
-
19
- require 'youtube-dl'
20
-
21
- TEST_ID = "gvdf5n-zI14"
22
- TEST_URL = "https://www.youtube.com/watch?feature=endscreen&v=gvdf5n-zI14"
23
- TEST_URL2 = "https://www.youtube.com/watch?v=Mt0PUjh-nDM"
24
- TEST_FILENAME = "nope.avi.mp4"
25
- TEST_FORMAT = "5"
26
- TEST_GLOB = "nope*"
27
-
28
- def remove_downloaded_files
29
- Dir.glob("**/*nope*").each do |nope|
30
- File.delete(nope)
31
- end
32
- end
33
-
34
- def travis_ci?
35
- !!ENV['TRAVIS']
36
- end
@@ -1,145 +0,0 @@
1
- require_relative '../test_helper'
2
-
3
- describe YoutubeDL::Options do
4
- before do
5
- @options = YoutubeDL::Options.new
6
- end
7
-
8
- describe '#initialize' do
9
- it 'should symbolize option keys' do
10
- @options.store['key'] = "value"
11
- @options.sanitize_keys!
12
- assert_equal({key: 'value'}, @options.store)
13
- end
14
-
15
- it 'should accept a parent Options as a param' do
16
- parent = YoutubeDL::Options.new(parent_key: 'parent value')
17
- child = YoutubeDL::Options.new(parent)
18
- assert_equal parent.store, child.store
19
- end
20
-
21
- it 'should accept a Hash as a param' do
22
- hash = {parent_key: 'parent value'}
23
- options = YoutubeDL::Options.new(hash)
24
- assert_equal hash, options.store
25
- end
26
- end
27
-
28
- describe '#to_hash, #to_h' do
29
- before do
30
- @options.store[:key] = "value"
31
- end
32
-
33
- it 'should return a hash' do
34
- assert_instance_of Hash, @options.to_hash
35
- end
36
-
37
- it 'should be equal to store' do
38
- assert_equal @options.store, @options.to_hash
39
- end
40
- end
41
-
42
- describe '#each_paramized' do
43
- it 'should properly paramize keys and not values' do
44
- @options.some_key = "some value"
45
-
46
- @options.each_paramized do |key, value|
47
- assert_equal key, 'some-key'
48
- assert_equal value, 'some value'
49
- end
50
- end
51
- end
52
-
53
- describe '#each_paramized_key' do
54
- it 'should properly paramize keys' do # TODO: Write a better test name
55
- @options.some_key = "some value"
56
-
57
- @options.each_paramized_key do |key, paramized_key|
58
- assert_equal :some_key, key
59
- assert_equal 'some-key', paramized_key
60
- end
61
- end
62
- end
63
-
64
- describe '#configure' do
65
- it 'should be able to use an explicit configuration block' do
66
- @options.configure do |c|
67
- c.get_operator = true
68
- c['get_index'] = true
69
- end
70
-
71
- assert @options.store[:get_operator], "Actual: #{@options.store[:get_operator]}"
72
- assert @options.store[:get_index], "Actual: #{@options.store[:get_index]}"
73
- end
74
-
75
- it 'should not override parent configuration' do
76
- opts = YoutubeDL::Options.new(parent: 'value')
77
- opts.configure do |c|
78
- c.child = 'vlaue'
79
- end
80
-
81
- assert_equal opts.store[:parent], 'value'
82
- assert_equal opts.store[:child], 'vlaue'
83
- end
84
- end
85
-
86
- describe '#[], #[]==' do
87
- it 'should be able to use brackets' do
88
- @options[:mtn] = :dew
89
- assert @options[:mtn] == :dew
90
- end
91
-
92
- it 'should automatically symbolize keys' do
93
- @options.get_operator = true
94
- @options['get_index'] = true
95
-
96
- [:get_operator, :get_index].each do |d|
97
- assert @options.store.keys.include?(d), "keys not symbolizing automatically: #{d}"
98
- end
99
- end
100
- end
101
-
102
- describe '#method_missing' do
103
- it 'should be able to set options with method_missing' do
104
- @options.test = true
105
-
106
- assert @options.store[:test]
107
- end
108
-
109
- it 'should be able to retrieve options with method_missing' do
110
- @options.store[:walrus] = 'haswalrus'
111
-
112
- assert @options.walrus == 'haswalrus'
113
- end
114
- end
115
-
116
- describe '#manipulate_keys!' do
117
- it 'should manipulate keys' do
118
- @options.some_key = 'value'
119
- @options.manipulate_keys! do |key|
120
- key.to_s.upcase
121
- end
122
- assert_equal({'SOME_KEY' => 'value'}, @options.store)
123
- end
124
- end
125
-
126
- describe '#sanitize_keys!' do
127
- it 'should convert hyphens to underscores in keys' do # See issue #9
128
- @options.store[:"hyphenated-key"] = 'value'
129
- @options.sanitize_keys!
130
- assert_equal({hyphenated_key: 'value'}, @options.to_h)
131
- end
132
- end
133
-
134
- describe '#sanitize_keys' do
135
- it 'should not modify the original by calling sanitize_keys without bang' do
136
- @options.store['some-key'] = "some_value"
137
- refute_equal @options.sanitize_keys, @options
138
- end
139
-
140
- it 'should return instance of Options when calling sanitize_keys' do
141
- @options.store['some-key'] = "some_value"
142
- assert_instance_of YoutubeDL::Options, @options.sanitize_keys
143
- end
144
- end
145
- end
@@ -1,86 +0,0 @@
1
- require_relative '../test_helper'
2
-
3
- describe YoutubeDL::Runner do
4
- before do
5
- @runner = YoutubeDL::Runner.new(TEST_URL)
6
- end
7
-
8
- after do
9
- remove_downloaded_files
10
- end
11
-
12
- describe '#initialize' do
13
- it 'should take options as a hash yet still have configuration blocks work' do
14
- r = YoutubeDL::Runner.new(TEST_URL, {some_key: 'some value'})
15
- r.options.configure do |c|
16
- c.another_key = 'another_value'
17
- end
18
-
19
- assert_includes r.to_command, "--some-key"
20
- assert_includes r.to_command, "--another-key"
21
- end
22
- end
23
-
24
- describe '#executable_path' do
25
- it 'should set executable path automatically' do
26
- assert_match 'youtube-dl', @runner.executable_path
27
- end
28
-
29
- it 'should not have a newline char in the executable_path' do
30
- assert_match(/youtube-dl\z/, @runner.executable_path)
31
- end
32
- end
33
-
34
- describe '#backend_runner=, #backend_runner' do
35
- it 'should set cocaine runner' do
36
- @runner.backend_runner = Cocaine::CommandLine::BackticksRunner.new
37
- assert_instance_of Cocaine::CommandLine::BackticksRunner, @runner.backend_runner
38
-
39
- @runner.backend_runner = Cocaine::CommandLine::PopenRunner.new
40
- assert_instance_of Cocaine::CommandLine::PopenRunner, @runner.backend_runner
41
- end
42
- end
43
-
44
- describe '#to_command' do
45
- it 'should parse key-values from options' do
46
- @runner.options.some_key = "a value"
47
-
48
- refute_nil @runner.to_command.match(/--some-key\s.*a value.*/)
49
- end
50
-
51
- it 'should handle true boolean values' do
52
- @runner.options.truthy_value = true
53
-
54
- assert_match(/youtube-dl .*--truthy-value\s--|\"http.*/, @runner.to_command)
55
- end
56
-
57
- it 'should handle false boolean values' do
58
- @runner.options.false_value = false
59
-
60
- assert_match(/youtube-dl .*--no-false-value\s--|\"http.*/, @runner.to_command)
61
- end
62
-
63
- it 'should not have newline char in to_command' do
64
- assert_match(/youtube-dl\s/, @runner.to_command)
65
- end
66
- end
67
-
68
- describe '#run' do
69
- it 'should run commands' do
70
- @runner.options.output = TEST_FILENAME
71
- @runner.options.format = TEST_FORMAT
72
- @runner.run
73
- assert File.exists? TEST_FILENAME
74
- end
75
- end
76
-
77
- describe '#configure' do
78
- it 'should update configuration options' do
79
- @runner.configure do |c|
80
- c.output = TEST_FILENAME
81
- end
82
-
83
- assert_equal TEST_FILENAME, @runner.options.output
84
- end
85
- end
86
- end
@@ -1,64 +0,0 @@
1
- require_relative '../test_helper'
2
-
3
- TestKlass = Class.new do
4
- include YoutubeDL::Support
5
-
6
- def executable_path
7
- usable_executable_path_for 'youtube-dl'
8
- end
9
- end
10
-
11
- describe YoutubeDL::Support do
12
- before do
13
- @klass = TestKlass.new
14
- end
15
-
16
- describe '#usable_executable_path' do
17
- it 'should detect system executable' do
18
- vendor_bin = File.join(Dir.pwd, 'vendor', 'bin', 'youtube-dl')
19
- Dir.mktmpdir do |tmpdir|
20
- FileUtils.cp vendor_bin, tmpdir
21
-
22
- old_path = ENV["PATH"]
23
- ENV["PATH"] = "#{tmpdir}:#{old_path}"
24
-
25
- usable_path = @klass.usable_executable_path_for('youtube-dl')
26
- assert_match usable_path, "#{tmpdir}/youtube-dl"
27
-
28
- ENV["PATH"] = old_path
29
- end
30
- end
31
-
32
- it 'should not have a newline char in the executable_path' do
33
- assert_match(/youtube-dl\z/, @klass.executable_path)
34
- end
35
- end
36
-
37
- describe '#cocaine_line' do
38
- it 'should return a Cocaine::CommandLine instance' do
39
- assert_instance_of Cocaine::CommandLine, @klass.cocaine_line('')
40
- end
41
-
42
- it 'should be able to override the executable' do
43
- line = @klass.cocaine_line('hello', 'echo')
44
- assert_equal "echo hello", line.command
45
- end
46
-
47
- it 'should default to youtube-dl' do
48
- line = @klass.cocaine_line(@klass.quoted(TEST_URL))
49
- assert_includes line.command, "youtube-dl \"#{TEST_URL}\""
50
- end
51
- end
52
-
53
- describe '#quoted' do
54
- it 'should add quotes' do
55
- assert_equal "\"#{TEST_URL}\"", @klass.quoted(TEST_URL)
56
- end
57
- end
58
-
59
- describe '#which' do
60
- it 'should find a proper executable' do
61
- assert File.exists?(@klass.which('ls'))
62
- end
63
- end
64
- end
@@ -1,136 +0,0 @@
1
- require_relative '../test_helper'
2
-
3
- describe YoutubeDL::Video do
4
- before do
5
- @video = YoutubeDL::Video.new TEST_URL
6
- end
7
-
8
- after do
9
- remove_downloaded_files
10
- end
11
-
12
- describe '.download' do
13
- it 'should download videos without options' do
14
- YoutubeDL::Video.download TEST_URL
15
- assert_equal 1, Dir.glob(TEST_GLOB).length
16
- end
17
-
18
- it 'should download videos with options' do
19
- YoutubeDL::Video.download TEST_URL, output: TEST_FILENAME, format: TEST_FORMAT
20
- assert File.exist? TEST_FILENAME
21
- end
22
-
23
- it 'should return an instance of YoutubeDL::Video' do
24
- video = YoutubeDL::Video.download TEST_URL
25
- assert_instance_of YoutubeDL::Video, video
26
- end
27
- end
28
-
29
- describe '.get' do
30
- it 'should download videos, exactly like .download' do
31
- YoutubeDL::Video.get TEST_URL
32
- assert_equal Dir.glob(TEST_GLOB).length, 1
33
- end
34
- end
35
-
36
- describe '#initialize' do
37
- it 'should return an instance of YoutubeDL::Video' do
38
- assert_instance_of YoutubeDL::Video, @video
39
- end
40
-
41
- it 'should not download anything' do
42
- assert_empty Dir.glob(TEST_GLOB)
43
- end
44
- end
45
-
46
- describe '#download' do
47
- it 'should download the file' do
48
- assert_equal 0, Dir.glob(TEST_GLOB).length
49
- @video.download
50
- assert_equal 1, Dir.glob(TEST_GLOB).length
51
- end
52
-
53
- it 'should set model variables accordingly' do
54
- @video.download
55
- assert_equal Dir.glob(TEST_GLOB).first, @video.filename
56
- end
57
-
58
- it 'should raise ArgumentError if url is nil or empty' do
59
- assert_raises ArgumentError do
60
- YoutubeDL::Video.new(nil).download
61
- end
62
-
63
- assert_raises ArgumentError do
64
- YoutubeDL::Video.new('').download
65
- end
66
- end
67
- end
68
-
69
- describe '#filename' do
70
- before do
71
- @video.options.configure do |c|
72
- c.output = TEST_FILENAME
73
- end
74
- end
75
-
76
- it 'should be able to get the filename from the output' do
77
- @video.download
78
- assert_equal TEST_FILENAME, @video.filename
79
- end
80
-
81
- it 'should be able to be predicted' do
82
- predicted_filename = @video.information[:_filename]
83
- @video.download
84
- assert_equal predicted_filename, @video.filename
85
- end
86
-
87
- it 'should not return previously predicted filename' do
88
- predicted_filename = @video.information[:_filename]
89
- @video.configure do |c|
90
- c.output = "#{TEST_FILENAME}.2"
91
- end
92
- @video.download
93
- refute_equal @video.filename, predicted_filename
94
- end
95
-
96
- # Broken on Travis. Output test should be fine.
97
- # it 'should give the correct filename when run through ffmpeg' do
98
- # skip if travis_ci?
99
- # @video.configure do |c|
100
- # c.output = 'nope-%(id)s.%(ext)s'
101
- # c.extract_audio = true
102
- # c.audio_format = 'mp3'
103
- # end
104
- # @video.download
105
- # assert_equal "nope-#{TEST_ID}.mp3", @video.filename
106
- # end
107
- end
108
-
109
- describe '#information' do
110
- before do
111
- @information = @video.information
112
- end
113
-
114
- it 'should be an OpenStruct' do
115
- assert_instance_of OpenStruct, @information
116
- end
117
- end
118
-
119
- describe '#method_missing' do
120
- it 'should pull values from @information' do
121
- assert_equal 'youtube', @video.information[:extractor] # Sanity Check
122
- assert_equal 'youtube', @video.extractor
123
- end
124
-
125
- it 'should return correct formats for things' do
126
- assert_instance_of Array, @video.formats
127
- assert_instance_of Hash, @video.subtitles
128
- end
129
-
130
- it 'should fail if a method does not exist' do
131
- assert_raises NoMethodError do
132
- @video.i_dont_exist
133
- end
134
- end
135
- end
136
- end
@@ -1,84 +0,0 @@
1
- require_relative './test_helper'
2
-
3
- describe YoutubeDL do
4
- describe '.download' do
5
- after do
6
- remove_downloaded_files
7
- end
8
-
9
- it 'should download videos without options' do
10
- YoutubeDL.download TEST_URL
11
- assert_equal 1, Dir.glob(TEST_GLOB).length
12
- end
13
-
14
- it 'should download videos with options' do
15
- YoutubeDL.download TEST_URL, output: TEST_FILENAME, format: TEST_FORMAT
16
- assert File.exist? TEST_FILENAME
17
- end
18
-
19
- it 'should download multiple videos without options' do
20
- YoutubeDL.download [TEST_URL, TEST_URL2]
21
- assert_equal 2, Dir.glob(TEST_GLOB).length
22
- end
23
-
24
- it 'should download multiple videos with options' do
25
- YoutubeDL.download [TEST_URL, TEST_URL2], output: 'test_%(title)s-%(id)s.%(ext)s'
26
- assert_equal 2, Dir.glob('test_' + TEST_GLOB).length
27
- end
28
- end
29
-
30
- describe '.get' do
31
- after do
32
- remove_downloaded_files
33
- end
34
-
35
- it 'should download videos, exactly like .download' do
36
- YoutubeDL.get TEST_URL
37
- assert_equal Dir.glob(TEST_GLOB).length, 1
38
- end
39
- end
40
-
41
- describe '.extractors' do
42
- before do
43
- @extractors = YoutubeDL.extractors
44
- end
45
-
46
- it 'should return an Array' do
47
- assert_instance_of Array, @extractors
48
- end
49
-
50
- it 'should include the youtube extractors' do
51
- ['youtube', 'youtube:channel', 'youtube:search', 'youtube:show', 'youtube:user', 'youtube:playlist'].each do |e|
52
- assert_includes @extractors, e
53
- end
54
- end
55
- end
56
-
57
- describe '.binary_version' do
58
- before do
59
- @version = YoutubeDL.binary_version
60
- end
61
-
62
- it 'should return a string' do
63
- assert_instance_of String, @version
64
- end
65
-
66
- it 'should be a specific format with no newlines' do
67
- assert_match /\d+.\d+.\d+\z/, @version
68
- end
69
- end
70
-
71
- describe '.user_agent' do
72
- before do
73
- @user_agent = YoutubeDL.user_agent
74
- end
75
-
76
- it 'should return a string' do
77
- assert_instance_of String, @user_agent
78
- end
79
-
80
- it 'should be a specific format with no newlines' do
81
- assert_match /Mozilla\/5\.0\s.*\)\z/, @user_agent
82
- end
83
- end
84
- end