[WebInterface] - forward opener for externals to have access to functions of WebInterface
[enigma2-plugins.git] / src / Additions / bangyoulater.py
1 # bangyoulater plugin by AliAbdul
2 from Plugin import Movie, Plugin
3 import re, urllib2
4
5 ##################################################
6
7 class bangYouLaterSub(Plugin):
8         def __init__(self, name, url):
9                 self.url = url
10                 self.moreEntries = True
11                 Plugin.__init__(self, name, "bangyoulater.png")
12
13         def getEntries(self, callback, currPage=1):
14                 self.currPage = currPage
15                 self.callback = callback
16                 self.getPage("%s/%d" % (self.url, self.currPage))
17
18         def getPageCallback(self, page):
19                 movies = []
20                 reonecat = re.compile(r'<div class="mobile_item">(.+?)</td>', re.DOTALL)
21                 for div in reonecat.findall(page):
22                         reonecat = re.compile(r'<a href="/player.php(.+?)"><img src="(.+?)" /></a>.+?margin-top: 8px;">(.+?)</div>', re.DOTALL)
23                         for url, thumb, name in reonecat.findall(div):
24                                 movies.append(Movie(name, "http://stream.bangyoulater.com/"+url[3:]+"/mobile.mp4", thumb))
25                 self.callback(movies)
26
27         def getMoreEntries(self):
28                 if self.moreEntries:
29                         self.getEntries(self.callback, self.currPage+1)
30
31         def getPageError(self, error=None):
32                 if error and self.currPage == 1:
33                         print "[%s] Error: %s" % (self.name, error)
34                 else:
35                         self.moreEntries = False
36
37 ##################################################
38
39 class bangYouLater(Plugin):
40         def __init__(self):
41                 Plugin.__init__(self, "Bang You Later", "bangyoulater.png")
42
43         def getEntries(self, callback):
44                 self.callback = callback
45                 self.getPage("http://mobile.bangyoulater.com")
46
47         def getPageCallback(self, page):
48                 plugins = []
49                 if 'Most Discussed' in page:
50                         page = page[page.index('Most Discussed'):]
51                 reonecat = re.compile(r'<option value="(.+?)">(.+?)</option>', re.DOTALL)\r
52                 for cat, name in reonecat.findall(page):
53                         plugins.append(bangYouLaterSub("Bang You Later - "+name, "http://mobile.bangyoulater.com/?cat="+cat))
54                 self.callback(plugins)
55
56         def getPageError(self, error=None):
57                 if error: print "[%s] Error: %s" % (self.name, error)
58
59 ##################################################
60
61 def getPlugin():
62         return bangYouLater()