viddl-rb 0.88 → 0.89
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +6 -0
- data/bin/helper/downloader.rb +4 -1
- data/bin/helper/parameter-parser.rb +1 -1
- data/helper/download-helper.rb +49 -23
- metadata +7 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
SHA512:
|
3
|
-
metadata.gz: cf812cece7ef8e7eebc091e815bddb2582a8359ea0cedbb78bf6805a869540e79d794e22c7925c9bc760e472596be5e2803bc0a8c127ec197fdb2115ca88c9fe
|
4
|
-
data.tar.gz: 11dd9c9a0efd88776dd7e98ea74e82bc5d99cdf2772c61ab115104104381a62fec10525a80bf7f2a4b55ced8e517857a4b96a0ba51145b347975157e2cb328a3
|
5
2
|
SHA1:
|
6
|
-
|
7
|
-
|
3
|
+
data.tar.gz: 7de5023703da26be9d242da04ec58925b843575e
|
4
|
+
metadata.gz: dfb1edf7260c4c6e5606a8cd27e5f9bfad7f6a79
|
5
|
+
SHA512:
|
6
|
+
data.tar.gz: 7d81c1e71aa8b04eddc36c624b6ed619367be48ce3fccc1adeb2a76310dda35f0a30dd1174c2a85753f6b78c52bfea6665477eec6af79f16255503ff9af2deb2
|
7
|
+
metadata.gz: 934b156a9bce149f474e9c6da09c5f454168ecdab0119cc0849bcc5e1351299c3bc35ad55d2ab5d5f7bd1fbdcb8a3e083fa3ddaa2bf9dcd32e5698d6f613b2b4
|
data/Gemfile
CHANGED
data/bin/helper/downloader.rb
CHANGED
@@ -8,7 +8,10 @@ class Downloader
|
|
8
8
|
url = url_name[:url]
|
9
9
|
name = url_name[:name]
|
10
10
|
|
11
|
-
result = ViddlRb::DownloadHelper.save_file
|
11
|
+
result = ViddlRb::DownloadHelper.save_file url,
|
12
|
+
name,
|
13
|
+
:save_dir => params[:save_dir],
|
14
|
+
:tool => params[:tool] && params[:tool].to_sym
|
12
15
|
unless result
|
13
16
|
if params[:abort_on_failure]
|
14
17
|
raise DownloadFailedError, "Download for #{name} failed."
|
@@ -67,7 +67,7 @@ class ParameterParser
|
|
67
67
|
end
|
68
68
|
|
69
69
|
opts.on("-d", "--downloader TOOL", "Specifies the tool to download with. Supports 'wget', 'curl' and 'net-http'") do |tool|
|
70
|
-
if tool =~ /(^wget$)|(^curl$)|(^net-http$)/
|
70
|
+
if tool =~ /(^wget$)|(^curl$)|(^net-http$)|(^aria2c$)/
|
71
71
|
options[:tool] = tool
|
72
72
|
else
|
73
73
|
raise OptionParser::InvalidArgument.new("'#{tool}' is not a valid tool.")
|
data/helper/download-helper.rb
CHANGED
@@ -4,39 +4,65 @@ module ViddlRb
|
|
4
4
|
|
5
5
|
class DownloadHelper
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
class Tool
|
8
|
+
attr_reader :name
|
9
|
+
|
10
|
+
def initialize(name, &command_proc)
|
11
|
+
@name = name
|
12
|
+
@command_proc = command_proc
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_command(download_url, save_path)
|
16
|
+
@command_proc.call(download_url, save_path)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# This array specifies the order of and how to invoke the different download tools.
|
21
|
+
# A Tool is created with a name and block, where the block should evaluate to the cmd call
|
22
|
+
# given a download url and a full file save path.
|
23
|
+
TOOLS_PRIORITY_LIST = [
|
24
|
+
|
25
|
+
Tool.new(:aria2c) do |url, path|
|
26
|
+
"aria2c #{url.inspect} -x4 -d #{File.dirname(path).inspect} -o #{File.basename(path).inspect}"
|
27
|
+
end,
|
28
|
+
|
29
|
+
Tool.new(:wget) do |url, path|
|
30
|
+
"wget #{url.inspect} -O #{path.inspect}"
|
31
|
+
end,
|
32
|
+
|
33
|
+
Tool.new(:curl) do |url, path|
|
34
|
+
"curl -A 'Wget/1.8.1' --retry 10 --retry-delay 5 --retry-max-time 4 -L #{url.inspect} -o #{path.inspect}"
|
35
|
+
end
|
36
|
+
]
|
10
37
|
|
11
38
|
#simple helper that will save a file from the web and save it with a progress bar
|
12
|
-
def self.save_file(file_url, file_name,
|
39
|
+
def self.save_file(file_url, file_name, user_opts = {})
|
13
40
|
trap("SIGINT") { puts "goodbye"; exit }
|
14
41
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
:tool => get_tool}
|
42
|
+
default_opts = {:save_dir => ".",
|
43
|
+
:amount_of_retries => 6,
|
44
|
+
:tool => get_default_tool}
|
19
45
|
|
20
|
-
|
21
|
-
|
46
|
+
if user_tool = user_opts[:tool]
|
47
|
+
user_opts[:tool] = TOOLS_PRIORITY_LIST.find { |tool| tool.name == user_tool } unless user_tool == :"net-http"
|
48
|
+
else
|
49
|
+
user_opts[:tool] = default_opts[:tool]
|
50
|
+
end
|
22
51
|
|
52
|
+
options = default_opts.merge(user_opts)
|
23
53
|
file_path = File.expand_path(File.join(options[:save_dir], file_name))
|
24
54
|
success = false
|
25
55
|
|
26
56
|
#Some providers seem to flake out every now end then
|
27
57
|
options[:amount_of_retries].times do |i|
|
28
|
-
|
29
|
-
when :wget
|
30
|
-
puts "Using wget"
|
31
|
-
success = system "wget \"#{file_url}\" -O #{file_path.inspect}"
|
32
|
-
when :curl
|
33
|
-
puts "Using curl"
|
34
|
-
#-L means: follow redirects, We set an agent because Vimeo seems to want one
|
35
|
-
success = system "curl -A 'Wget/1.8.1' --retry 10 --retry-delay 5 --retry-max-time 4 -L \"#{file_url}\" -o #{file_path.inspect}"
|
36
|
-
else
|
58
|
+
if options[:tool] == :"net-http"
|
37
59
|
require_progressbar
|
38
60
|
puts "Using net/http"
|
39
61
|
success = download_and_save_file(file_url, file_path)
|
62
|
+
else
|
63
|
+
tool = options[:tool]
|
64
|
+
puts "Using #{tool.name}"
|
65
|
+
success = system tool.get_command(file_url, file_path)
|
40
66
|
end
|
41
67
|
#we were successful, we're outta here
|
42
68
|
if success
|
@@ -46,11 +72,12 @@ module ViddlRb
|
|
46
72
|
sleep 2
|
47
73
|
end
|
48
74
|
end
|
75
|
+
|
49
76
|
success
|
50
77
|
end
|
51
78
|
|
52
|
-
def self.
|
53
|
-
tool = TOOLS_PRIORITY_LIST.find { |tool| ViddlRb::UtilityHelper.os_has?(tool) }
|
79
|
+
def self.get_default_tool
|
80
|
+
tool = TOOLS_PRIORITY_LIST.find { |tool| ViddlRb::UtilityHelper.os_has?(tool.name) }
|
54
81
|
tool || :net_http
|
55
82
|
end
|
56
83
|
|
@@ -59,11 +86,10 @@ module ViddlRb
|
|
59
86
|
require "progressbar"
|
60
87
|
rescue LoadError
|
61
88
|
raise RequirementError,
|
62
|
-
"you don't seem to have curl or wget on your system. In this case you'll need to install the 'progressbar' gem."
|
89
|
+
"you don't seem to have aria2, curl or wget on your system. In this case you'll need to install the 'progressbar' gem."
|
63
90
|
end
|
64
91
|
end
|
65
92
|
|
66
|
-
# downloads and saves a file using the net/http streaming api
|
67
93
|
# return true if the download was successful, else returns false
|
68
94
|
def self.download_and_save_file(download_url, full_path)
|
69
95
|
final_url = UtilityHelper.get_final_location(download_url) # follow all redirects
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: viddl-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.89"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marc Seeger
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
type: :runtime
|
33
33
|
version_requirements: *id002
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
|
-
name:
|
35
|
+
name: progressbar
|
36
36
|
prerelease: false
|
37
37
|
requirement: &id003 !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
type: :runtime
|
44
44
|
version_requirements: *id003
|
45
45
|
- !ruby/object:Gem::Dependency
|
46
|
-
name:
|
46
|
+
name: multi_json
|
47
47
|
prerelease: false
|
48
48
|
requirement: &id005 !ruby/object:Gem::Requirement
|
49
49
|
requirements:
|
@@ -51,15 +51,15 @@ dependencies:
|
|
51
51
|
type: :runtime
|
52
52
|
version_requirements: *id005
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
|
-
name:
|
54
|
+
name: rake
|
55
55
|
prerelease: false
|
56
56
|
requirement: &id006 !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- *id004
|
59
|
-
type: :
|
59
|
+
type: :development
|
60
60
|
version_requirements: *id006
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
62
|
+
name: rest-client
|
63
63
|
prerelease: false
|
64
64
|
requirement: &id007 !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
@@ -67,21 +67,13 @@ dependencies:
|
|
67
67
|
type: :development
|
68
68
|
version_requirements: *id007
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: minitest
|
71
71
|
prerelease: false
|
72
72
|
requirement: &id008 !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
74
|
- *id004
|
75
75
|
type: :development
|
76
76
|
version_requirements: *id008
|
77
|
-
- !ruby/object:Gem::Dependency
|
78
|
-
name: minitest
|
79
|
-
prerelease: false
|
80
|
-
requirement: &id009 !ruby/object:Gem::Requirement
|
81
|
-
requirements:
|
82
|
-
- *id004
|
83
|
-
type: :development
|
84
|
-
version_requirements: *id009
|
85
77
|
description: An extendable commandline video downloader for flash video sites. Includes plugins for vimeo, youtube, dailymotion and more
|
86
78
|
email: mail@marc-seeger.de
|
87
79
|
executables:
|