viddl-rb 0.4.7 → 0.4.8
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/README.txt +4 -0
- data/helper/download-helper.rb +52 -37
- data/plugins/youtube.rb +4 -2
- metadata +5 -7
data/README.txt
CHANGED
data/helper/download-helper.rb
CHANGED
@@ -1,42 +1,57 @@
|
|
1
1
|
class DownloadHelper
|
2
2
|
#usually not called directly
|
3
|
-
def self.fetch_file(uri)
|
3
|
+
def self.fetch_file(uri)
|
4
4
|
|
5
|
-
begin
|
6
|
-
|
7
|
-
rescue LoadError
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
#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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
5
|
+
begin
|
6
|
+
require "progressbar" #http://github.com/nex3/ruby-progressbar
|
7
|
+
rescue LoadError
|
8
|
+
puts "ERROR: You don't seem to have curl or wget on your system. In this case you'll need to install the 'progressbar' gem."
|
9
|
+
exit
|
10
|
+
end
|
11
|
+
progress_bar = nil
|
12
|
+
open(uri, :proxy => nil,
|
13
|
+
:content_length_proc => lambda { |length|
|
14
|
+
if length && 0 < length
|
15
|
+
progress_bar = ProgressBar.new(uri.to_s, length)
|
16
|
+
end
|
17
|
+
},
|
18
|
+
:progress_proc => lambda { |progress|
|
19
|
+
progress_bar.set(progress) if progress_bar
|
20
|
+
}) {|file| return file.read}
|
21
|
+
end
|
22
|
+
|
23
|
+
#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
|
+
unescaped_uri = CGI::unescape(file_uri)
|
26
|
+
result = false
|
27
|
+
windows = ENV['OS'] =~ /windows/i
|
28
|
+
if os_has?("wget", windows)
|
29
|
+
puts "using wget"
|
30
|
+
result = system("wget \"#{unescaped_uri}\" -O #{file_name}")
|
31
|
+
elsif os_has?("curl", windows)
|
32
|
+
puts "using curl"
|
33
|
+
#-L means: follow redirects, We set an agent because Vimeo seems to want one
|
34
|
+
result = system("curl -A 'Mozilla/2.02 (OS/2; U)' -L \"#{unescaped_uri}\" -o #{file_name}")
|
35
|
+
else
|
36
|
+
open(file_name, 'wb') { |file|
|
37
|
+
file.write(fetch_file(unescaped_uri)); puts
|
38
|
+
}
|
39
|
+
result = true
|
40
|
+
end
|
41
|
+
result
|
42
|
+
end
|
43
|
+
|
44
|
+
#checks to see whether the os has a certain utility like wget or curl
|
45
|
+
def self.os_has?(utility, windows)
|
46
|
+
unless windows # if os is something else than Windows
|
47
|
+
return `which #{utility}`.include?(utility)
|
48
|
+
else
|
49
|
+
begin
|
50
|
+
`#{utility}` #if running the command does not thow an error, Windows has it
|
51
|
+
return true
|
52
|
+
rescue Errno::ENOENT
|
53
|
+
return false
|
54
|
+
end
|
55
|
+
end
|
39
56
|
end
|
40
|
-
result
|
41
|
-
end
|
42
57
|
end
|
data/plugins/youtube.rb
CHANGED
@@ -129,9 +129,11 @@ class Youtube < PluginBase
|
|
129
129
|
puts "[YOUTUBE] formats available: #{available_formats.inspect} (downloading format #{selected_format} -> #{format_ext[selected_format][:name]})"
|
130
130
|
|
131
131
|
#video_info_hash.keys.sort.each{|key| puts "#{key} : #{video_info_hash[key]}" }
|
132
|
-
|
132
|
+
download_url = video_info_hash["url_encoded_fmt_stream_map"][selected_format]
|
133
|
+
#if download url ends with a ';' followed by a codec string remove that part because stops URI.parse from working
|
134
|
+
download_url = $1 if download_url =~ /(.*?);\scodecs=/
|
133
135
|
file_name = title.delete("\"'").gsub(/[^0-9A-Za-z]/, '_') + "." + format_ext[selected_format][:extension]
|
134
136
|
puts "downloading to " + file_name
|
135
137
|
{:url => download_url, :name => file_name}
|
136
138
|
end
|
137
|
-
end
|
139
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: viddl-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 8
|
10
|
+
version: 0.4.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Marc Seeger
|
@@ -15,8 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
19
|
-
default_executable:
|
18
|
+
date: 2011-11-11 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: nokogiri
|
@@ -50,7 +49,6 @@ files:
|
|
50
49
|
- plugins/youtube.rb
|
51
50
|
- CHANGELOG.txt
|
52
51
|
- README.txt
|
53
|
-
has_rdoc: true
|
54
52
|
homepage: https://github.com/rb2k/viddl-rb
|
55
53
|
licenses: []
|
56
54
|
|
@@ -82,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
80
|
requirements: []
|
83
81
|
|
84
82
|
rubyforge_project: viddl-rb
|
85
|
-
rubygems_version: 1.6
|
83
|
+
rubygems_version: 1.8.6
|
86
84
|
signing_key:
|
87
85
|
specification_version: 3
|
88
86
|
summary: An extendable commandline video downloader for flash video sites.
|