youtube-dl.rb 0.2.2.2015.10.16 → 0.2.3.2015.10.24

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: 3086452fd3e50b0fd72e0df944c69f071dfe240f
4
- data.tar.gz: 8c0e663fd1310dbe0b9c2c277f77a9ed4c2e3fad
3
+ metadata.gz: f84b679cf5fdaf07df79d63a0bea60581437e7f6
4
+ data.tar.gz: d47c54582881bdbda2c16b2fc5791a6c1b5a4d48
5
5
  SHA512:
6
- metadata.gz: b3cc0018c4d67f375da27d78b584cea026a75fd6b08651258abf207a672dd9e0559dc17e22e7cfe0b5a615b35dbbadfe1427b5fd322c2ae091e7cefecd7b9578
7
- data.tar.gz: f83bc8820db4d65070b0673f763ded3d72b62260e9b431ec9c4f5061954553d37b7b52e5f22fe6cd35bc7999180079c6a02ed0d6daad0e1ea310b5313d768fc5
6
+ metadata.gz: 793a6beeb1db594fb23557188bd285420463c4b56d7117e10361209e2f2860ab961e59dd4d3aec569dbba6bee220c70cba10fb57e2471f71ace2b222de68b2f4
7
+ data.tar.gz: 3a1e7c289112aee97560df754618bbb1c08811c95557f6f9bb83eca52b0fa1232435fe0f1ad7f2d115c75182c7c962b79dabc902841a810b26738fa279006f29
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ Metrics/LineLength:
2
+ Max: 200
3
+
4
+ Metrics/AbcSize:
5
+ Max: 22
6
+
7
+ Metrics/MethodLength:
8
+ Max: 14
9
+
10
+ Style/ModuleFunction:
11
+ Enabled: false
12
+
13
+ Style/FileName:
14
+ Enabled: false
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,135 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2015-10-19 08:34:35 -0400 using RuboCop version 0.34.2.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 7
10
+ Lint/AmbiguousRegexpLiteral:
11
+ Exclude:
12
+ - 'test/youtube-dl/runner_test.rb'
13
+ - 'test/youtube-dl/support_test.rb'
14
+ - 'test/youtube-dl_test.rb'
15
+
16
+ # Offense count: 1
17
+ Lint/Debugger:
18
+ Exclude:
19
+ - 'tmp/parse_formats.rb'
20
+
21
+ # Offense count: 2
22
+ # Cop supports --auto-correct.
23
+ Lint/DeprecatedClassMethods:
24
+ Exclude:
25
+ - 'test/youtube-dl/runner_test.rb'
26
+ - 'test/youtube-dl/support_test.rb'
27
+
28
+ # Offense count: 3
29
+ Metrics/AbcSize:
30
+ Max: 22
31
+
32
+ # Offense count: 3
33
+ # Configuration parameters: CountComments.
34
+ Metrics/MethodLength:
35
+ Max: 14
36
+
37
+ # Offense count: 2
38
+ # Cop supports --auto-correct.
39
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
40
+ Style/AccessModifierIndentation:
41
+ Enabled: false
42
+
43
+ # Offense count: 1
44
+ # Cop supports --auto-correct.
45
+ # Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
46
+ Style/BlockDelimiters:
47
+ Enabled: false
48
+
49
+ # Offense count: 2
50
+ # Cop supports --auto-correct.
51
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
52
+ Style/BracesAroundHashParameters:
53
+ Exclude:
54
+ - 'test/youtube-dl/output_test.rb'
55
+ - 'test/youtube-dl/runner_test.rb'
56
+
57
+ # Offense count: 1
58
+ # Configuration parameters: Exclude.
59
+ Style/Documentation:
60
+ Exclude:
61
+ - 'lib/youtube-dl/version.rb'
62
+
63
+ # Offense count: 1
64
+ # Cop supports --auto-correct.
65
+ Style/EmptyLinesAroundAccessModifier:
66
+ Exclude:
67
+ - 'lib/youtube-dl/video.rb'
68
+
69
+ # Offense count: 1
70
+ # Cop supports --auto-correct.
71
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
72
+ Style/EmptyLinesAroundClassBody:
73
+ Exclude:
74
+ - 'lib/youtube-dl/output.rb'
75
+
76
+ # Offense count: 5
77
+ # Cop supports --auto-correct.
78
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
79
+ Style/EmptyLinesAroundModuleBody:
80
+ Exclude:
81
+ - 'lib/youtube-dl/output.rb'
82
+ - 'lib/youtube-dl/runner.rb'
83
+ - 'lib/youtube-dl/support.rb'
84
+ - 'lib/youtube-dl/video.rb'
85
+
86
+ # Offense count: 2
87
+ # Configuration parameters: Exclude.
88
+ Style/FileName:
89
+ Exclude:
90
+ - 'lib/youtube-dl.rb'
91
+ - 'test/youtube-dl_test.rb'
92
+
93
+ # Offense count: 1
94
+ Style/ModuleFunction:
95
+ Exclude:
96
+ - 'lib/youtube-dl.rb'
97
+
98
+ # Offense count: 1
99
+ # Cop supports --auto-correct.
100
+ # Configuration parameters: AllowMultipleReturnValues.
101
+ Style/RedundantReturn:
102
+ Exclude:
103
+ - 'lib/youtube-dl/support.rb'
104
+
105
+ # Offense count: 1
106
+ # Cop supports --auto-correct.
107
+ # Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
108
+ Style/RegexpLiteral:
109
+ Exclude:
110
+ - 'test/youtube-dl_test.rb'
111
+
112
+ # Offense count: 3
113
+ # Cop supports --auto-correct.
114
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
115
+ Style/SpaceAroundEqualsInParameterDefault:
116
+ Enabled: false
117
+
118
+ # Offense count: 12
119
+ # Cop supports --auto-correct.
120
+ # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles.
121
+ Style/SpaceInsideHashLiteralBraces:
122
+ Enabled: false
123
+
124
+ # Offense count: 2
125
+ # Cop supports --auto-correct.
126
+ Style/SpecialGlobalVars:
127
+ Exclude:
128
+ - 'test/test_helper.rb'
129
+ - 'tmp/parse_formats.rb'
130
+
131
+ # Offense count: 22
132
+ # Cop supports --auto-correct.
133
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
134
+ Style/StringLiterals:
135
+ Enabled: false
data/Rakefile CHANGED
@@ -1,27 +1,27 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
2
  require 'rake/testtask'
3
3
 
4
4
  Rake::TestTask.new do |t|
5
- t.pattern = "test/**/*_test.rb"
5
+ t.pattern = 'test/**/*_test.rb'
6
6
  end
7
7
 
8
- task :default => [:test]
8
+ task default: [:test]
9
9
 
10
10
  namespace :binaries do
11
11
  def get_binaries(version)
12
- puts "Updating python script"
12
+ puts 'Updating python script'
13
13
  system("wget -O ./vendor/bin/youtube-dl https://yt-dl.org/downloads/#{version}/youtube-dl")
14
- puts "Updating Windows EXE"
14
+ puts 'Updating Windows EXE'
15
15
  system("wget -O ./vendor/bin/youtube-dl.exe https://yt-dl.org/downloads/#{version}/youtube-dl.exe")
16
16
  end
17
17
 
18
- desc "Get latest binaries"
18
+ desc 'Get latest binaries'
19
19
  task :latest do
20
20
  get_binaries('latest')
21
21
  end
22
22
 
23
- desc "Get binaries for specific version (run with `rake binaries:version[2015.07.07]`)"
24
- task :version, [:ver] do |t, a|
23
+ desc 'Get binaries for specific version (run with `rake binaries:version[2015.07.07]`)'
24
+ task :version, [:ver] do |_t, a|
25
25
  get_binaries(a[:ver])
26
26
  end
27
27
  end
data/lib/youtube-dl.rb CHANGED
@@ -16,7 +16,8 @@ module YoutubeDL
16
16
  #
17
17
  # @param urls [String, Array] URLs to download
18
18
  # @param options [Hash] Downloader options
19
- def download(urls, options={})
19
+ # @return [YoutubeDL::Video, Array] Video model or array of Video models
20
+ def download(urls, options = {})
20
21
  if urls.is_a? Array
21
22
  urls.map { |url| YoutubeDL::Video.get(url, options) }
22
23
  else
@@ -1,15 +1,13 @@
1
1
  module YoutubeDL
2
-
3
2
  # Option and configuration getting, setting, and storage, and all that
4
3
  class Options
5
-
6
- # [Hash] key value storage object
4
+ # @return [Hash] key value storage object
7
5
  attr_accessor :store
8
6
 
9
7
  # Options initializer
10
8
  #
11
9
  # @param options [Hash] a hash of options
12
- def initialize(options={})
10
+ def initialize(options = {})
13
11
  if options.is_a? Hash
14
12
  @store = options
15
13
  else
@@ -28,6 +26,7 @@ module YoutubeDL
28
26
  # Iterate through the paramized keys and values.
29
27
  #
30
28
  # @yield [paramized_key, value]
29
+ # @return [Object] @store
31
30
  #
32
31
  # TODO: Enumerable?
33
32
  def each_paramized
@@ -39,6 +38,7 @@ module YoutubeDL
39
38
  # Iterate through the keys and their paramized counterparts.
40
39
  #
41
40
  # @yield [key, paramized_key]
41
+ # @return [Object] @store
42
42
  def each_paramized_key
43
43
  @store.each_key do |key|
44
44
  yield(key, paramize(key))
@@ -64,6 +64,7 @@ module YoutubeDL
64
64
  #
65
65
  # @param key [Object] key
66
66
  # @param value [Object] value
67
+ # @return [Object] whatever Hash#= returns
67
68
  def []=(key, value)
68
69
  @store[key.to_sym] = value
69
70
  end
@@ -74,7 +75,7 @@ module YoutubeDL
74
75
  # @param args [Array] list of arguments passed
75
76
  # @param block [Proc] implicit block given
76
77
  # @return [Object] the value of method in the options store
77
- def method_missing(method, *args, &block)
78
+ def method_missing(method, *args, &_block)
78
79
  if method.to_s.include? '='
79
80
  method = method.to_s.tr('=', '').to_sym
80
81
  @store[method] = args.first
@@ -100,6 +101,8 @@ module YoutubeDL
100
101
  end
101
102
 
102
103
  # Symbolizes and sanitizes keys in the option store
104
+ #
105
+ # @return [Object] @store
103
106
  def sanitize_keys!
104
107
  # Symbolize
105
108
  manipulate_keys! { |key_name| key_name.is_a?(Symbol) ? key_name : key_name.to_sym }
@@ -112,18 +115,19 @@ module YoutubeDL
112
115
  #
113
116
  # @return [YoutubeDL::Options] Options with sanitized keys.
114
117
  def sanitize_keys
115
- safe_copy = self.dup
118
+ safe_copy = dup
116
119
  safe_copy.sanitize_keys!
117
120
  safe_copy
118
121
  end
119
122
 
120
123
  private
124
+
121
125
  # Helper function to convert option keys into command-line-friendly parameters
122
126
  #
123
127
  # @param key [Symbol, String] key to paramize
124
128
  # @return [String] paramized key
125
129
  def paramize(key)
126
- key.to_s.tr("_", '-')
130
+ key.to_s.tr('_', '-')
127
131
  end
128
132
  end
129
133
  end
@@ -1,9 +1,7 @@
1
1
  module YoutubeDL
2
-
3
2
  # A class of voodoo methods for parsing youtube-dl output
4
3
  class Output
5
-
6
- # [String] Whatever youtube-dl spat out.
4
+ # @return [String] Whatever youtube-dl spat out.
7
5
  attr_accessor :output
8
6
 
9
7
  # Initialize output parser
@@ -1,19 +1,18 @@
1
1
  module YoutubeDL
2
-
3
2
  # Utility class for running and managing youtube-dl
4
3
  class Runner
5
4
  include YoutubeDL::Support
6
5
 
7
- # [String] URL to download
6
+ # @return [String] URL to download
8
7
  attr_accessor :url
9
8
 
10
- # [YoutubeDL::Options] Options access.
9
+ # @return [YoutubeDL::Options] Options access.
11
10
  attr_accessor :options
12
11
 
13
- # [String] Executable path
12
+ # @return [String] Executable path
14
13
  attr_reader :executable_path
15
14
 
16
- # [String] Executable name to use
15
+ # @return [String] Executable name to use
17
16
  attr_accessor :executable
18
17
 
19
18
  # Command Line runner initializer
@@ -64,7 +63,17 @@ module YoutubeDL
64
63
  end
65
64
  alias_method :download, :run
66
65
 
67
- private
66
+ # Options configuration.
67
+ # Just aliases to options.configure
68
+ #
69
+ # @yield [config] options
70
+ # @param a [Array] arguments to pass to options#configure
71
+ # @param b [Proc] block to pass to options#configure
72
+ def configure(*a, &b)
73
+ options.configure(*a, &b)
74
+ end
75
+
76
+ private
68
77
 
69
78
  # Parses options and converts them to Cocaine's syntax
70
79
  #
@@ -1,8 +1,6 @@
1
1
  module YoutubeDL
2
-
3
2
  # Some support methods and glue logic.
4
3
  module Support
5
-
6
4
  # Returns a usable youtube-dl executable (system or vendor)
7
5
  #
8
6
  # @param exe [String] Executable to search for
@@ -49,12 +47,12 @@ module YoutubeDL
49
47
  def which(cmd)
50
48
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
51
49
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
52
- exts.each { |ext|
50
+ exts.each do |ext|
53
51
  exe = File.join(path, "#{cmd}#{ext}")
54
52
  return exe if File.executable?(exe) && !File.directory?(exe)
55
- }
53
+ end
56
54
  end
57
- return nil
55
+ nil
58
56
  end
59
57
  end
60
58
  end
@@ -1,3 +1,5 @@
1
1
  module YoutubeDL
2
- VERSION = "0.2.2.2015.10.16"
2
+ # Semantic Version as well as the bundled binary version.
3
+ # "(semver)(pre-release)(binary-version)"
4
+ VERSION = '0.2.3.2015.10.24'
3
5
  end
@@ -1,5 +1,4 @@
1
1
  module YoutubeDL
2
-
3
2
  # Video model for using and downloading a single video.
4
3
  class Video < Runner
5
4
  class << self
@@ -11,23 +10,22 @@ module YoutubeDL
11
10
  # @param url [String] URL to use and download
12
11
  # @param options [Hash] Options to pass in
13
12
  # @return [YoutubeDL::Video] new Video model
14
- def download(url, options={})
13
+ def download(url, options = {})
15
14
  video = new(url, options)
16
15
  video.download
17
16
  video
18
17
  end
19
-
20
18
  alias_method :get, :download
21
19
  end
22
20
 
23
- # [YoutubeDL::Options] Download Options for the last download
21
+ # @return [YoutubeDL::Options] Download Options for the last download
24
22
  attr_reader :download_options
25
23
 
26
24
  # Instantiate new model
27
25
  #
28
26
  # @param url [String] URL to initialize with
29
27
  # @param options [Hash] Options to populate the everything with
30
- def initialize(url, options={})
28
+ def initialize(url, options = {})
31
29
  @url = url
32
30
  @options = YoutubeDL::Options.new(options)
33
31
  end
@@ -48,16 +46,20 @@ module YoutubeDL
48
46
  @formats ||= YoutubeDL::Output.new(cocaine_line("--list-formats #{quoted(url)}").run).supported_formats
49
47
  end
50
48
 
49
+ # Parses the last downloaded output for a filename and returns it.
50
+ #
51
51
  # @return [String] Filename downloaded to
52
52
  def filename
53
53
  @filename ||= YoutubeDL::Output.new(@last_download_output).filename
54
54
  end
55
55
 
56
- private
56
+ private
57
+
57
58
  # Add in other default options here.
58
59
  def runner_options
59
60
  {
60
- no_color: true
61
+ color: false,
62
+ progress: false
61
63
  }.merge(@options)
62
64
  end
63
65
  end
@@ -73,4 +73,14 @@ describe YoutubeDL::Runner do
73
73
  assert File.exists? TEST_FILENAME
74
74
  end
75
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
76
86
  end
@@ -66,7 +66,9 @@ describe YoutubeDL::Video do
66
66
  end
67
67
 
68
68
  it 'should be an Array of Hashes' do
69
- assert_instance_of Hash, @formats.first
69
+ @formats.each do |f|
70
+ assert_instance_of Hash, f
71
+ end
70
72
  end
71
73
 
72
74
  it 'should have a hash size of 4' do
@@ -86,4 +88,17 @@ describe YoutubeDL::Video do
86
88
  end
87
89
  end
88
90
  end
91
+
92
+ describe '#filename' do
93
+ before do
94
+ @video.options.configure do |c|
95
+ c.output = TEST_FILENAME
96
+ end
97
+ end
98
+
99
+ it 'should be able to get the filename from the output' do
100
+ @video.download
101
+ assert_equal TEST_FILENAME, @video.filename
102
+ end
103
+ end
89
104
  end
Binary file
Binary file
@@ -4,27 +4,27 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'youtube-dl/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "youtube-dl.rb"
7
+ spec.name = 'youtube-dl.rb'
8
8
  spec.version = YoutubeDL::VERSION
9
- spec.authors = ["sapslaj", "xNightMare"]
10
- spec.email = ["saps.laj@gmail.com"]
11
- spec.summary = %q{youtube-dl wrapper for Ruby}
12
- spec.description = %q{in the spirit of pygments.rb and MiniMagick, youtube-dl.rb is a command line wrapper for the python script youtube-dl}
13
- spec.homepage = "https://github.com/layer8x/youtube-dl.rb"
14
- spec.license = "MIT"
9
+ spec.authors = %w(sapslaj xNightMare)
10
+ spec.email = ['saps.laj@gmail.com']
11
+ spec.summary = 'youtube-dl wrapper for Ruby'
12
+ spec.description = 'in the spirit of pygments.rb and MiniMagick, youtube-dl.rb is a command line wrapper for the python script youtube-dl'
13
+ spec.homepage = 'https://github.com/layer8x/youtube-dl.rb'
14
+ spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
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
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency "cocaine", ">=0.5.4"
21
+ spec.add_dependency 'cocaine', '>=0.5.4'
22
22
 
23
- spec.add_development_dependency "bundler", ">= 1.6"
24
- spec.add_development_dependency "pry"
25
- spec.add_development_dependency "m"
26
- spec.add_development_dependency "rake", "~> 10.0"
27
- spec.add_development_dependency "minitest", "~> 5.8.1"
28
- spec.add_development_dependency "purdytest"
29
- spec.add_development_dependency "codeclimate-test-reporter"
23
+ spec.add_development_dependency 'bundler', '>= 1.6'
24
+ spec.add_development_dependency 'pry'
25
+ spec.add_development_dependency 'm'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'minitest', '~> 5.8.1'
28
+ spec.add_development_dependency 'purdytest'
29
+ spec.add_development_dependency 'codeclimate-test-reporter'
30
30
  end
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.2.2.2015.10.16
4
+ version: 0.2.3.2015.10.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - sapslaj
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-10-17 00:00:00.000000000 Z
12
+ date: 2015-10-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cocaine
@@ -132,6 +132,8 @@ extensions: []
132
132
  extra_rdoc_files: []
133
133
  files:
134
134
  - ".gitignore"
135
+ - ".rubocop.yml"
136
+ - ".rubocop_todo.yml"
135
137
  - ".travis.yml"
136
138
  - Gemfile
137
139
  - LICENSE.txt