]> gitweb.michael.orlitzky.com - dead/whatever-dl.git/blob - src/websites/youporn.rb
Made the output filename the responsibility of the website subclass.
[dead/whatever-dl.git] / src / websites / youporn.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 # Needed to download the page, which is in turn
22 # needed because it contains the video URL.
23 require 'net/http'
24 require 'uri'
25
26
27 class Youporn < Website
28
29 VALID_YOUPORN_URL_REGEX = /^(http:\/\/)?(www\.)?youporn\.com\/watch\/(\d+)(\/.*)?$/
30
31 def self.owns_url?(url)
32 return url =~ VALID_YOUPORN_URL_REGEX
33 end
34
35
36 def get_video_url()
37 page_data = self.get_page_data(@url)
38 video_url = self.parse_video_url(page_data)
39 return video_url
40 end
41
42
43 protected;
44
45 # Get the FLV file URL from the HTML page for this movie.
46 # They don't obfuscate it or anything, so we assume here
47 # that the first "download" url ending in ".flv" is the
48 # movie file we want.
49 def parse_video_url(page_data)
50 flv_regex = /http:\/\/download\.youporn\.com\/.*?\.flv/
51 matches = flv_regex.match(page_data)
52 flv_url = matches[0] if not matches.nil?
53
54 return flv_url
55 end
56
57
58 def get_page_data(url)
59 uri = URI.parse(url)
60
61 response = Net::HTTP.start(uri.host, uri.port) do |http|
62 # Bypass the stupid age verification.
63 form_data = 'user_choice=Enter'
64 http.post(uri.path, form_data, self.get_headers())
65 end
66
67 return response.body
68 end
69
70 # Build the header hash from the URL we're requesting.
71 def get_headers()
72 headers = { 'Referer' => @url,
73 'Content-Type' => 'application/x-www-form-urlencoded' }
74 end
75
76
77 end