Update NEWS for v0.9.20131130
[libquvi-scripts.git] / share / lua / website / totallynsfw.lua
Commit [+]AuthorDateLineData
62cc25f1
TG
Toni Gundogdu2011-09-19 19:39:08 +03001
2-- libquvi-scripts
01fd8f98 Toni Gundogdu2012-03-17 18:05:10 +02003-- Copyright (C) 2011-2012 quvi project
62cc25f1
TG
Toni Gundogdu2011-09-19 19:39:08 +03004--
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
e5a0d97b
TG
Toni Gundogdu2012-05-28 21:47:21 +030023local TotallyNSFW = {} -- Utility functions specific to this script
24
62cc25f1 Toni Gundogdu2011-09-19 19:39:08 +030025-- Identify the script.
01fd8f98 Toni Gundogdu2012-03-17 18:05:10 +020026function ident(self)
62cc25f1
TG
Toni Gundogdu2011-09-19 19:39:08 +030027 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'
e5a0d97b
TG
Toni Gundogdu2012-05-28 21:47:21 +030034 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
62cc25f1
TG
Toni Gundogdu2011-09-19 19:39:08 +030042 return r
43end
44
45-- Query available formats.
46function query_formats(self)
e5a0d97b
TG
Toni Gundogdu2012-05-28 21:47:21 +030047 local p = quvi.fetch(self.page_url)
48
49 if TotallyNSFW.is_external(self, p) then
50 return self
51 end
52
62cc25f1
TG
Toni Gundogdu2011-09-19 19:39:08 +030053 self.formats = 'default'
54 return self
55end
56
57-- Parse media URL.
01fd8f98 Toni Gundogdu2012-03-17 18:05:10 +020058function parse(self)
62cc25f1 Toni Gundogdu2011-09-19 19:39:08 +030059 self.host_id = "totallynsfw"
62cc25f1 Toni Gundogdu2011-09-19 19:39:08 +030060
01fd8f98 Toni Gundogdu2012-03-17 18:05:10 +020061 local p = quvi.fetch(self.page_url)
62cc25f1 Toni Gundogdu2011-09-19 19:39:08 +030062
e5a0d97b
TG
Toni Gundogdu2012-05-28 21:47:21 +030063 if TotallyNSFW.is_external(self, p) then
64 return self
65 end
66
01fd8f98
TG
Toni Gundogdu2012-03-17 18:05:10 +020067 self.title = p:match('<div class="hdr"><h2>(.-)</h2></div>')
68 or error ("no match: media title")
62cc25f1 Toni Gundogdu2011-09-19 19:39:08 +030069
01fd8f98
TG
Toni Gundogdu2012-03-17 18:05:10 +020070 local c_url = p:match('"config","(.-)"')
71 or error ("no match: config URL")
62cc25f1 Toni Gundogdu2011-09-19 19:39:08 +030072
01fd8f98
TG
Toni Gundogdu2012-03-17 18:05:10 +020073 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}
62cc25f1
TG
Toni Gundogdu2011-09-19 19:39:08 +030082
83 return self
84end
85
e5a0d97b
TG
Toni Gundogdu2012-05-28 21:47:21 +030086--
87-- Utility functions.
88--
89
90function 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
99end
100
101function 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
107end
108
62cc25f1 Toni Gundogdu2011-09-19 19:39:08 +0300109-- vim: set ts=4 sw=4 tw=72 expandtab: