viddl-rb 0.66 → 0.67
Sign up to get free protection for your applications and to get access to all the features.
- data/helper/download-helper.rb +24 -20
- data/helper/plugin-helper.rb +8 -2
- data/plugins/blip.rb +2 -1
- data/plugins/metacafe.rb +2 -1
- data/plugins/veoh.rb +2 -3
- data/plugins/vimeo.rb +3 -8
- data/plugins/youtube.rb +1 -1
- metadata +7 -6
data/helper/download-helper.rb
CHANGED
@@ -4,16 +4,17 @@ class DownloadHelper
|
|
4
4
|
def self.fetch_file(uri)
|
5
5
|
|
6
6
|
begin
|
7
|
-
|
7
|
+
require "progressbar" #http://github.com/nex3/ruby-progressbar
|
8
8
|
rescue LoadError
|
9
|
-
|
10
|
-
|
9
|
+
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."
|
10
|
+
exit
|
11
11
|
end
|
12
12
|
progress_bar = nil
|
13
13
|
open(uri, :proxy => nil,
|
14
14
|
:content_length_proc => lambda { |length|
|
15
15
|
if length && 0 < length
|
16
16
|
progress_bar = ProgressBar.new(uri.to_s, length)
|
17
|
+
progress_bar.file_transfer_mode #to show download speed and file size
|
17
18
|
end
|
18
19
|
},
|
19
20
|
:progress_proc => lambda { |progress|
|
@@ -33,10 +34,10 @@ class DownloadHelper
|
|
33
34
|
elsif os_has?("curl")
|
34
35
|
puts "using curl"
|
35
36
|
#-L means: follow redirects, We set an agent because Vimeo seems to want one
|
36
|
-
|
37
|
+
`curl -A 'Wget/1.8.1' -L \"#{unescaped_uri}\" -o #{file_name}`
|
37
38
|
else
|
38
|
-
|
39
|
-
open(file_name, 'wb') { |file|
|
39
|
+
puts "using net/http"
|
40
|
+
open(file_name, 'wb') { |file|
|
40
41
|
file.write(fetch_file(unescaped_uri)); puts
|
41
42
|
}
|
42
43
|
end
|
@@ -52,26 +53,29 @@ class DownloadHelper
|
|
52
53
|
end
|
53
54
|
|
54
55
|
#checks to see whether the os has a certain utility like wget or curl
|
56
|
+
#`` returns the standard output of the process
|
57
|
+
#system returns the exit code of the process
|
55
58
|
def self.os_has?(utility)
|
56
59
|
windows = ENV['OS'] =~ /windows/i
|
57
|
-
return `which #{utility}`.include?(utility) unless windows # if not Windows
|
58
60
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
61
|
+
unless windows # if os is not Windows
|
62
|
+
`which #{utility}`.include?(utility)
|
63
|
+
else
|
64
|
+
if has_where?
|
65
|
+
system("where /q #{utility}") #/q is the quiet mode flag
|
66
|
+
else
|
67
|
+
begin #as a fallback we just run the utility itself
|
68
|
+
system(utility)
|
69
|
+
rescue Errno::ENOENT
|
70
|
+
false
|
71
|
+
end
|
72
|
+
end
|
65
73
|
end
|
66
74
|
end
|
67
75
|
|
68
76
|
#checks if Windows has the where utility (Server 2003 and later)
|
77
|
+
#system only return nil if the command is not found
|
69
78
|
def self.has_where?
|
70
|
-
|
71
|
-
`where`
|
72
|
-
true
|
73
|
-
rescue Errno::ENOENT
|
74
|
-
false
|
75
|
-
end
|
79
|
+
!system("where /q where").nil?
|
76
80
|
end
|
77
|
-
end
|
81
|
+
end
|
data/helper/plugin-helper.rb
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
class PluginBase
|
2
|
-
#some static stuff
|
2
|
+
#some static stuff
|
3
3
|
class << self; attr_reader :registered_plugins end
|
4
4
|
@registered_plugins = []
|
5
5
|
|
6
|
-
#if you inherit from this class, the child gets added to the "registered plugins" array
|
6
|
+
#if you inherit from this class, the child gets added to the "registered plugins" array
|
7
7
|
def self.inherited(child)
|
8
8
|
PluginBase.registered_plugins << child
|
9
9
|
end
|
10
|
+
|
11
|
+
#takes a string a returns a new string that is file name safe
|
12
|
+
#deletes \"' and replaces anything else that is not a digit or letter with _
|
13
|
+
def self.make_filename_safe(string)
|
14
|
+
string.delete("\"'").gsub(/[^\d\w]/, '_')
|
15
|
+
end
|
10
16
|
end
|
data/plugins/blip.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
2
|
class Blip < PluginBase
|
2
3
|
# this will be called by the main app to check whether this plugin is responsible for the url passed
|
3
4
|
def self.matches_provider?(url)
|
@@ -10,7 +11,7 @@ class Blip < PluginBase
|
|
10
11
|
xml_url = "http://blip.tv/rss/#{id}"
|
11
12
|
doc = Nokogiri::XML(open(xml_url))
|
12
13
|
user = doc.at("//channel/item/blip:user").inner_text
|
13
|
-
title = doc.at("//channel/item/title").inner_text
|
14
|
+
title = PluginBase.make_filename_safe(doc.at("//channel/item/title").inner_text)
|
14
15
|
download_url = doc.at("//channel/item/media:group/media:content").attributes["url"].value
|
15
16
|
extention = download_url.split(".").last
|
16
17
|
file_name = "#{id}-#{user}-#{title}.#{extention}"
|
data/plugins/metacafe.rb
CHANGED
data/plugins/veoh.rb
CHANGED
@@ -30,9 +30,8 @@ class Veoh < PluginBase
|
|
30
30
|
#the file name string is a combination of the video name and the extension
|
31
31
|
def self.get_file_name(info_doc, download_url)
|
32
32
|
name = info_doc.xpath('//rsp/videoList/video').first.attributes['title'].content
|
33
|
-
name.gsub!(" ", "_") # replace spaces with underscores
|
34
33
|
extension = download_url[/\/[\w\d]+(\.[\w\d]+)\?ct/, 1]
|
35
|
-
name + extension
|
34
|
+
PluginBase.make_filename_safe(name) + extension
|
36
35
|
end
|
37
36
|
|
38
37
|
def self.get_attribute(format)
|
@@ -43,4 +42,4 @@ class Veoh < PluginBase
|
|
43
42
|
"previewUrl"
|
44
43
|
end
|
45
44
|
end
|
46
|
-
end
|
45
|
+
end
|
data/plugins/vimeo.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
|
2
|
+
|
2
3
|
class Vimeo < PluginBase
|
3
4
|
#this will be called by the main app to check whether this plugin is responsible for the url passed
|
4
5
|
def self.matches_provider?(url)
|
@@ -22,18 +23,12 @@ class Vimeo < PluginBase
|
|
22
23
|
timestamp = page_html[/"timestamp":(\d+),/, 1]
|
23
24
|
signature = page_html[/"signature":"([\d\w]+)",/, 1]
|
24
25
|
|
25
|
-
# The quality and codecs are listed in order of preference in the url. If HD is not availabe SD will be download for example.
|
26
26
|
redirect_url = "http://player.vimeo.com/play_redirect?clip_id=#{vimeo_id}&sig=#{signature}&time=#{timestamp}&quality=hd,sd&codecs=H264,VP8,VP6"
|
27
27
|
|
28
28
|
#the download url is the value of the location (redirect) header
|
29
29
|
download_url = agent.get(redirect_url).header["location"]
|
30
|
+
file_name = PluginBase.make_filename_safe(title) + ".mp4"
|
30
31
|
|
31
|
-
file_name = make_filename(title)
|
32
|
-
|
33
32
|
[{:url => download_url, :name => file_name}]
|
34
33
|
end
|
35
|
-
|
36
|
-
def self.make_filename(title)
|
37
|
-
title.delete("\"'").gsub(/[^\d\w]/, '_') + ".mp4"
|
38
|
-
end
|
39
|
-
end
|
34
|
+
end
|
data/plugins/youtube.rb
CHANGED
@@ -190,7 +190,7 @@ class Youtube < PluginBase
|
|
190
190
|
download_url = video_info_hash["url_encoded_fmt_stream_map"][selected_format]
|
191
191
|
#if download url ends with a ';' followed by a codec string remove that part because it stops URI.parse from working
|
192
192
|
download_url = $1 if download_url =~ /(.*?);\scodecs=/
|
193
|
-
file_name =
|
193
|
+
file_name = PluginBase.make_filename_safe(title) + "." + format_ext[selected_format][:extension]
|
194
194
|
puts "downloading to " + file_name
|
195
195
|
{:url => download_url, :name => file_name}
|
196
196
|
end
|
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: viddl-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 141
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: "0.
|
8
|
+
- 67
|
9
|
+
version: "0.67"
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Marc Seeger
|
@@ -14,7 +14,8 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2012-
|
17
|
+
date: 2012-07-03 00:00:00 +02:00
|
18
|
+
default_executable:
|
18
19
|
dependencies:
|
19
20
|
- !ruby/object:Gem::Dependency
|
20
21
|
name: nokogiri
|
@@ -109,6 +110,7 @@ files:
|
|
109
110
|
- Gemfile.lock
|
110
111
|
- Rakefile
|
111
112
|
- README.md
|
113
|
+
has_rdoc: true
|
112
114
|
homepage: https://github.com/rb2k/viddl-rb
|
113
115
|
licenses: []
|
114
116
|
|
@@ -140,10 +142,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
142
|
requirements: []
|
141
143
|
|
142
144
|
rubyforge_project: viddl-rb
|
143
|
-
rubygems_version: 1.
|
145
|
+
rubygems_version: 1.4.2
|
144
146
|
signing_key:
|
145
147
|
specification_version: 3
|
146
148
|
summary: An extendable commandline video downloader for flash video sites.
|
147
149
|
test_files: []
|
148
150
|
|
149
|
-
has_rdoc: false
|