]> gitweb.michael.orlitzky.com - dead/whatever-dl.git/blobdiff - lib/whatever-dl/websites/efukt.rb
Move all of the 'src' code under the more-standard 'lib'.
[dead/whatever-dl.git] / lib / whatever-dl / websites / efukt.rb
diff --git a/lib/whatever-dl/websites/efukt.rb b/lib/whatever-dl/websites/efukt.rb
new file mode 100644 (file)
index 0000000..0818eac
--- /dev/null
@@ -0,0 +1,76 @@
+#
+# 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 like 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;
+
+  def parse_video_url(page_data)
+    # Get the FLV file URL from the HTML page for this movie.
+    # It's stored in some Flash variable.
+    video_url_regex = /flashvars\.file = "(http:\/\/.*\.flv)"/i
+    matches = video_url_regex.match(page_data)
+
+    if not matches.nil? || matches.length < 2
+      return matches[1]
+    else
+      raise StandardError.new('Could not find the "file" Flash variable.');
+    end
+
+    return matches[1]
+  end
+
+
+end