youtube-dl.rb 0.0.1 → 0.0.2

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: 9d2e08f28b92fbb5f4648f62a80cb17c6e789880
4
- data.tar.gz: a0156c53d24ff475811e5525f93005a6cb56d138
3
+ metadata.gz: e2f3b80e2f598cbea19cdb6aa760535bd1735ef1
4
+ data.tar.gz: 372eadeb8f68fe3d9bf659ea1d1528b26b028b72
5
5
  SHA512:
6
- metadata.gz: 3f033ca22e27a6f6d9ff3954cf19e2bbf77406185d27a3cc977ad479af360b13065900e1c71e8c23292b4bb75e08fd91e7903c08481c5b1ecb0f4c1b16128b9c
7
- data.tar.gz: fe4bbb6ed28c00d05b0fdd5a1c289b154abebecd2dafa427c323b6bf545f9e09d8da238d1b0a1d772c64c65b78a46d75f4ff70504bc55890366b909d98b1de4b
6
+ metadata.gz: 5bfdb2529020c00c0baa402acabd604e970c82cccd126aefb651ea26b39e89a15ea7d08ade283c1763785f46378fa6cced2ed3a548ea94b60bbc93ccbe8940c1
7
+ data.tar.gz: 4d151900a4a7a2dd3556e01c9f4236820b27b7532a71a1200678dc9e3dfe4603da960c4d4e5b07cdba6c88fce94d99383b76c789f6fa61be8f9d5e5caf1e1acc
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ before_install: 'sudo pip install youtube-dl'
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.5
6
+ - jruby-19mode
7
+ - rbx-2
data/README.md CHANGED
@@ -1,9 +1,10 @@
1
1
  # youtube-dl.rb
2
2
 
3
- Ruby wrapper for youtube-dl
3
+ Ruby wrapper for [youtube-dl](http://rg3.github.io/youtube-dl/).
4
+ [![Build Status](https://travis-ci.org/layer8x/youtube-dl.rb.svg?branch=master)](https://travis-ci.org/layer8x/youtube-dl.rb)
4
5
 
5
6
  ## Installing youtube-dl
6
- This gem does not ship with youtube-dl built in (yet), so you need to install manually.
7
+ This gem does not ship with the `youtube-dl` command-line program (yet!) so you will need to install `youtube-dl` manually. Luckily there are three ways to do it.
7
8
 
8
9
  ### The easy way
9
10
  Use your distro's package manager!
@@ -51,7 +52,7 @@ All options available to youtube-dl can be passed to the options hash
51
52
  options = {
52
53
  username: 'someone',
53
54
  password: 'password1',
54
- rate_limit: '50K'
55
+ rate_limit: '50K',
55
56
  format: :worst
56
57
  }
57
58
 
data/Rakefile CHANGED
@@ -4,3 +4,5 @@ require 'rake/testtask'
4
4
  Rake::TestTask.new do |t|
5
5
  t.pattern = "test/**/*_test.rb"
6
6
  end
7
+
8
+ task :default => [:test]
data/lib/youtube-dl.rb CHANGED
@@ -4,9 +4,19 @@ require 'youtube-dl/runner'
4
4
 
5
5
  module YoutubeDL
6
6
  extend self
7
- def download(url, options={})
8
- runner = YoutubeDL::Runner.new(url, YoutubeDL::Options.new(options))
9
- runner.run
7
+
8
+ # Downloads given array of URLs with any options passed
9
+ #
10
+ # @param urls [String, Array] URLs to download
11
+ # @param options [Hash] Downloader options
12
+ def download(urls, options={})
13
+ # force convert urls to array
14
+ urls = [urls] unless urls.is_a? Array
15
+
16
+ urls.each do |url|
17
+ runner = YoutubeDL::Runner.new(url, YoutubeDL::Options.new(options))
18
+ runner.run
19
+ end
10
20
  end
11
21
 
12
22
  alias_method :get, :download
@@ -2,10 +2,21 @@ module YoutubeDL
2
2
  class Options
3
3
  attr_accessor :store
4
4
 
5
+ # Options initializer
6
+ #
7
+ # @param options [Hash] a hash of options
5
8
  def initialize(options={})
6
9
  @store = options
7
10
  end
8
11
 
12
+ # Returns options as a hash
13
+ #
14
+ # @return [Hash] hash of options
15
+ def to_hash
16
+ @store
17
+ end
18
+ alias_method :to_h, :to_hash
19
+
9
20
  def each_paramized
10
21
  @store.each do |key, value|
11
22
  yield(paramize(key), value)
@@ -18,18 +29,22 @@ module YoutubeDL
18
29
  end
19
30
  end
20
31
 
32
+ # Set options using a block
21
33
  def configure(&block)
22
34
  block.call(self)
23
35
  end
24
36
 
37
+ # Get option with brackets syntax
25
38
  def [](key)
26
39
  @store[key.to_sym]
27
40
  end
28
41
 
42
+ # Set option with brackets syntax
29
43
  def []=(key, value)
30
44
  @store[key.to_sym] = value
31
45
  end
32
46
 
47
+ # Option getting and setting using ghost methods
33
48
  def method_missing(method, *args, &block)
34
49
  if method.to_s.include? '='
35
50
  method = method.to_s.tr('=', '').to_sym
@@ -39,6 +54,7 @@ module YoutubeDL
39
54
  end
40
55
  end
41
56
 
57
+ # Symbolizes keys in the option store
42
58
  def symbolize_keys!
43
59
  @store.keys.each do |key_name|
44
60
  unless key_name.is_a? Symbol
@@ -49,6 +65,10 @@ module YoutubeDL
49
65
  end
50
66
 
51
67
  private
68
+ # Helper function to convert option keys into command-line-friendly parameters
69
+ #
70
+ # @param key [Symbol, String] key to paramize
71
+ # @return [String] paramized key
52
72
  def paramize(key)
53
73
  key.to_s.tr("_", '-')
54
74
  end
@@ -6,29 +6,48 @@ module YoutubeDL
6
6
  attr_accessor :options
7
7
  attr_accessor :executable_path
8
8
 
9
+ # Command Line runner initializer
10
+ #
11
+ # @param url [String] URL to pass to youtube-dl executable
12
+ # @param options [Hash, Options] options to pass to the executable. Automatically converted to Options if it isn't already
9
13
  def initialize(url, options=YoutubeDL::Options.new)
10
14
  @url = url
11
- @options = options
15
+ @options = YoutubeDL::Options.new(options.to_hash)
12
16
  @executable_path = 'youtube-dl'
13
17
  end
14
18
 
19
+ # Returns Cocaine's runner engine
20
+ #
21
+ # @return [CommandLineRunner] backend runner class
15
22
  def backend_runner
16
23
  Cocaine::CommandLine.runner
17
24
  end
18
25
 
26
+ # Sets Cocaine's runner engine
27
+ #
28
+ # @param [CommandLineRunner] backend runner class
19
29
  def backend_runner=(cocaine_runner)
20
30
  Cocaine::CommandLine.runner = cocaine_runner
21
31
  end
22
32
 
33
+ # Returns the command string without running anything
34
+ #
35
+ # @return [String] command line string
23
36
  def to_command
24
37
  cocaine_line(options_to_commands).command(@options.store)
25
38
  end
39
+ alias_method :command, :to_command
26
40
 
41
+ # Runs the command
27
42
  def run
28
43
  cocaine_line(options_to_commands).run(@options.store)
29
44
  end
30
45
 
31
46
  private
47
+
48
+ # Parses options and converts them to Cocaine's syntax
49
+ #
50
+ # @return [String] commands ready to do cocaine
32
51
  def options_to_commands
33
52
  commands = []
34
53
  options.each_paramized_key do |key, paramized_key|
@@ -42,6 +61,10 @@ module YoutubeDL
42
61
  commands.join(' ')
43
62
  end
44
63
 
64
+ # Helper for doing lines of cocaine (initializing, auto executable stuff, etc)
65
+ #
66
+ # @param command [String] command switches to run
67
+ # @return [Cocaine::CommandLine] initialized Cocaine instance
45
68
  def cocaine_line(command)
46
69
  Cocaine::CommandLine.new(@executable_path, command)
47
70
  end
@@ -1,3 +1,3 @@
1
1
  module YoutubeDL
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/test/test_helper.rb CHANGED
@@ -1,3 +1,4 @@
1
+ gem 'minitest'
1
2
  require 'minitest/autorun'
2
3
  require 'minitest/spec'
3
4
  require 'purdytest' # minitest-colorize is broken in minitest version 5
@@ -24,7 +24,7 @@ describe YoutubeDL::Runner do
24
24
  it 'should parse key-values from options' do
25
25
  @runner.options.some_key = "a value"
26
26
 
27
- assert_includes @runner.to_command, "--some-key 'a value'"
27
+ refute_nil @runner.to_command.match(/--some-key\s.*a value.*/)
28
28
  end
29
29
 
30
30
  it 'should not include the value if value is true' do
@@ -38,4 +38,14 @@ describe YoutubeDL::Runner do
38
38
  @runner.run
39
39
  assert File.exists? 'nope.avi'
40
40
  end
41
+
42
+ it 'should take options as a hash yet still have configuration blocks work' do
43
+ r = YoutubeDL::Runner.new(NOPE, {some_key: 'some value'})
44
+ r.options.configure do |c|
45
+ c.another_key = 'another_value'
46
+ end
47
+
48
+ assert_includes r.to_command, "--some-key"
49
+ assert_includes r.to_command, "--another-key"
50
+ end
41
51
  end
@@ -9,4 +9,9 @@ describe YoutubeDL do
9
9
  YoutubeDL.get NOPE, output: 'nope.avi'
10
10
  assert File.exist? 'nope.avi'
11
11
  end
12
+
13
+ it 'should download multiple videos' do
14
+ YoutubeDL.download [NOPE, "https://www.youtube.com/watch?v=Mt0PUjh-nDM"]
15
+ assert_equal Dir.glob('nope*').length, 2
16
+ end
12
17
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["saps.laj@gmail.com"]
11
11
  spec.summary = %q{youtube-dl wrapper for Ruby}
12
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 = ""
13
+ spec.homepage = "https://github.com/layer8x/youtube-dl.rb"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
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.0.1
4
+ version: 0.0.2
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-02-16 00:00:00.000000000 Z
12
+ date: 2015-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cocaine
@@ -104,6 +104,7 @@ extensions: []
104
104
  extra_rdoc_files: []
105
105
  files:
106
106
  - ".gitignore"
107
+ - ".travis.yml"
107
108
  - Gemfile
108
109
  - LICENSE.txt
109
110
  - README.md
@@ -117,7 +118,7 @@ files:
117
118
  - test/youtube-dl/runner_test.rb
118
119
  - test/youtube-dl/youtube-dl_test.rb
119
120
  - youtube-dl.rb.gemspec
120
- homepage: ''
121
+ homepage: https://github.com/layer8x/youtube-dl.rb
121
122
  licenses:
122
123
  - MIT
123
124
  metadata: {}