rb-youtube-dl 0.4.0.2021.12.17
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 +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +61 -0
- data/lib/rb-youtube-dl/options.rb +173 -0
- data/lib/rb-youtube-dl/runner.rb +96 -0
- data/lib/rb-youtube-dl/support.rb +58 -0
- data/lib/rb-youtube-dl/version.rb +10 -0
- data/lib/rb-youtube-dl/video.rb +110 -0
- data/lib/rb-youtube-dl.rb +51 -0
- data/vendor/bin/test +0 -0
- data/vendor/bin/youtube-dl +0 -0
- data/vendor/bin/youtube-dl.exe +0 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6913fa63ff896ab25c4ec4f4c73330aa58e0100440bcc4800dce2b039d8847dc
|
4
|
+
data.tar.gz: a2655038a8e1216712ff031644255bda24b83464721bffa7819fc68c56539a4e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 40ce388df3dc9e473463178483d1f422ae897a1c238c6df1dc90f505e02eeb4e354ae4d9f7e5733d34790850d9f8551125acc85cb10972fc11a679c0882daf37
|
7
|
+
data.tar.gz: f3ce7a79800c269e05f5869aab94e9fe5a40dae3662b19a615427675e0a7cfd4a1907ea5ab51c890ad27e4f0a84d5c65267d6cb9970cd39bb261e462a963668d
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 sapslaj
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# RbYoutubeDL
|
2
|
+
|
3
|
+
Ruby wrapper for [youtube-dl](http://rg3.github.io/youtube-dl/), forked from [youtube-dl.rb](https://github.com/layer8x/youtube-dl.rb).
|
4
|
+
|
5
|
+
## Install the gem
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'rb-youtube-dl'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install rb-youtube-dl
|
20
|
+
|
21
|
+
## Install youtube-dl
|
22
|
+
This gem ships with the latest (working) version of youtube-dl built-in, so you don't have to install youtube-dl at all! Unless you want to.
|
23
|
+
|
24
|
+
Refer to the gem version patch and revision to see what version of youtube-dl is being bundled.
|
25
|
+
|
26
|
+
Some features of youtube-dl require ffmpeg or avconf to be installed. Normally these are available for installation from your distribution's repositories.
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
Pretty simple.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
RbYoutubeDL.download "https://www.youtube.com/watch?v=gvdf5n-zI14", output: 'some_file.mp4'
|
34
|
+
```
|
35
|
+
|
36
|
+
All options available to youtube-dl can be passed to the options hash
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
options = {
|
40
|
+
username: 'someone',
|
41
|
+
password: 'password1',
|
42
|
+
rate_limit: '50K',
|
43
|
+
format: :worst,
|
44
|
+
continue: false
|
45
|
+
}
|
46
|
+
|
47
|
+
RbYoutubeDL.download "https://www.youtube.com/watch?v=gvdf5n-zI14", options
|
48
|
+
```
|
49
|
+
|
50
|
+
Options passed as `options = {option: true}` or `options = {option: false}` are passed to youtube-dl as `--option` or `--no-option`
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
1. Fork it
|
55
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
56
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
57
|
+
4. Pass test suite (`rake test`)
|
58
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
59
|
+
6. Create a new Pull Request
|
60
|
+
|
61
|
+
Remember: commit now, commit often.
|
@@ -0,0 +1,173 @@
|
|
1
|
+
module RbYoutubeDL
|
2
|
+
# Option and configuration getting, setting, and storage, and all that
|
3
|
+
class Options
|
4
|
+
# @return [Hash] key value storage object
|
5
|
+
attr_accessor :store
|
6
|
+
|
7
|
+
# @return [Array] array of keys that won't be saved to the options store
|
8
|
+
attr_accessor :banned_keys
|
9
|
+
|
10
|
+
# Options initializer
|
11
|
+
#
|
12
|
+
# @param options [Hash] a hash of options
|
13
|
+
def initialize(options = {})
|
14
|
+
if options.is_a? Hash
|
15
|
+
@store = options
|
16
|
+
else
|
17
|
+
@store = options.to_h
|
18
|
+
end
|
19
|
+
|
20
|
+
@banned_keys = []
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns options as a hash
|
24
|
+
#
|
25
|
+
# @return [Hash] hash of options
|
26
|
+
def to_hash
|
27
|
+
remove_banned
|
28
|
+
@store
|
29
|
+
end
|
30
|
+
alias_method :to_h, :to_hash
|
31
|
+
|
32
|
+
# Iterate through the paramized keys and values.
|
33
|
+
#
|
34
|
+
# @yield [paramized_key, value]
|
35
|
+
# @return [Object] @store
|
36
|
+
#
|
37
|
+
# TODO: Enumerable?
|
38
|
+
def each_paramized
|
39
|
+
@store.each do |key, value|
|
40
|
+
yield(paramize(key), value)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Iterate through the keys and their paramized counterparts.
|
45
|
+
#
|
46
|
+
# @yield [key, paramized_key]
|
47
|
+
# @return [Object] @store
|
48
|
+
def each_paramized_key
|
49
|
+
@store.each_key do |key|
|
50
|
+
yield(key, paramize(key))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Set options using a block
|
55
|
+
#
|
56
|
+
# @yield [config] self
|
57
|
+
def configure
|
58
|
+
yield(self) if block_given?
|
59
|
+
remove_banned
|
60
|
+
self
|
61
|
+
end
|
62
|
+
|
63
|
+
# Get option with brackets syntax
|
64
|
+
#
|
65
|
+
# @param key [Object] key
|
66
|
+
# @return [Object] value
|
67
|
+
def [](key)
|
68
|
+
remove_banned
|
69
|
+
return nil if banned? key
|
70
|
+
@store[key.to_sym]
|
71
|
+
end
|
72
|
+
|
73
|
+
# Set option with brackets syntax
|
74
|
+
#
|
75
|
+
# @param key [Object] key
|
76
|
+
# @param value [Object] value
|
77
|
+
# @return [Object] whatever Hash#= returns
|
78
|
+
def []=(key, value)
|
79
|
+
remove_banned
|
80
|
+
return nil if banned? key
|
81
|
+
@store[key.to_sym] = value
|
82
|
+
end
|
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 [RbYoutubeDL::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
|
+
|
96
|
+
# Option getting and setting using ghost methods
|
97
|
+
#
|
98
|
+
# @param method [Symbol] method name
|
99
|
+
# @param args [Array] list of arguments passed
|
100
|
+
# @param block [Proc] implicit block given
|
101
|
+
# @return [Object] the value of method in the options store
|
102
|
+
def method_missing(method, *args, &_block)
|
103
|
+
remove_banned
|
104
|
+
if method.to_s.include? '='
|
105
|
+
method = method.to_s.tr('=', '').to_sym
|
106
|
+
return nil if banned? method
|
107
|
+
@store[method] = args.first
|
108
|
+
else
|
109
|
+
return nil if banned? method
|
110
|
+
@store[method]
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# Calls a block to do operations on keys
|
115
|
+
# See sanitize_keys! for examples
|
116
|
+
#
|
117
|
+
# @param block [Proc] Block with operations on keys
|
118
|
+
# @yieldparam key [Object] Original key
|
119
|
+
# @yieldreturn [Object] Manipulated key
|
120
|
+
def manipulate_keys!(&block)
|
121
|
+
@store.keys.each do |old_name|
|
122
|
+
new_name = block.call(old_name)
|
123
|
+
unless new_name == old_name
|
124
|
+
@store[new_name] = @store[old_name]
|
125
|
+
@store.delete(old_name)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# Symbolizes and sanitizes keys in the option store
|
131
|
+
#
|
132
|
+
# @return [Object] @store
|
133
|
+
def sanitize_keys!
|
134
|
+
# Symbolize
|
135
|
+
manipulate_keys! { |key_name| key_name.is_a?(Symbol) ? key_name : key_name.to_sym }
|
136
|
+
|
137
|
+
# Underscoreize (because Terrapin doesn't like hyphens)
|
138
|
+
manipulate_keys! { |key_name| key_name.to_s.tr('-', '_').to_sym }
|
139
|
+
end
|
140
|
+
|
141
|
+
# Symbolizes and sanitizes keys and returns a copy of self
|
142
|
+
#
|
143
|
+
# @return [RbYoutubeDL::Options] Options with sanitized keys.
|
144
|
+
def sanitize_keys
|
145
|
+
safe_copy = dup
|
146
|
+
safe_copy.sanitize_keys!
|
147
|
+
safe_copy
|
148
|
+
end
|
149
|
+
|
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
|
159
|
+
|
160
|
+
# Helper function to convert option keys into command-line-friendly parameters
|
161
|
+
#
|
162
|
+
# @param key [Symbol, String] key to paramize
|
163
|
+
# @return [String] paramized key
|
164
|
+
def paramize(key)
|
165
|
+
key.to_s.tr('_', '-')
|
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
|
172
|
+
end
|
173
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module RbYoutubeDL
|
2
|
+
# Utility class for running and managing youtube-dl
|
3
|
+
class Runner
|
4
|
+
include RbYoutubeDL::Support
|
5
|
+
|
6
|
+
# @return [String] URL to download
|
7
|
+
attr_accessor :url
|
8
|
+
|
9
|
+
# @return [RbYoutubeDL::Options] Options access.
|
10
|
+
attr_accessor :options
|
11
|
+
|
12
|
+
# @return [String] Executable path
|
13
|
+
attr_reader :executable_path
|
14
|
+
|
15
|
+
# @return [String] Executable name to use
|
16
|
+
attr_accessor :executable
|
17
|
+
|
18
|
+
# Command Line runner initializer
|
19
|
+
#
|
20
|
+
# @param url [String] URL to pass to youtube-dl executable
|
21
|
+
# @param options [Hash, Options] options to pass to the executable. Automatically converted to Options if it isn't already
|
22
|
+
def initialize(url, options = {})
|
23
|
+
@url = url
|
24
|
+
@options = RbYoutubeDL::Options.new(options)
|
25
|
+
@executable = 'youtube-dl'
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns usable executable path for youtube-dl
|
29
|
+
#
|
30
|
+
# @return [String] usable executable path for youtube-dl
|
31
|
+
def executable_path
|
32
|
+
@executable_path ||= usable_executable_path_for(@executable)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns Terrapin's runner engine
|
36
|
+
#
|
37
|
+
# @return [CommandLineRunner] backend runner class
|
38
|
+
def backend_runner
|
39
|
+
Terrapin::CommandLine.runner
|
40
|
+
end
|
41
|
+
|
42
|
+
# Sets Terrapin's runner engine
|
43
|
+
#
|
44
|
+
# @param terrapin_runner [CommandLineRunner] backend runner class
|
45
|
+
# @return [Object] whatever Terrapin::CommandLine.runner= returns.
|
46
|
+
def backend_runner=(terrapin_runner)
|
47
|
+
Terrapin::CommandLine.runner = terrapin_runner
|
48
|
+
end
|
49
|
+
|
50
|
+
# Returns the command string without running anything
|
51
|
+
#
|
52
|
+
# @return [String] command line string
|
53
|
+
def to_command
|
54
|
+
terrapin_line(options_to_commands).command(@options.store)
|
55
|
+
end
|
56
|
+
alias_method :command, :to_command
|
57
|
+
|
58
|
+
# Runs the command
|
59
|
+
#
|
60
|
+
# @return [String] the output of youtube-dl
|
61
|
+
def run
|
62
|
+
terrapin_line(options_to_commands).run(@options.store)
|
63
|
+
end
|
64
|
+
alias_method :download, :run
|
65
|
+
|
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
|
77
|
+
|
78
|
+
# Parses options and converts them to Terrapin's syntax
|
79
|
+
#
|
80
|
+
# @return [String] commands ready to do terrapin
|
81
|
+
def options_to_commands
|
82
|
+
commands = []
|
83
|
+
@options.sanitize_keys.each_paramized_key do |key, paramized_key|
|
84
|
+
if @options[key].to_s == 'true'
|
85
|
+
commands.push "--#{paramized_key}"
|
86
|
+
elsif @options[key].to_s == 'false'
|
87
|
+
commands.push "--no-#{paramized_key}"
|
88
|
+
else
|
89
|
+
commands.push "--#{paramized_key} :#{key}"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
commands.push quoted(url)
|
93
|
+
commands.join(' ')
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module RbYoutubeDL
|
2
|
+
# Some support methods and glue logic.
|
3
|
+
module Support
|
4
|
+
# Returns a usable youtube-dl executable (system or vendor)
|
5
|
+
#
|
6
|
+
# @param exe [String] Executable to search for
|
7
|
+
# @return [String] executable path
|
8
|
+
def usable_executable_path_for(exe)
|
9
|
+
system_path = which(exe)
|
10
|
+
if system_path.nil?
|
11
|
+
# TODO: Search vendor bin for executable before just saying it's there.
|
12
|
+
vendor_path = File.absolute_path("#{__FILE__}/../../../vendor/bin/#{exe}")
|
13
|
+
File.chmod(775, vendor_path) unless File.executable?(vendor_path) # Make sure vendor binary is executable
|
14
|
+
vendor_path
|
15
|
+
else
|
16
|
+
system_path.strip
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
alias_method :executable_path_for, :usable_executable_path_for
|
21
|
+
|
22
|
+
# Helper for doing lines of terrapin (initializing, auto executable stuff, etc)
|
23
|
+
#
|
24
|
+
# @param command [String] command switches to run
|
25
|
+
# @param executable_path [String] executable to run. Defaults to usable youtube-dl.
|
26
|
+
# @return [Terrapin::CommandLine] initialized Terrapin instance
|
27
|
+
def terrapin_line(command, executable_path = nil)
|
28
|
+
executable_path = executable_path_for('youtube-dl') if executable_path.nil?
|
29
|
+
Terrapin::CommandLine.new(executable_path, command)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Helper to add quotes to beginning and end of a URL or whatever you want....
|
33
|
+
#
|
34
|
+
# @param url [String] Raw URL
|
35
|
+
# @return [String] Quoted URL
|
36
|
+
def quoted(url)
|
37
|
+
"\"#{url}\""
|
38
|
+
end
|
39
|
+
|
40
|
+
# Cross-platform way of finding an executable in the $PATH.
|
41
|
+
# Stolen from http://stackoverflow.com/a/5471032
|
42
|
+
#
|
43
|
+
# which('ruby') #=> /usr/bin/ruby
|
44
|
+
#
|
45
|
+
# @param cmd [String] cmd to search for
|
46
|
+
# @return [String] full path for the cmd
|
47
|
+
def which(cmd)
|
48
|
+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
49
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
50
|
+
exts.each do |ext|
|
51
|
+
exe = File.join(path, "#{cmd}#{ext}")
|
52
|
+
return exe if File.executable?(exe) && !File.directory?(exe)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
|
2
|
+
# Version file
|
3
|
+
# If you are updating this code, make sure you are updating
|
4
|
+
# lib/rb-youtube-dl/version.rb as well as the Rakefile.
|
5
|
+
|
6
|
+
module RbYoutubeDL
|
7
|
+
# Semantic Version as well as the bundled binary version.
|
8
|
+
# "(major).(minor).(teeny).(pre-release).(binary-version)"
|
9
|
+
VERSION = '0.4.0.2021.12.17'.freeze
|
10
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module RbYoutubeDL
|
2
|
+
# Video model for using and downloading a single video.
|
3
|
+
class Video < Runner
|
4
|
+
class << self
|
5
|
+
# Instantiate a new Video model and download the video
|
6
|
+
#
|
7
|
+
# RbYoutubeDL.download 'https://www.youtube.com/watch?v=KLRDLIIl8bA' # => #<RbYoutubeDL::Video:0x00000000000000>
|
8
|
+
# RbYoutubeDL.get 'https://www.youtube.com/watch?v=ia1diPnNBgU', extract_audio: true, audio_quality: 0
|
9
|
+
#
|
10
|
+
# @param url [String] URL to use and download
|
11
|
+
# @param options [Hash] Options to pass in
|
12
|
+
# @return [RbYoutubeDL::Video] new Video model
|
13
|
+
def download(url, options = {})
|
14
|
+
video = new(url, options)
|
15
|
+
video.download
|
16
|
+
video
|
17
|
+
end
|
18
|
+
alias_method :get, :download
|
19
|
+
end
|
20
|
+
|
21
|
+
# @return [RbYoutubeDL::Options] Download Options for the last download
|
22
|
+
attr_reader :download_options
|
23
|
+
|
24
|
+
# Instantiate new model
|
25
|
+
#
|
26
|
+
# @param url [String] URL to initialize with
|
27
|
+
# @param options [Hash] Options to populate the everything with
|
28
|
+
def initialize(url, options = {})
|
29
|
+
@url = url
|
30
|
+
@options = RbYoutubeDL::Options.new(options.merge(default_options))
|
31
|
+
@options.banned_keys = banned_keys
|
32
|
+
end
|
33
|
+
|
34
|
+
# Download the video.
|
35
|
+
def download
|
36
|
+
raise ArgumentError.new('url cannot be nil') if @url.nil?
|
37
|
+
raise ArgumentError.new('url cannot be empty') if @url.empty?
|
38
|
+
|
39
|
+
set_information_from_json(RbYoutubeDL::Runner.new(url, runner_options).run)
|
40
|
+
end
|
41
|
+
|
42
|
+
alias_method :get, :download
|
43
|
+
|
44
|
+
# Returns the expected filename
|
45
|
+
#
|
46
|
+
# @return [String] Filename downloaded to
|
47
|
+
def filename
|
48
|
+
self._filename
|
49
|
+
end
|
50
|
+
|
51
|
+
# Metadata information for the video, gotten from --print-json
|
52
|
+
#
|
53
|
+
# @return [OpenStruct] information
|
54
|
+
def information
|
55
|
+
@information || grab_information_without_download
|
56
|
+
end
|
57
|
+
|
58
|
+
# Redirect methods for information getting
|
59
|
+
#
|
60
|
+
# @param method [Symbol] method name
|
61
|
+
# @param args [Array] method arguments
|
62
|
+
# @param block [Proc] explict block
|
63
|
+
# @return [Object] The value from @information
|
64
|
+
def method_missing(method, *args, &block)
|
65
|
+
value = information[method]
|
66
|
+
|
67
|
+
if value.nil?
|
68
|
+
super
|
69
|
+
else
|
70
|
+
value
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
# Add in other default options here.
|
77
|
+
def default_options
|
78
|
+
{
|
79
|
+
color: false,
|
80
|
+
progress: false,
|
81
|
+
print_json: true
|
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
|
+
RbYoutubeDL::Options.new(@options.to_h.merge(default_options))
|
100
|
+
end
|
101
|
+
|
102
|
+
def set_information_from_json(json) # :nodoc:
|
103
|
+
@information = JSON.parse(json, symbolize_names: true)
|
104
|
+
end
|
105
|
+
|
106
|
+
def grab_information_without_download # :nodoc:
|
107
|
+
set_information_from_json(RbYoutubeDL::Runner.new(url, runner_options.with({ skip_download: true})).run)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'terrapin'
|
2
|
+
require 'json'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
require 'rb-youtube-dl/version'
|
6
|
+
require 'rb-youtube-dl/support'
|
7
|
+
require 'rb-youtube-dl/options'
|
8
|
+
require 'rb-youtube-dl/runner'
|
9
|
+
require 'rb-youtube-dl/video'
|
10
|
+
|
11
|
+
# Global RbYoutubeDL module. Contains some convenience methods and all of the business classes.
|
12
|
+
module RbYoutubeDL
|
13
|
+
extend self
|
14
|
+
extend Support
|
15
|
+
|
16
|
+
# Downloads given array of URLs with any options passed
|
17
|
+
#
|
18
|
+
# @param urls [String, Array] URLs to download
|
19
|
+
# @param options [Hash] Downloader options
|
20
|
+
# @return [RbYoutubeDL::Video, Array] Video model or array of Video models
|
21
|
+
def download(urls, options = {})
|
22
|
+
if urls.is_a? Array
|
23
|
+
urls.map { |url| RbYoutubeDL::Video.get(url, options) }
|
24
|
+
else
|
25
|
+
RbYoutubeDL::Video.get(urls, options) # Urls should be singular but oh well. url = urls. There. Go cry in a corner.
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
alias_method :get, :download
|
30
|
+
|
31
|
+
# Lists extractors
|
32
|
+
#
|
33
|
+
# @return [Array] list of extractors
|
34
|
+
def extractors
|
35
|
+
@extractors ||= terrapin_line('--list-extractors').run.split("\n")
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns youtube-dl's version
|
39
|
+
#
|
40
|
+
# @return [String] youtube-dl version
|
41
|
+
def binary_version
|
42
|
+
@binary_version ||= terrapin_line('--version').run.strip
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns user agent
|
46
|
+
#
|
47
|
+
# @return [String] user agent
|
48
|
+
def user_agent
|
49
|
+
@user_agent ||= terrapin_line('--dump-user-agent').run.strip
|
50
|
+
end
|
51
|
+
end
|
data/vendor/bin/test
ADDED
File without changes
|
Binary file
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rb-youtube-dl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0.2021.12.17
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- drwl
|
8
|
+
- sapslaj
|
9
|
+
- xNightMare
|
10
|
+
autorequire:
|
11
|
+
bindir: vendor/bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2022-12-11 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: terrapin
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ">="
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.6.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: 0.6.0
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: bundler
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '1.6'
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '1.6'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: rake
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: rspec
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: rspec-retry
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: pry
|
87
|
+
requirement: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
type: :development
|
93
|
+
prerelease: false
|
94
|
+
version_requirements: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
name: pry-byebug
|
101
|
+
requirement: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
type: :development
|
107
|
+
prerelease: false
|
108
|
+
version_requirements: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
description: in the spirit of pygments.rb and MiniMagick, youtube-dl.rb is a command
|
114
|
+
line wrapper for the python script youtube-dl
|
115
|
+
email:
|
116
|
+
- git@drewlee.com
|
117
|
+
executables: []
|
118
|
+
extensions: []
|
119
|
+
extra_rdoc_files: []
|
120
|
+
files:
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- lib/rb-youtube-dl.rb
|
124
|
+
- lib/rb-youtube-dl/options.rb
|
125
|
+
- lib/rb-youtube-dl/runner.rb
|
126
|
+
- lib/rb-youtube-dl/support.rb
|
127
|
+
- lib/rb-youtube-dl/version.rb
|
128
|
+
- lib/rb-youtube-dl/video.rb
|
129
|
+
- vendor/bin/test
|
130
|
+
- vendor/bin/youtube-dl
|
131
|
+
- vendor/bin/youtube-dl.exe
|
132
|
+
homepage: https://github.com/drwl/rb-youtube-dl
|
133
|
+
licenses:
|
134
|
+
- MIT
|
135
|
+
metadata:
|
136
|
+
homepage_uri: https://github.com/drwl/rb-youtube-dl
|
137
|
+
source_code_uri: https://github.com/drwl/rb-youtube-dl
|
138
|
+
bug_tracker_uri: https://github.com/drwl/rb-youtube-dl/issues
|
139
|
+
post_install_message:
|
140
|
+
rdoc_options: []
|
141
|
+
require_paths:
|
142
|
+
- lib
|
143
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: 2.7.0
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
requirements: []
|
154
|
+
rubygems_version: 3.1.6
|
155
|
+
signing_key:
|
156
|
+
specification_version: 4
|
157
|
+
summary: Ruby wrapper for youtube-dl, forked from youtube-dl.rb
|
158
|
+
test_files: []
|