youtube-dl.rb 0.2.0 → 0.2.1
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 +4 -4
- data/lib/youtube-dl.rb +3 -0
- data/lib/youtube-dl/options.rb +9 -0
- data/lib/youtube-dl/output.rb +14 -1
- data/lib/youtube-dl/runner.rb +3 -3
- data/lib/youtube-dl/support.rb +24 -5
- data/lib/youtube-dl/version.rb +1 -1
- data/lib/youtube-dl/video.rb +5 -1
- data/test/fixtures.yml +54 -0
- data/test/test_helper.rb +9 -0
- data/test/youtube-dl/output_test.rb +12 -40
- data/test/youtube-dl/support_test.rb +6 -0
- data/vendor/bin/youtube-dl +0 -0
- data/vendor/bin/youtube-dl.exe +0 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9617af8816b4a2d132a238753878f96266d28c83
|
4
|
+
data.tar.gz: 90ebb1224cf47322e548d66ff45d13a32b48b2ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 005ac4174bbf67fd4392f339dd853615fc984d3da896e83ec4024dcce56e0895c834a2eb9181426e6ec3a61a305e4e3fc17d9ace8781487df46e98c48f42e204
|
7
|
+
data.tar.gz: 24c69abc365276c73497f483d8c7c9eb6ca782dd42181bb99bee7b8a5964ee52105b0ba53507a4881c5b3a8ceb4c4579982ae4b8862e6b4da3c54debe0c688a2
|
data/lib/youtube-dl.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'cocaine'
|
2
|
+
|
1
3
|
require 'youtube-dl/version'
|
2
4
|
require 'youtube-dl/support'
|
3
5
|
require 'youtube-dl/options'
|
@@ -5,6 +7,7 @@ require 'youtube-dl/output'
|
|
5
7
|
require 'youtube-dl/runner'
|
6
8
|
require 'youtube-dl/video'
|
7
9
|
|
10
|
+
# Global YoutubeDL module. Contains some convenience methods and all of the business classes.
|
8
11
|
module YoutubeDL
|
9
12
|
extend self
|
10
13
|
extend Support
|
data/lib/youtube-dl/options.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
module YoutubeDL
|
2
|
+
|
3
|
+
# Option and configuration getting, setting, and storage, and all that
|
2
4
|
class Options
|
5
|
+
|
6
|
+
# [Hash] key value storage object
|
3
7
|
attr_accessor :store
|
4
8
|
|
5
9
|
# Options initializer
|
@@ -65,6 +69,11 @@ module YoutubeDL
|
|
65
69
|
end
|
66
70
|
|
67
71
|
# Option getting and setting using ghost methods
|
72
|
+
#
|
73
|
+
# @param method [Symbol] method name
|
74
|
+
# @param args [Array] list of arguments passed
|
75
|
+
# @param block [Proc] implicit block given
|
76
|
+
# @return [Object] the value of method in the options store
|
68
77
|
def method_missing(method, *args, &block)
|
69
78
|
if method.to_s.include? '='
|
70
79
|
method = method.to_s.tr('=', '').to_sym
|
data/lib/youtube-dl/output.rb
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
module YoutubeDL
|
2
|
+
|
2
3
|
# A class of voodoo methods for parsing youtube-dl output
|
3
|
-
class Output
|
4
|
+
class Output
|
5
|
+
|
6
|
+
# [String] Whatever youtube-dl spat out.
|
7
|
+
attr_accessor :output
|
8
|
+
|
9
|
+
# Initialize output parser
|
10
|
+
#
|
11
|
+
# @param output [String] Whatever youtube-dl spat out.
|
12
|
+
# @return [YoutubeDL::Output] self
|
13
|
+
def initialize(output)
|
14
|
+
@output = output
|
15
|
+
end
|
16
|
+
|
4
17
|
# Takes the output of '--list-formats'
|
5
18
|
#
|
6
19
|
# @return [Array] Array of supported formats
|
data/lib/youtube-dl/runner.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require 'cocaine'
|
2
|
-
|
3
1
|
module YoutubeDL
|
2
|
+
|
3
|
+
# Utility class for running and managing youtube-dl
|
4
4
|
class Runner
|
5
5
|
include YoutubeDL::Support
|
6
6
|
|
@@ -42,7 +42,7 @@ module YoutubeDL
|
|
42
42
|
|
43
43
|
# Sets Cocaine's runner engine
|
44
44
|
#
|
45
|
-
# @param [CommandLineRunner] backend runner class
|
45
|
+
# @param cocaine_runner [CommandLineRunner] backend runner class
|
46
46
|
# @return [Object] whatever Cocaine::CommandLine.runner= returns.
|
47
47
|
def backend_runner=(cocaine_runner)
|
48
48
|
Cocaine::CommandLine.runner = cocaine_runner
|
data/lib/youtube-dl/support.rb
CHANGED
@@ -1,20 +1,21 @@
|
|
1
1
|
module YoutubeDL
|
2
|
+
|
3
|
+
# Some support methods and glue logic.
|
2
4
|
module Support
|
3
|
-
# Some support methods and glue logic.
|
4
5
|
|
5
6
|
# Returns a usable youtube-dl executable (system or vendor)
|
6
7
|
#
|
7
8
|
# @param exe [String] Executable to search for
|
8
9
|
# @return [String] executable path
|
9
10
|
def usable_executable_path_for(exe)
|
10
|
-
system_path =
|
11
|
-
if
|
12
|
-
system_path.strip
|
13
|
-
else
|
11
|
+
system_path = which(exe)
|
12
|
+
if system_path.nil?
|
14
13
|
# TODO: Search vendor bin for executable before just saying it's there.
|
15
14
|
vendor_path = File.absolute_path("#{__FILE__}/../../../vendor/bin/#{exe}")
|
16
15
|
File.chmod(775, vendor_path) unless File.executable?(vendor_path) # Make sure vendor binary is executable
|
17
16
|
vendor_path
|
17
|
+
else
|
18
|
+
system_path.strip
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
@@ -37,5 +38,23 @@ module YoutubeDL
|
|
37
38
|
def quoted(url)
|
38
39
|
"\"#{url}\""
|
39
40
|
end
|
41
|
+
|
42
|
+
# Cross-platform way of finding an executable in the $PATH.
|
43
|
+
# Stolen from http://stackoverflow.com/a/5471032
|
44
|
+
#
|
45
|
+
# which('ruby') #=> /usr/bin/ruby
|
46
|
+
#
|
47
|
+
# @param cmd [String] cmd to search for
|
48
|
+
# @return [String] full path for the cmd
|
49
|
+
def which(cmd)
|
50
|
+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
51
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
52
|
+
exts.each { |ext|
|
53
|
+
exe = File.join(path, "#{cmd}#{ext}")
|
54
|
+
return exe if File.executable?(exe) && !File.directory?(exe)
|
55
|
+
}
|
56
|
+
end
|
57
|
+
return nil
|
58
|
+
end
|
40
59
|
end
|
41
60
|
end
|
data/lib/youtube-dl/version.rb
CHANGED
data/lib/youtube-dl/video.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
module YoutubeDL
|
2
|
-
|
2
|
+
|
3
|
+
# Video model for using and downloading a single video.
|
3
4
|
class Video < Runner
|
4
5
|
class << self
|
5
6
|
# Instantiate a new Video model and download the video
|
6
7
|
#
|
8
|
+
# YoutubeDL.download 'https://www.youtube.com/watch?v=KLRDLIIl8bA' # => #<YoutubeDL::Video:0x00000000000000>
|
9
|
+
# YoutubeDL.get 'https://www.youtube.com/watch?v=ia1diPnNBgU', extract_audio: true, audio_quality: 0
|
10
|
+
#
|
7
11
|
# @param url [String] URL to use and download
|
8
12
|
# @param options [Hash] Options to pass in
|
9
13
|
# @return [YoutubeDL::Video] new Video model
|
data/test/fixtures.yml
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
---
|
2
|
+
:output:
|
3
|
+
:download: |
|
4
|
+
[youtube] gvdf5n-zI14: Downloading webpage
|
5
|
+
[youtube] gvdf5n-zI14: Downloading video info webpage
|
6
|
+
[youtube] gvdf5n-zI14: Extracting video information
|
7
|
+
[youtube] gvdf5n-zI14: Downloading DASH manifest
|
8
|
+
[youtube] gvdf5n-zI14: Downloading DASH manifest
|
9
|
+
[download] Destination: nope.avi-gvdf5n-zI14.mp4
|
10
|
+
[download] 100% of 1.31MiB in 00:00
|
11
|
+
:download_ffmpeg: |
|
12
|
+
[youtube] gvdf5n-zI14: Downloading webpage
|
13
|
+
[youtube] gvdf5n-zI14: Downloading video info webpage
|
14
|
+
[youtube] gvdf5n-zI14: Extracting video information
|
15
|
+
[youtube] gvdf5n-zI14: Downloading DASH manifest
|
16
|
+
[youtube] gvdf5n-zI14: Downloading DASH manifest
|
17
|
+
[download] Destination: nope.avi-gvdf5n-zI14.f136.mp4
|
18
|
+
[download] 100% of 762.83KiB in 00:04
|
19
|
+
[download] Destination: nope.avi-gvdf5n-zI14.f141.m4a
|
20
|
+
[download] 100% of 282.57KiB in 00:00
|
21
|
+
[ffmpeg] Merging formats into "nope.avi-gvdf5n-zI14.mp4"
|
22
|
+
Deleting original file nope.avi-gvdf5n-zI14.f136.mp4 (pass -k to keep)
|
23
|
+
Deleting original file nope.avi-gvdf5n-zI14.f141.m4a (pass -k to keep)
|
24
|
+
:download_exists: |
|
25
|
+
[youtube] gvdf5n-zI14: Downloading webpage
|
26
|
+
[youtube] gvdf5n-zI14: Downloading video info webpage
|
27
|
+
[youtube] gvdf5n-zI14: Extracting video information
|
28
|
+
[youtube] gvdf5n-zI14: Downloading DASH manifest
|
29
|
+
[youtube] gvdf5n-zI14: Downloading DASH manifest
|
30
|
+
[download] nope.avi-gvdf5n-zI14.mp4 has already been downloaded
|
31
|
+
[download] 100% of 1.31MiB
|
32
|
+
:list_formats: "[youtube] gvdf5n-zI14: Downloading webpage\n[youtube] gvdf5n-zI14:
|
33
|
+
Downloading video info webpage\n[youtube] gvdf5n-zI14: Extracting video information\n[youtube]
|
34
|
+
gvdf5n-zI14: Downloading DASH manifest\n[youtube] gvdf5n-zI14: Downloading DASH
|
35
|
+
manifest\n[info] Available formats for gvdf5n-zI14:\nformat code extension resolution
|
36
|
+
note\n171 webm audio only DASH audio 120k , vorbis@128k (44100Hz),
|
37
|
+
132.26KiB\n140 m4a audio only DASH audio 129k , m4a_dash container,
|
38
|
+
aac @128k (44100Hz), 142.59KiB\n141 m4a audio only DASH audio
|
39
|
+
\ 255k , m4a_dash container, aac @256k (44100Hz), 282.57KiB\n242 webm
|
40
|
+
\ 426x240 DASH video 109k , vp9, 1fps, video only, 118.40KiB\n160 mp4
|
41
|
+
\ 256x144 DASH video 110k , avc1.4d400c, 12fps, video only, 121.30KiB\n243
|
42
|
+
\ webm 640x360 DASH video 189k , vp9, 1fps, video only, 200.48KiB\n134
|
43
|
+
\ mp4 640x360 DASH video 237k , avc1.4d401e, 24fps, video only,
|
44
|
+
239.13KiB\n133 mp4 426x240 DASH video 248k , avc1.4d4015,
|
45
|
+
24fps, video only, 270.34KiB\n244 webm 854x480 DASH video 311k
|
46
|
+
, vp9, 1fps, video only, 333.92KiB\n135 mp4 854x480 DASH video
|
47
|
+
\ 430k , avc1.4d401e, 24fps, video only, 421.60KiB\n247 webm 1280x720
|
48
|
+
\ DASH video 572k , vp9, 1fps, video only, 596.27KiB\n136 mp4 1280x720
|
49
|
+
\ DASH video 788k , avc1.4d401f, 24fps, video only, 762.83KiB\n13 3gp
|
50
|
+
\ unknown small \n17 3gp 176x144 small , mp4a.40.2,
|
51
|
+
mp4v.20.3\n36 3gp 320x240 small , mp4a.40.2, mp4v.20.3\n5
|
52
|
+
\ flv 400x240 small \n43 webm 640x360 medium
|
53
|
+
, vorbis, vp8.0\n18 mp4 640x360 medium , mp4a.40.2, avc1.42001E\n22
|
54
|
+
\ mp4 1280x720 hd720 , mp4a.40.2, avc1.64001F (best)\n"
|
data/test/test_helper.rb
CHANGED
@@ -14,6 +14,7 @@ require 'minitest/spec'
|
|
14
14
|
require 'purdytest' # minitest-colorize is broken in minitest version 5
|
15
15
|
require 'pry'
|
16
16
|
require 'fileutils'
|
17
|
+
require 'yaml'
|
17
18
|
|
18
19
|
require 'youtube-dl'
|
19
20
|
|
@@ -28,3 +29,11 @@ def remove_downloaded_files
|
|
28
29
|
File.delete(nope)
|
29
30
|
end
|
30
31
|
end
|
32
|
+
|
33
|
+
def fixture(*keys)
|
34
|
+
@fixtures ||= YAML.load(File.read(File.join(File.dirname(__FILE__), 'fixtures.yml')))
|
35
|
+
|
36
|
+
last_path = @fixtures
|
37
|
+
keys.each { |key| last_path = last_path[key] }
|
38
|
+
last_path
|
39
|
+
end
|
@@ -1,38 +1,5 @@
|
|
1
1
|
require_relative '../test_helper'
|
2
2
|
|
3
|
-
module OutputFactory
|
4
|
-
extend self
|
5
|
-
extend YoutubeDL::Support
|
6
|
-
|
7
|
-
def download
|
8
|
-
remove_downloaded_files # Make sure there isn't a file there
|
9
|
-
@download ||= cocaine_line(quoted(TEST_URL)).run
|
10
|
-
end
|
11
|
-
|
12
|
-
def download_exists
|
13
|
-
@download_exists ||= lambda do
|
14
|
-
cocaine_line(quoted(TEST_URL)).run # two times to make sure it's there.
|
15
|
-
cocaine_line(quoted(TEST_URL)).run
|
16
|
-
end.call
|
17
|
-
end
|
18
|
-
|
19
|
-
def list_formats
|
20
|
-
@list_formats ||= cocaine_line("--list-formats #{quoted(TEST_URL)}").run
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
# For debugging
|
25
|
-
# puts
|
26
|
-
# puts " --------------- OutputFactory.download --------------- "
|
27
|
-
# puts OutputFactory.download
|
28
|
-
# puts
|
29
|
-
# puts " --------------- OutputFactory.download_exists --------------- "
|
30
|
-
# puts OutputFactory.download_exists
|
31
|
-
# puts
|
32
|
-
# puts " --------------- OutputFactory.list_formats --------------- "
|
33
|
-
# puts OutputFactory.list_formats
|
34
|
-
# puts
|
35
|
-
|
36
3
|
describe YoutubeDL::Output do
|
37
4
|
describe '#initialize' do
|
38
5
|
it 'should set the output variable' do
|
@@ -44,7 +11,7 @@ describe YoutubeDL::Output do
|
|
44
11
|
|
45
12
|
describe '#supported_formats' do
|
46
13
|
before do
|
47
|
-
@parser = YoutubeDL::Output.new(
|
14
|
+
@parser = YoutubeDL::Output.new(fixture(:output, :list_formats))
|
48
15
|
end
|
49
16
|
|
50
17
|
it 'should find a match given the correct output' do
|
@@ -56,37 +23,41 @@ describe YoutubeDL::Output do
|
|
56
23
|
end
|
57
24
|
|
58
25
|
it 'should return nil if no match or wrong log format' do
|
59
|
-
bad_parser = YoutubeDL::Output.new(
|
26
|
+
bad_parser = YoutubeDL::Output.new(fixture(:output, :download))
|
60
27
|
assert_nil bad_parser.supported_formats
|
61
28
|
end
|
62
29
|
end
|
63
30
|
|
64
31
|
describe '#filename' do
|
65
32
|
before do
|
66
|
-
@parser_download = YoutubeDL::Output.new(
|
67
|
-
@
|
33
|
+
@parser_download = YoutubeDL::Output.new(fixture(:output, :download))
|
34
|
+
@parser_download_ffmpeg = YoutubeDL::Output.new(fixture(:output, :download_ffmpeg))
|
35
|
+
@parser_download_exists = YoutubeDL::Output.new(fixture(:output, :download_exists))
|
68
36
|
end
|
69
37
|
|
70
38
|
it 'should find a match given the correct output' do
|
71
39
|
refute_nil @parser_download.filename
|
40
|
+
refute_nil @parser_download_ffmpeg.filename
|
72
41
|
refute_nil @parser_download_exists.filename
|
73
42
|
end
|
74
43
|
|
75
44
|
it 'should find the correct match' do
|
76
45
|
assert_equal 'nope.avi-gvdf5n-zI14.mp4', @parser_download.filename
|
46
|
+
assert_equal 'nope.avi-gvdf5n-zI14.mp4', @parser_download_ffmpeg.filename
|
77
47
|
assert_equal 'nope.avi-gvdf5n-zI14.mp4', @parser_download_exists.filename
|
78
48
|
end
|
79
49
|
|
80
50
|
it 'should return nil if no match or wrong log format' do
|
81
|
-
bad_parser = YoutubeDL::Output.new(
|
51
|
+
bad_parser = YoutubeDL::Output.new(fixture(:output, :list_formats))
|
82
52
|
assert_nil bad_parser.filename
|
83
53
|
end
|
84
54
|
end
|
85
55
|
|
86
56
|
describe '#already_downloaded?' do
|
87
57
|
before do
|
88
|
-
@parser_download = YoutubeDL::Output.new(
|
89
|
-
@
|
58
|
+
@parser_download = YoutubeDL::Output.new(fixture(:output, :download))
|
59
|
+
@parser_download_ffmpeg = YoutubeDL::Output.new(fixture(:output, :download_ffmpeg))
|
60
|
+
@parser_download_exists = YoutubeDL::Output.new(fixture(:output, :download_exists))
|
90
61
|
end
|
91
62
|
|
92
63
|
it 'should return a truthy value if true' do
|
@@ -95,6 +66,7 @@ describe YoutubeDL::Output do
|
|
95
66
|
|
96
67
|
it 'should return a falsy value if false' do
|
97
68
|
refute @parser_download.already_downloaded?
|
69
|
+
refute @parser_download_ffmpeg.already_downloaded?
|
98
70
|
end
|
99
71
|
end
|
100
72
|
end
|
data/vendor/bin/youtube-dl
CHANGED
Binary file
|
data/vendor/bin/youtube-dl.exe
CHANGED
Binary file
|
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.
|
4
|
+
version: 0.2.1
|
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-09-
|
12
|
+
date: 2015-09-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cocaine
|
@@ -144,6 +144,7 @@ files:
|
|
144
144
|
- lib/youtube-dl/support.rb
|
145
145
|
- lib/youtube-dl/version.rb
|
146
146
|
- lib/youtube-dl/video.rb
|
147
|
+
- test/fixtures.yml
|
147
148
|
- test/test_helper.rb
|
148
149
|
- test/youtube-dl/options_test.rb
|
149
150
|
- test/youtube-dl/output_test.rb
|
@@ -179,6 +180,7 @@ signing_key:
|
|
179
180
|
specification_version: 4
|
180
181
|
summary: youtube-dl wrapper for Ruby
|
181
182
|
test_files:
|
183
|
+
- test/fixtures.yml
|
182
184
|
- test/test_helper.rb
|
183
185
|
- test/youtube-dl/options_test.rb
|
184
186
|
- test/youtube-dl/output_test.rb
|