[WebInterface] - forward opener for externals to have access to functions of WebInterface
[enigma2-plugins.git] / src / Additions / pornrabbit.py
1 # pornrabbit plugin by AliAbdul
2 from Plugin import Movie, Plugin
3 import re, urllib2
4
5 ##################################################
6
7 class PornRabbitMovie(Movie):
8         def __init__(self, name, url, thumb):
9                 Movie.__init__(self, name, url, thumb)
10
11         def getVideoUrl(self):
12                 try:
13                         data = urllib2.urlopen(self.url).read()
14                 except:
15                         data = ""
16                 reonecat = re.compile(r'<span class="download"><a href="(.+?).mp4"')
17                 list = reonecat.findall(data)
18                 if list and len(list) > 0:
19                         return list[0]+".mp4"
20                 else:
21                         return None
22
23 ##################################################
24
25 class PornRabbitSub(Plugin):
26         def __init__(self, name, url):
27                 self.url = url
28                 self.moreEntries = True
29                 Plugin.__init__(self, name, "pornrabbit.png")
30
31         def getEntries(self, callback, currPage=1):
32                 self.currPage = currPage
33                 self.callback = callback
34                 self.getPage("http://www.pornrabbit.com%spage%d.html" % (self.url, self.currPage))
35
36         def getDetails(self, div):
37                 name = None
38                 url = None
39                 thumb = None
40                 reonecat = re.compile(r'<img src="(.+?)"(.+?)<h3>(.+?)</h3>(.+?)class="link"><a href="(.+?)"><b>Play', re.DOTALL)\r
41                 for t, x1, n, x2, u in reonecat.findall(div):
42                         name = n
43                         thumb = t
44                         url = "http://www.pornrabbit.com"+u
45                 return (name, url, thumb)
46
47         def getPageCallback(self, page):
48                 movies = []
49                 tmps = []
50                 if '<div class="video">' in page:
51                         while '<div class="video">' in page:
52                                 idx = page.index('<div class="video">')
53                                 page = page[idx:]
54                                 idx = page.index('</div>')
55                                 tmps.append(page[:idx])
56                                 page = page[idx:]\r
57                 for tmp in tmps:
58                         (name, url, thumb) = self.getDetails(tmp)
59                         if name and url and thumb:
60                                 movies.append(PornRabbitMovie(name, url, thumb))
61                 self.callback(movies)
62
63         def getMoreEntries(self):
64                 if self.moreEntries:
65                         self.getEntries(self.callback, self.currPage+1)
66
67         def getPageError(self, error=None):
68                 if error and self.currPage == 1:
69                         print "[%s] Error: %s" % (self.name, error)
70                 else:
71                         self.moreEntries = False
72
73 ##################################################
74
75 class PornRabbit(Plugin):
76         def __init__(self):
77                 Plugin.__init__(self, "Porn Rabbit", "pornrabbit.png")
78
79         def getEntries(self, callback):
80                 self.callback = callback
81                 self.getPage("http://www.pornrabbit.com/category.html")
82
83         def getDetails(self, div):
84                 name = None
85                 url = None
86                 reonecat = re.compile(r'<h3>(.+?)<span class(.+?)<a href="(.+?)"><b>', re.DOTALL)\r
87                 for n, x, u in reonecat.findall(div):
88                         name = n
89                         if len(u) > 10:
90                                 url = u[:-10]
91                 return (name, url)
92
93         def getPageCallback(self, page):
94                 plugins = []
95                 reonecat = re.compile(r'<div class="categ">(.+?)</div>', re.DOTALL)\r
96                 for tmp in reonecat.findall(page):
97                         (name, url) = self.getDetails(tmp)
98                         if name and url:
99                                 plugins.append(PornRabbitSub("Porn Rabbit - " + name, url))
100                 self.callback(plugins)
101
102         def getPageError(self, error=None):
103                 if error: print "[%s] Error: %s" % (self.name, error)
104
105 ##################################################
106
107 def getPlugin():
108         return PornRabbit()