Update NEWS for v0.9.20131130
[libquvi-scripts.git] / share / lua / website / totallynsfw.lua
1
2 -- libquvi-scripts
3 -- Copyright (C) 2011-2012 quvi project
4 --
5 -- This file is part of libquvi-scripts <http://quvi.sourceforge.net/>.
6 --
7 -- This library is free software; you can redistribute it and/or
8 -- modify it under the terms of the GNU Lesser General Public
9 -- License as published by the Free Software Foundation; either
10 -- version 2.1 of the License, or (at your option) any later version.
11 --
12 -- This library is distributed in the hope that it will be useful,
13 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
14 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 -- Lesser General Public License for more details.
16 --
17 -- You should have received a copy of the GNU Lesser General Public
18 -- License along with this library; if not, write to the Free Software
19 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 -- 02110-1301 USA
21 --
22
23 local TotallyNSFW = {} -- Utility functions specific to this script
24
25 -- Identify the script.
26 function ident(self)
27 package.path = self.script_dir .. '/?.lua'
28 local C = require 'quvi/const'
29 local r = {}
30 r.domain = "totallynsfw%.com"
31 r.formats = "default"
32 r.categories = C.proto_http
33 local U = require 'quvi/util'
34 local is_rss = U.handles(self.page_url, {r.domain},
35 {"/videos/rss_2%.0/?"})
36 if is_rss then -- Don't try to handle the RSS feeds
37 r.handles = false
38 else
39 r.handles = U.handles(self.page_url, {r.domain},
40 {"/videos/.-", "/nsfw/"})
41 end
42 return r
43 end
44
45 -- Query available formats.
46 function query_formats(self)
47 local p = quvi.fetch(self.page_url)
48
49 if TotallyNSFW.is_external(self, p) then
50 return self
51 end
52
53 self.formats = 'default'
54 return self
55 end
56
57 -- Parse media URL.
58 function parse(self)
59 self.host_id = "totallynsfw"
60
61 local p = quvi.fetch(self.page_url)
62
63 if TotallyNSFW.is_external(self, p) then
64 return self
65 end
66
67 self.title = p:match('<div class="hdr"><h2>(.-)</h2></div>')
68 or error ("no match: media title")
69
70 local c_url = p:match('"config","(.-)"')
71 or error ("no match: config URL")
72
73 self.id = c_url:match("config_jwplayer_test/(.-)/")
74 or error ("no match: media id")
75
76 local c = quvi.fetch(c_url, {fetch_type='config'})
77
78 local s = c:match('<file>(.-)</file>')
79 or error ("no match: media url")
80
81 self.url = {s}
82
83 return self
84 end
85
86 --
87 -- Utility functions.
88 --
89
90 function TotallyNSFW.is_external(self, page)
91 local u = page:match('options=(.-)"')
92 if u then
93 if TotallyNSFW.is_hosted_at_pornhub(self, u) then
94 return true
95 end
96 -- Add more below if necessary.
97 end
98 return false
99 end
100
101 function TotallyNSFW.is_hosted_at_pornhub(self, url)
102 if url:match('pornhub%.com/embed_player') then
103 local c = quvi.fetch(url, {fetch_type='config'})
104 self.redirect_url = c:match('<link_url>(.-)<') or ''
105 end
106 return #self.redirect_url >0
107 end
108
109 -- vim: set ts=4 sw=4 tw=72 expandtab: