added porn-center plugin
[enigma2-plugins.git] / porncenter / src / Additions / Podcast.py
1 # podcast plugin by AliAbdul
2 from Plugin import Movie, Plugin
3 import re
4
5 ##################################################
6
7 def encodeUrl(url):
8         url = url.replace("&", "&")
9         url = url.replace("&lt;", "<")
10         url = url.replace("&gt;", ">")
11         url = url.replace("&#39;", "'")
12         url = url.replace("&quot;", '"')
13         url = url.replace("&#42;", "*")
14         url = url.replace("&#124;", "|")
15         url = url.replace("&#039;", "'")
16         url = url.replace("&#187;", ">>")
17         return url
18
19 ##################################################
20
21 class Podcast(Plugin):
22         def __init__(self, name, icon, url):
23                 self.url = url
24                 Plugin.__init__(self, name, icon)
25
26         def getEntries(self, callback):
27                 self.callback = callback
28                 self.getPage(self.url)
29
30         def getPageCallback(self, page):
31                 movies = []
32                 if page.__contains__("</title>"):
33                         page = page[page.index("</title>")+8:]
34                 reonecat = re.compile(r'<title>(.+?)</title>.+?<description>(.+?)</description>.+?<enclosure(.+?)/>.+?', re.DOTALL)\r
35                 for title, description, info in reonecat.findall(page):
36                         if title.startswith("<![CDATA["):
37                                 title = title[9:]
38                         if title.endswith("]]>"):
39                                 title = title[:-3]
40                         url = None
41                         thumb = None\r
42                         if info.__contains__('url="'):\r
43                                 idx = info.index('url="')\r
44                                 url = info[idx+5:]\r
45                                 idx = url.index('"')\r
46                                 url = url[:idx]\r
47                         if description.__contains__('img src="'):\r
48                                 idx = description.index('img src="')\r
49                                 thumb = description[idx+9:]\r
50                                 idx = thumb.index('"')\r
51                                 thumb = thumb[:idx]
52                         if url:
53                                 movies.append(Movie(encodeUrl(title), url, thumb))
54                 self.callback(movies)
55
56         def getPageError(self, error=None):
57                 if error: print error