2 # Copyright Michael Orlitzky
4 # http://michael.orlitzky.com/
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # http://www.fsf.org/licensing/licenses/gpl.html
21 class Liveleak
< Website
23 VALID_LIVELEAK_URL_REGEX
= /^(http:\/\
/)?(www\.)?liveleak\.com\/view
\?i
=.+
$/
25 def self.owns_url
?(url
)
26 return url
=~ VALID_LIVELEAK_URL_REGEX
31 page_data
= self.get_page_data(@url)
32 embed_tag
= parse_embed_tag(page_data
)
33 playlist_data
= self.get_page_data(playlist_url(embed_tag
))
35 return parse_location_from_playlist(playlist_data
)
41 def parse_embed_tag(page_data
)
42 embed_tag_regex
= /file_embed_tag%3D([[:alnum:]]+)%/
43 matches
= embed_tag_regex
.match(page_data
)
45 if matches
.nil? or matches
.length
< 2
46 return StandardError
.new("Couldn't parse the video's embed_tag.")
53 def playlist_url(embed_tag
)
54 return "http://www.liveleak.com/playlist_new.php?file_embed_tag=#{embed_tag}"
58 def parse_location_from_playlist(xml_data
)
59 file_path_regex
= /<location>(.*?)<\/location
>/
60 matches
= file_path_regex
.match(xml_data
)
63 raise StandardError
.new("Couldn't parse the <location> tag from the playlist XML file.")