added porn-center plugin
[enigma2-plugins.git] / porncenter / src / Additions / mXVideos.py
1 # mXVideos plugin by AliAbdul
2 from Plugin import Movie, Plugin
3 import re, urllib2
4
5 ##################################################
6
7 class mXVideosMovie(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'Watch Video: <a href="(.+?)">MP4</a>')
17                 list = reonecat.findall(data)
18                 if list and len(list) > 0:
19                         return "http://m.xvideos.com"+list[0]
20                 else:
21                         return None
22
23 ##################################################
24
25 class mXVideosSub(Plugin):
26         def __init__(self, name, url):
27                 self.url = url
28                 self.moreEntries = True
29                 Plugin.__init__(self, name, "mXVideos.png")
30
31         def getEntries(self, callback, currPage=1):
32                 self.currPage = currPage
33                 self.callback = callback
34                 self.getPage("http://m.xvideos.com%s/page/%d" % (self.url, self.currPage))
35
36         def getPageCallback(self, page):
37                 movies = []
38                 reonecat = re.compile(r'src="(.+?)" /></a><div class="scene_title"><a href="(.+?)"> (.+?)</a></div></div>', re.DOTALL)\r
39                 for thumb, url, name in reonecat.findall(page):
40                         movies.append(mXVideosMovie(name, "http://m.xvideos.com"+url, thumb))
41                 self.callback(movies)
42
43         def getMoreEntries(self):
44                 if self.moreEntries:
45                         self.getEntries(self.callback, self.currPage+1)
46
47         def getPageError(self, error=None):
48                 if error and self.currPage == 1:
49                         print "[%s] Error: %s" % (self.name, error)
50                 else:
51                         self.moreEntries = False
52
53 ##################################################
54
55 class mXVideos(Plugin):
56         def __init__(self):
57                 Plugin.__init__(self, "mXVideos", "mXVideos.png")
58
59         def getEntries(self, callback):
60                 self.callback = callback
61                 self.getPage("http://m.xvideos.com/tag/browse")
62
63         def getPageCallback(self, page):
64                 plugins = []
65                 idx = 0
66                 reonecat = re.compile(r'<a href="(.+?)">(.+?)</a><br />', re.DOTALL)\r
67                 for url, name in reonecat.findall(page):
68                         if idx == 0:
69                                 idx += 1
70                                 name = "Amateur"
71                         plugins.append(mXVideosSub("mXVideos - "+name, url))
72                 if len(plugins):
73                         del plugins[-1]
74                 self.callback(plugins)
75
76         def getPageError(self, error=None):
77                 if error: print "[%s] Error: %s" % (self.name, error)
78
79 ##################################################
80
81 def getPlugin():
82         return mXVideos()