viddl-rb 0.61 → 0.63
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.
- data/Gemfile.lock +5 -4
- data/README.md +3 -2
- data/helper/download-helper.rb +27 -17
- metadata +3 -3
data/Gemfile.lock
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
viddl-rb (0.
|
|
4
|
+
viddl-rb (0.61)
|
|
5
5
|
nokogiri
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: http://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
mime-types (1.
|
|
11
|
-
minitest (2.
|
|
12
|
-
nokogiri (1.5.
|
|
10
|
+
mime-types (1.18)
|
|
11
|
+
minitest (2.12.1)
|
|
12
|
+
nokogiri (1.5.2)
|
|
13
|
+
nokogiri (1.5.2-java)
|
|
13
14
|
rake (0.9.2.2)
|
|
14
15
|
rest-client (1.6.7)
|
|
15
16
|
mime-types (>= 1.16)
|
data/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
__viddl-rb:__
|
|
2
2
|
Created by Marc Seeger (@rb2k)
|
|
3
3
|
Repo: http://github.com/rb2k/viddl-rb
|
|
4
|
-
[](http://travis-ci.org/rb2k/viddl-rb)
|
|
4
|
+
[](http://travis-ci.org/rb2k/viddl-rb) [](https://gemnasium.com/rb2k/viddl-rb)
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
@@ -31,4 +31,5 @@ __Contributors:__
|
|
|
31
31
|
* [kl](https://github.com/kl): Windows support (who knew!), bug fixes, veoh plugin, metacafe plugin
|
|
32
32
|
* [divout](https://github.com/divout) aka Ivan K: blip.tv plugin, bugfixes
|
|
33
33
|
* Sniper: bugfixes
|
|
34
|
-
* [Serabe](https://github.com/Serabe) aka Sergio Arbeo: packaging viddl as a binary
|
|
34
|
+
* [Serabe](https://github.com/Serabe) aka Sergio Arbeo: packaging viddl as a binary
|
|
35
|
+
* [laserlemon](https://github.com/laserlemon): Adding gemnasium images to readme
|
data/helper/download-helper.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
class DownloadHelper
|
|
2
|
+
|
|
2
3
|
#usually not called directly
|
|
3
4
|
def self.fetch_file(uri)
|
|
4
5
|
|
|
@@ -21,24 +22,33 @@ class DownloadHelper
|
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
#simple helper that will save a file from the web and save it with a progress bar
|
|
24
|
-
def self.save_file(file_uri, file_name)
|
|
25
|
+
def self.save_file(file_uri, file_name, amount_of_retries = 6)
|
|
26
|
+
trap("SIGINT") { puts "goodbye"; exit }
|
|
25
27
|
unescaped_uri = CGI::unescape(file_uri)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
28
|
+
#Some providers seem to flake out every now end then
|
|
29
|
+
amount_of_retries.times do |i|
|
|
30
|
+
if os_has?("wget")
|
|
31
|
+
puts "using wget"
|
|
32
|
+
`wget \"#{unescaped_uri}\" -O #{file_name}`
|
|
33
|
+
elsif os_has?("curl")
|
|
34
|
+
puts "using curl"
|
|
35
|
+
#-L means: follow redirects, We set an agent because Vimeo seems to want one
|
|
36
|
+
`curl -A 'Wget/1.8.1' -L \"#{unescaped_uri}\" -o #{file_name}`
|
|
37
|
+
else
|
|
38
|
+
puts "using net/http"
|
|
39
|
+
open(file_name, 'wb') { |file|
|
|
40
|
+
file.write(fetch_file(unescaped_uri)); puts
|
|
41
|
+
}
|
|
42
|
+
end
|
|
43
|
+
#we were successful, we're outta here
|
|
44
|
+
if $? == 0
|
|
45
|
+
break
|
|
46
|
+
else
|
|
47
|
+
puts "Download seems to have failed (retrying, attempt #{i+1}/#{amount_of_retries})"
|
|
48
|
+
sleep 2
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
$? == 0
|
|
42
52
|
end
|
|
43
53
|
|
|
44
54
|
#checks to see whether the os has a certain utility like wget or curl
|
metadata
CHANGED