3 -- Copyright (C) 2011-2012 quvi project
5 -- This file is part of libquvi-scripts <http://quvi.sourceforge.net/>.
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.
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.
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
23 local TotallyNSFW
= {} -- Utility functions specific to this script
25 -- Identify the script.
27 package
.path
= self
.script_dir
.. '/?.lua'
28 local C
= require
'quvi/const'
30 r
.domain
= "totallynsfw%.com"
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
39 r
.handles
= U
.handles(self
.page_url
, {r
.domain
},
40 {"/videos/.-", "/nsfw/"})
45 -- Query available formats.
46 function query_formats(self
)
47 local p
= quvi
.fetch(self
.page_url
)
49 if TotallyNSFW
.is_external(self
, p
) then
53 self
.formats
= 'default'
59 self
.host_id
= "totallynsfw"
61 local p
= quvi
.fetch(self
.page_url
)
63 if TotallyNSFW
.is_external(self
, p
) then
67 self
.title
= p
:match('<div class="hdr"><h2>(.-)</h2></div>')
68 or error ("no match: media title")
70 local c_url
= p
:match('"config","(.-)"')
71 or error ("no match: config URL")
73 self
.id
= c_url
:match("config_jwplayer_test/(.-)/")
74 or error ("no match: media id")
76 local c
= quvi
.fetch(c_url
, {fetch_type
='config'})
78 local s
= c
:match('<file>(.-)</file>')
79 or error ("no match: media url")
90 function TotallyNSFW
.is_external(self
, page
)
91 local u
= page
:match('options=(.-)"')
93 if TotallyNSFW
.is_hosted_at_pornhub(self
, u
) then
96 -- Add more below if necessary.
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 ''
106 return #self
.redirect_url
>0
109 -- vim: set ts=4 sw=4 tw=72 expandtab: