[WebInterface] - forward opener for externals to have access to functions of WebInterface
[enigma2-plugins.git] / src / Additions / videarn.py
1 # videarn plugin by AliAbdul
2 from Plugin import Movie, Plugin
3 import re, urllib2
4
5 ##################################################
6
7 class VidearnMovie(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"<source src='(.+?)' type='video/mp4;'>")
17                 list = reonecat.findall(data)
18                 if list and len(list) > 0:
19                         return list[0]
20                 else:
21                         return None
22
23 ##################################################
24
25 class VidearnSub(Plugin):
26         def __init__(self, name, url):
27                 self.url = url
28                 self.moreEntries = True
29                 Plugin.__init__(self, name, "videarn.png")
30
31         def getEntries(self, callback, currPage=1):
32                 self.currPage = currPage
33                 self.callback = callback
34                 self.getPage("http://videarn.com/%s&page=%d" % (self.url, self.currPage))
35
36         def getPageCallback(self, page):
37                 movies = []
38                 reonecat = re.compile(r'<div class="gal">(.+?)</font></div></div></div>', re.DOTALL)\r
39                 divs = reonecat.findall(page)
40                 for div in divs:
41                         reonecat = re.compile(r'<a href="(.+?)".+?<img src="(.+?)".+?class="galtitle">(.+?)</a>', re.DOTALL)
42                         for url, thumb, name in reonecat.findall(div):
43                                 movies.append(VidearnMovie(name, "http://videarn.com/"+url, thumb))
44                 self.callback(movies)
45
46         def getMoreEntries(self):
47                 if self.moreEntries:
48                         self.getEntries(self.callback, self.currPage+1)
49
50         def getPageError(self, error=None):
51                 if error and self.currPage == 1:
52                         print "[%s] Error: %s" % (self.name, error)
53                 else:
54                         self.moreEntries = False
55
56 ##################################################
57
58 class Videarn(Plugin):
59         def __init__(self):
60                 Plugin.__init__(self, "videarn.com", "videarn.png")
61
62         def getEntries(self, callback):
63                 self.callback = callback
64                 self.getPage("http://videarn.com")
65
66         def getPageCallback(self, page):
67                 plugins = []
68                 start = "<span>Browse Videos</span>"
69                 end = "</div>"
70                 if start in page and end in page:
71                         page = page[page.index(start):]
72                         page = page[:page.index(end)]
73                         reonecat = re.compile(r'<a href="(.+?)">(.+?)</a>', re.DOTALL)\r
74                         for url, name in reonecat.findall(page):
75                                 plugins.append(VidearnSub("videarn.com - "+name, url))
76                 self.callback(plugins)
77
78         def getPageError(self, error=None):
79                 if error: print "[%s] Error: %s" % (self.name, error)
80
81 ##################################################
82
83 def getPlugin():
84         return Videarn()