Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add facebook plugin #101

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/viddl-rb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions plugins/facebook.rb
Original file line number Diff line number Diff line change
@@ -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.+>(.+)<\/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

1 change: 0 additions & 1 deletion plugins/youtube/ciphers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 8 additions & 1 deletion spec/integration/url_extraction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down