]> gitweb.michael.orlitzky.com - dead/whatever-dl.git/blobdiff - lib/whatever-dl/websites/youporn.rb
Move all of the 'src' code under the more-standard 'lib'.
[dead/whatever-dl.git] / lib / whatever-dl / websites / youporn.rb
diff --git a/lib/whatever-dl/websites/youporn.rb b/lib/whatever-dl/websites/youporn.rb
new file mode 100644 (file)
index 0000000..2c453dd
--- /dev/null
@@ -0,0 +1,73 @@
+#
+# 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 Youporn < Website
+
+  VALID_YOUPORN_URL_REGEX = /^(http:\/\/)?(www\.)?youporn\.com\/watch\/(\d+)(\/.*)?$/
+  
+  def self.owns_url?(url)
+    return url =~ VALID_YOUPORN_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.
+  # They don't obfuscate it or anything, so we assume here
+  # that the first "download" url ending in ".flv" is the
+  # movie file we want.
+  def parse_video_url(page_data)    
+    flv_regex = /http:\/\/download\.youporn\.com\/.*?\.flv/
+    matches = flv_regex.match(page_data)
+    flv_url = matches[0] if not matches.nil?
+    
+    return flv_url
+  end
+
+  
+  def get_page_data(url)
+    uri = URI.parse(url)
+    
+    response = Net::HTTP.start(uri.host, uri.port) do |http|
+      # Bypass the stupid age verification.
+      form_data = 'user_choice=Enter'
+      http.post(uri.path, form_data, self.get_headers())
+    end
+    
+    return response.body
+  end
+
+  # Build the header hash from the URL we're requesting.
+  def get_headers()
+    headers = { 'Referer' => @url,
+                'Content-Type' => 'application/x-www-form-urlencoded' }
+    return headers
+  end
+
+  
+end