diff --git a/lib/viddl-rb.rb b/lib/viddl-rb.rb
index 78150d0..a32746f 100755
--- a/lib/viddl-rb.rb
+++ b/lib/viddl-rb.rb
@@ -26,8 +26,8 @@ def self.io=(io_object)
#set the default PluginBase io object to a StringIO instance.
#this will suppress any standard output from the plugins.
self.io = StringIO.new
-
- #returns an array of hashes containing the download url(s) and filenames(s)
+
+ #returns an array of hashes containing the download url(s) and filenames(s)
#for the specified video url.
#if the url does not match any plugin, return nil and if a plugin
#throws an error, throw PluginError.
@@ -36,7 +36,7 @@ def self.io=(io_object)
def self.get_urls_names(url)
plugin = PluginBase.registered_plugins.find { |p| p.matches_provider?(url) }
- if plugin
+ if plugin
begin
#we'll end up with an array of hashes with they keys :url and :name
urls_filenames = plugin.get_urls_and_filenames(url)
diff --git a/plugins/facebook.rb b/plugins/facebook.rb
new file mode 100755
index 0000000..5326b65
--- /dev/null
+++ b/plugins/facebook.rb
@@ -0,0 +1,25 @@
+require 'uri'
+require 'cgi'
+
+class Facebook < PluginBase
+
+ #this will be called by the main app to check whether this plugin is responsible for the url passed
+ def self.matches_provider?(url)
+ url.include?("facebook.com")
+ end
+
+ def self.get_urls_and_filenames(url, options = {})
+ video_page = open(url).read
+
+ title = video_page.scan(/
(.+)<\/title>/).flatten.first
+
+ download_url = video_page[/https.*.mp4/].gsub(/\\u([\da-fA-F]{4})/) {|m| [$1].pack("H*").unpack("n*").pack("U*")}
+ download_url = CGI::unescape(download_url)
+ download_url = URI::extract(download_url.gsub('\\', '')).first
+
+ file_name = PluginBase.make_filename_safe(title) + '.mp4'
+
+ [{:url => download_url, :name => file_name}]
+ end
+end
+
diff --git a/plugins/youtube/ciphers.yml b/plugins/youtube/ciphers.yml
index eadad85..d6d25fb 100644
--- a/plugins/youtube/ciphers.yml
+++ b/plugins/youtube/ciphers.yml
@@ -97,4 +97,3 @@ en_US-vflbJnZqE: w26 s1 w15 w3 w62 w54 w22
en_US-vflgd5txb: w26 s1 w15 w3 w62 w54 w22
en_US-vflTm330y: w26 s1 w15 w3 w62 w54 w22
en_US-vflnwMARr: s3 r w24 s2
-en_US-vflaTh7jt: w46 r s3 w19 r s2 w15
diff --git a/spec/integration/url_extraction_spec.rb b/spec/integration/url_extraction_spec.rb
index d0c7977..bdbd862 100755
--- a/spec/integration/url_extraction_spec.rb
+++ b/spec/integration/url_extraction_spec.rb
@@ -102,6 +102,12 @@ def test_instagram
can_download_test(result) { |url_output| http_code_grabber(CGI::unescape(url_output), {:method => :get}) }
end
+ def test_facebook
+ result = `ruby bin/viddl-rb "https://www.facebook.com/photo.php?v=101503003357454&set=vb.310080259100701&type=2&theater" --url-only`
+ assert_equal $?, 0
+ can_download_test(result) { |url_output| http_code_grabber(CGI::unescape(url_output), {:method => :get}) }
+ end
+
# NOTE: The Metacafe tests are skipped because plugin is currently broken.
def test_metacafe
@@ -131,7 +137,8 @@ def test_dailymotion_hq
def can_download_test(result, &grabber)
url_output = result.split("\n").last
- assert_includes(CGI.unescape(url_output), 'http://')
+ # Assert url includes http:// or https://
+ assert((CGI.unescape(url_output) =~ /https?:\/\//) != nil)
code_grabber = grabber || proc { |url_output| http_code_grabber(url_output) }
tries = 0
http_response_code = 0