]> gitweb.michael.orlitzky.com - dead/whatever-dl.git/commitdiff
Add support for liveleak.com.
authorMichael Orlitzky <michael@orlitzky.com>
Sun, 5 Dec 2010 01:15:25 +0000 (20:15 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Sun, 5 Dec 2010 01:15:25 +0000 (20:15 -0500)
src/websites/liveleak.rb [new file with mode: 0644]

diff --git a/src/websites/liveleak.rb b/src/websites/liveleak.rb
new file mode 100644 (file)
index 0000000..7016c04
--- /dev/null
@@ -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 'src/website'
+
+class Liveleak < Website
+
+  VALID_LIVELEAK_URL_REGEX = /^(http:\/\/)?(www\.)?liveleak\.com\/view\?i=.+$/
+
+  def self.owns_url?(url)
+    return url =~ VALID_LIVELEAK_URL_REGEX
+  end
+
+
+  def get_video_url()
+    page_data = self.get_page_data(@url)
+    embed_tag = parse_embed_tag(page_data)
+    playlist_data = self.get_page_data(playlist_url(embed_tag))
+
+    return parse_location_from_playlist(playlist_data)
+  end
+
+
+  protected;
+
+  def parse_embed_tag(page_data)
+    embed_tag_regex = /file_embed_tag%3D([[:alnum:]]+)%/
+    matches = embed_tag_regex.match(page_data)
+
+    if matches.nil? or matches.length < 2
+      return StandardError.new("Couldn't parse the video's embed_tag.")
+    end
+
+    return matches[1]
+  end
+
+
+  def playlist_url(embed_tag)
+    return "http://www.liveleak.com/playlist_new.php?file_embed_tag=#{embed_tag}"
+  end
+
+
+  def parse_location_from_playlist(xml_data)
+    file_path_regex = /<location>(.*?)<\/location>/
+    matches = file_path_regex.match(xml_data)
+
+    if matches.nil?
+      raise StandardError.new("Couldn't parse the <location> tag from the playlist XML file.")
+    end
+
+    return matches[1]
+  end
+
+end