]> gitweb.michael.orlitzky.com - dead/whatever-dl.git/blobdiff - src/websites/fuckedtube.rb
Added the ability to download FuckedTube (http://www.fuckedtube.com/) videos.
[dead/whatever-dl.git] / src / websites / fuckedtube.rb
diff --git a/src/websites/fuckedtube.rb b/src/websites/fuckedtube.rb
new file mode 100644 (file)
index 0000000..dfde083
--- /dev/null
@@ -0,0 +1,64 @@
+#
+# 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 Fuckedtube < Website
+
+  VALID_FUCKEDTUBE_URL_REGEX = /^(http:\/\/)?(www\.)?fuckedtube\.com\/video\/\d+\/(.+)$/
+
+  def self.owns_url?(url)
+    return url =~ VALID_FUCKEDTUBE_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
+
+
+  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 = /\?movie=([a-z0-9\-_]+\.flv)&/i
+    matches = video_url_regex.match(page_data)
+
+    if (matches.nil? || matches.length < 2)
+      raise StandardError.new('Could not find the "movie" flash variable on the page.');
+    end
+    
+    return "http://www.fuckedtube.com/videos/br_#{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