viddl-rb 0.5.4 → 0.5.5

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.md CHANGED
@@ -28,7 +28,7 @@ __Requirements:__
28
28
 
29
29
  __Contributors:__
30
30
 
31
- * [kl](https://github.com/kl): Windows support (who knew!), bug fixes, veoh plugin
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
34
  * [Serabe](https://github.com/Serabe) aka Sergio Arbeo: packaging viddl as a binary
@@ -32,6 +32,7 @@ class DownloadHelper
32
32
  #-L means: follow redirects, We set an agent because Vimeo seems to want one
33
33
  result = system("curl -A 'Wget/1.8.1' -L \"#{unescaped_uri}\" -o #{file_name}")
34
34
  else
35
+ puts "using net/http"
35
36
  open(file_name, 'wb') { |file|
36
37
  file.write(fetch_file(unescaped_uri)); puts
37
38
  }
@@ -41,12 +42,13 @@ class DownloadHelper
41
42
  end
42
43
 
43
44
  #checks to see whether the os has a certain utility like wget or curl
44
- def self.os_has?(utility, windows = (ENV['OS'] =~ /windows/i))
45
+ def self.os_has?(utility)
46
+ windows = ENV['OS'] =~ /windows/i
45
47
  unless windows # if os is something else than Windows
46
48
  return `which #{utility}`.include?(utility)
47
- else
49
+ else # OS is Windows
48
50
  begin
49
- `#{utility}` #if running the command does not throw an error, Windows has it
51
+ `#{utility} --version` #if running the command does not throw an error, Windows has it. --version is for prettier console output.
50
52
  return true
51
53
  rescue Errno::ENOENT
52
54
  return false
@@ -0,0 +1,62 @@
1
+ # Note: unfortunaley, only videos that are hosted on Metacafe.com's content server can be downloaded.
2
+ # They have an URL that looks somehting like this: http://www.metacafe.com/watch/7731483/
3
+ # Vidoes that have URLs that look like this: http://www.metacafe.com/watch/cb-q78rA_lp9s1_9EJsqKJ5BdIHdDNuHa1l/ cannot be downloaded.
4
+ require 'cgi'
5
+
6
+ class Metacafe < PluginBase
7
+ BASE_FILE_URL = "http://v.mccont.com/ItemFiles/%5BFrom%20www.metacafe.com%5D%20"
8
+ API_BASE = "http://www.metacafe.com/api/"
9
+
10
+ #this will be called by the main app to check whether this plugin is responsible for the url passed
11
+ def self.matches_provider?(url)
12
+ url.include?("metacafe.com")
13
+ end
14
+
15
+ def self.get_urls_and_filenames(url)
16
+ video_id = get_video_id(url)
17
+ info_url = API_BASE + "item/#{video_id}" #use the API to get the full video url
18
+ info_doc = Nokogiri::XML(open(info_url))
19
+
20
+ video_swf_url = get_video_swf_url(info_doc, video_id)
21
+
22
+ #by getting the video swf url we get a http redirect url with all info needed
23
+ http_response = Net::HTTP.get_response(URI(video_swf_url))
24
+ redirect_url = http_response['location']
25
+
26
+ file_info = get_file_info(redirect_url, video_id)
27
+ key_string = get_file_key(redirect_url)
28
+ file_url_with_key = file_info[:file_url] + "?__gda__=#{key_string}"
29
+ escaped_url = CGI::escape(file_url_with_key)
30
+
31
+ [{:url => escaped_url, :name => get_video_name(video_swf_url) + file_info[:extension]}]
32
+ end
33
+
34
+ def self.get_video_id(url)
35
+ id = url[/watch\/(\d+)/, 1]
36
+ unless id
37
+ puts "ERROR: Can only download videos that has the ID in the URL."
38
+ exit
39
+ end
40
+ id
41
+ end
42
+
43
+ def self.get_video_swf_url(info_doc, video_id)
44
+ video_url = info_doc.xpath("//rss/channel/item/link").text
45
+ video_url.sub!("watch", "fplayer")
46
+ video_url.sub!(/\/\z/, ".swf") # remove last '/' and add .swf in it's place
47
+ end
48
+
49
+ #$1 = file name part 1, $2 = file name part 2, $3 = file extension
50
+ def self.get_file_info(redirect_url, video_id)
51
+ redirect_url =~ /mediaURL.+?metacafe\.com%.+?%\d+\.(\d+)\.(\d+)(\.[\d\w]+)/
52
+ {:file_url => "#{BASE_FILE_URL}#{video_id}\.#{$1}\.#{$2}#{$3}", :extension => $3}
53
+ end
54
+
55
+ def self.get_file_key(redirect_url)
56
+ redirect_url[/key.+?\%22([\w\d]+?)\%22/, 1]
57
+ end
58
+
59
+ def self.get_video_name(url)
60
+ url[/fplayer\/\d+\/([\d\w]+)\.swf/, 1]
61
+ end
62
+ end
data/plugins/veoh.rb CHANGED
@@ -26,7 +26,7 @@ class Veoh < PluginBase
26
26
  return(download_attr.content) unless download_attr.nil? || download_attr.content.empty?
27
27
  end
28
28
  end
29
-
29
+
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
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: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 4
10
- version: 0.5.4
9
+ - 5
10
+ version: 0.5.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Marc Seeger
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-24 00:00:00 Z
18
+ date: 2011-11-25 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: nokogiri
@@ -87,12 +87,12 @@ files:
87
87
  - helper/plugin-helper.rb
88
88
  - plugins/blip.rb
89
89
  - plugins/megavideo.rb
90
+ - plugins/metacafe.rb
90
91
  - plugins/veoh.rb
91
92
  - plugins/vimeo.rb
92
93
  - plugins/youtube.rb
93
94
  - CHANGELOG.txt
94
95
  - Gemfile
95
- - Gemfile.lock
96
96
  - Rakefile
97
97
  - README.md
98
98
  homepage: https://github.com/rb2k/viddl-rb
data/Gemfile.lock DELETED
@@ -1,21 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- viddl-rb (0.5.2)
5
- nokogiri
6
-
7
- GEM
8
- specs:
9
- mime-types (1.17.2)
10
- minitest (2.8.1)
11
- nokogiri (1.5.0)
12
- rest-client (1.6.7)
13
- mime-types (>= 1.16)
14
-
15
- PLATFORMS
16
- ruby
17
-
18
- DEPENDENCIES
19
- minitest
20
- rest-client
21
- viddl-rb!