From 5359bc2a58320794c5d6d91acb39eac4f371c9c2 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Mon, 10 Nov 2008 20:34:43 -0500 Subject: [PATCH] Added the ability to download videos from http://www.efukt.com/. --- src/websites/efukt.rb | 85 ++++ test/efukt_test.rb | 69 +++ .../2304_The_Dumbest_Porno_Ever_Made.html | 402 ++++++++++++++++++ test/test_suite.rb | 1 + 4 files changed, 557 insertions(+) create mode 100644 src/websites/efukt.rb create mode 100644 test/efukt_test.rb create mode 100644 test/fixtures/efukt/2304_The_Dumbest_Porno_Ever_Made.html diff --git a/src/websites/efukt.rb b/src/websites/efukt.rb new file mode 100644 index 0000000..f4cc58d --- /dev/null +++ b/src/websites/efukt.rb @@ -0,0 +1,85 @@ +# +# Copyright Michael Orlitzky +# +# http://michael.orlitzky.com/ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# http://www.fsf.org/licensing/licenses/gpl.html +# + +require 'src/website' + +class Efukt < Website + + VALID_EFUKT_URL_REGEX = /^(http:\/\/)?(www\.)?efukt\.com\/\d+(.+)$/ + + def self.owns_url?(url) + return url =~ VALID_EFUKT_URL_REGEX + end + + + def get_video_url() + page_data = self.get_page_data(@url) + video_url = self.parse_video_url(page_data) + return video_url + end + + + def get_video_filename() + # Default to whatever comes before the + # final-period-after-the-final-frontslash in the main URL. This is + # better than the superclass method because it doesn't rely on the + # network. + filename = @url.split('/').pop().split('.')[0] + + # Most of the URLs will just be the video's id, + # followed by an underscore and the video title (with + # all spaces replaced by underscores. Sounds look a good + # filename to me. + filename_regex = /\/([[:alnum:]_]+)\.html/ + matches = filename_regex.match(@url) + + # Overwrite the default if our regex worked. + filename = matches[1] if not (matches.nil? || matches.length < 1) + + return (filename + '.flv') + end + + + protected; + + # Get the FLV file URL from the HTML page for this movie. + # It's stored in some Flash variable. + def parse_video_url(page_data) + video_url_regex = /&file=(http:\/\/.*\.flv)&/i + matches = video_url_regex.match(page_data) + + if (matches.nil? || matches.length < 2) + raise StandardError.new('Could not find the "file" flash variable on the page.'); + end + + return matches[1] + end + + + # Just make a normal HTTP "get" request. + def get_page_data(url) + uri = URI.parse(url) + + response = Net::HTTP.start(uri.host, uri.port) do |http| + http.get(uri.path) + end + + return response.body + end + +end diff --git a/test/efukt_test.rb b/test/efukt_test.rb new file mode 100644 index 0000000..33b1bf2 --- /dev/null +++ b/test/efukt_test.rb @@ -0,0 +1,69 @@ +# +# Copyright Michael Orlitzky +# +# http://michael.orlitzky.com/ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# http://www.fsf.org/licensing/licenses/gpl.html +# + +require 'test/unit' +require 'src/websites/efukt' + + +class EfuktTest < Test::Unit::TestCase + + def test_owns_efukt_urls + assert(Efukt.owns_url?('http://www.efukt.com/2308_How_To_Fuck_Like_A_King.html')) + assert(Efukt.owns_url?('http://www.efukt.com/2304_The_Dumbest_Porno_Ever_Made.html')) + end + + def test_doesnt_own_infoq_urls + assert(!Efukt.owns_url?('http://www.infoq.com/interviews/jim-weirich-discusses-rake')) + end + + + def test_get_video_filename_works_on_good_urls + ef = Efukt.new('http://www.efukt.com/2308_How_To_Fuck_Like_A_King.html') + expected_filename = '2308_How_To_Fuck_Like_A_King.flv' + actual_filename = ef.get_video_filename() + assert_equal(expected_filename, actual_filename) + end + + + def test_get_video_filename_works_on_weird_urls + # The regex looks for an html extension, so this should + # not match. Instead, it should fall back on everything + # between the final slash and that last period. In this + # case, the filename should be the same as if the extension + # were html. + ef = Efukt.new('http://www.efukt.com/2308_How_To_Fuck_Like_A_King.broken') + expected_filename = '2308_How_To_Fuck_Like_A_King.flv' + actual_filename = ef.get_video_filename() + assert_equal(expected_filename, actual_filename) + end + + + def test_parse_video_url + ef = Efukt.new(nil) + + page_data = nil + + File.open('test/fixtures/efukt/2304_The_Dumbest_Porno_Ever_Made.html') do |f| + page_data = f.read + end + + test_result = ef.send('parse_video_url', page_data) + assert_equal('http://64.62.222.195/video/370c4a4662071261ccd5b833c4d83201/4918d88d/63563562.flv', test_result) + end + +end diff --git a/test/fixtures/efukt/2304_The_Dumbest_Porno_Ever_Made.html b/test/fixtures/efukt/2304_The_Dumbest_Porno_Ever_Made.html new file mode 100644 index 0000000..5c72ebc --- /dev/null +++ b/test/fixtures/efukt/2304_The_Dumbest_Porno_Ever_Made.html @@ -0,0 +1,402 @@ + + + + + + +eFukt.com - porn you wish you never saw - The Dumbest Porno Ever Made + + + + + + + + + + + + + + + + + +
+
+
THIS SITE IS STRICTLY FOR ADULTS. IF YOU ARE NOT 18 THEN GET THE FUCK OUT!
+ +
+
+

Fuck Buddies!

+
+
+ +
+
+

Webcams

+
+
+
+
+
+ + + +
+ +
+

"The Dumbest Porno Ever Made"

+
She gets raped... by an alien-infected talking tree named Tildar. Pretty much the same shit as in Evil Dead 1, except this has penetration shots and ninchucks. Need I say more?
+
+
+ + +
+
+ +
------------------------------------- RANDOM VIDS -------------------------------------
+
Phone Sex Slut +Korean Deflowering +Assholes Get Owned +Emotional Orgasm 3 +She Nearly Dies While Cumming +Boobs Pt. 2 +
My Sexy Girlfriend +Hairiest Woman Ever +Deflowering A Nun +Anal Attempt On Drunken Slut +Cop Groped By Naked Chick +Colin Farrell Eating Pussy +
+ +
------------------------------- FUCKED UP FAVORITES -------------------------------
+
Deaf Girl Wants To Be A Pornstar +Drunken Slut Has Hilarious Disaster +Dying Orgasm +She Cums Nine Times +Oh Noes The Condom Broke! +Insane Sex Show +
Worlds Biggest Cock +Pornstar Attacks Male Performer +Attack Of The Horny Lifeguard +Good Porn Ruined By Shitty Music +Tricked Into Having Gay Sex +How To Make A Girl Cum +
+
+ + + + + + + + + + + + +
+ +
+
+ +
+
+
+ +
+ + + + diff --git a/test/test_suite.rb b/test/test_suite.rb index 8987178..41f1f8c 100644 --- a/test/test_suite.rb +++ b/test/test_suite.rb @@ -16,6 +16,7 @@ # http://www.fsf.org/licensing/licenses/gpl.html # +require 'test/efukt_test' require 'test/howcast_test' require 'test/infoq_test' require 'test/redtube_test' -- 2.43.2