]> gitweb.michael.orlitzky.com - dead/whatever-dl.git/blob - src/websites/liveleak.rb
Add support for liveleak.com.
[dead/whatever-dl.git] / src / websites / liveleak.rb
1 #
2 # Copyright Michael Orlitzky
3 #
4 # http://michael.orlitzky.com/
5 #
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.
10 #
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.
15 #
16 # http://www.fsf.org/licensing/licenses/gpl.html
17 #
18
19 require 'src/website'
20
21 class Liveleak < Website
22
23 VALID_LIVELEAK_URL_REGEX = /^(http:\/\/)?(www\.)?liveleak\.com\/view\?i=.+$/
24
25 def self.owns_url?(url)
26 return url =~ VALID_LIVELEAK_URL_REGEX
27 end
28
29
30 def get_video_url()
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))
34
35 return parse_location_from_playlist(playlist_data)
36 end
37
38
39 protected;
40
41 def parse_embed_tag(page_data)
42 embed_tag_regex = /file_embed_tag%3D([[:alnum:]]+)%/
43 matches = embed_tag_regex.match(page_data)
44
45 if matches.nil? or matches.length < 2
46 return StandardError.new("Couldn't parse the video's embed_tag.")
47 end
48
49 return matches[1]
50 end
51
52
53 def playlist_url(embed_tag)
54 return "http://www.liveleak.com/playlist_new.php?file_embed_tag=#{embed_tag}"
55 end
56
57
58 def parse_location_from_playlist(xml_data)
59 file_path_regex = /<location>(.*?)<\/location>/
60 matches = file_path_regex.match(xml_data)
61
62 if matches.nil?
63 raise StandardError.new("Couldn't parse the <location> tag from the playlist XML file.")
64 end
65
66 return matches[1]
67 end
68
69 end