Reformed channel selection, and added location and tag filter to movie list
[vuplus_dvbapp-plugin] / webinterface / src / WebComponents / Sources / LocationsAndTags.py
1 from Components.Sources.Source import Source
2 from Components.config import config
3
4 class LocationsAndTags(Source):
5     CURRLOCATION = 0
6     LOCATIONS = 1
7     TAGS = 2
8     
9     def __init__(self, session, func):
10         self.func = func
11         Source.__init__(self)        
12         self.session = session
13         self.result = False,"one two three four unknown command"
14
15     def handleCommand(self, cmd):
16         if self.func is self.CURRLOCATION:
17             self.result = [self.getCurrentLocation()]
18         elif self.func is self.LOCATIONS:
19             self.result = self.getLocations()
20         elif self.func is self.TAGS:
21             self.result = self.getTags()
22         else:
23             self.result = False
24
25     def getCurrentLocation(self):
26         return config.movielist.last_videodir.value
27
28     def getLocations(self):
29         return config.movielist.videodirs.value
30
31     def getTags(self):
32         try:
33             file = open("/etc/enigma2/movietags")
34             tags = [x.rstrip() for x in file.readlines()]
35             while "" in tags:
36                 tags.remove("")
37             file.close()
38         except IOError, ioe:
39             tags = []
40         return tags
41
42     def getText(self):
43         self.handleCommand(None)
44         print self.result
45         lst = self.result
46         xml  = "<e2simplexmllist>\n"
47         if self.result:
48             for ele in self.result:
49                 xml += "<e2simplexmlitem>%s</e2simplexmlitem>\n"%ele
50         xml += "</e2simplexmllist>\n"
51         return xml
52     
53     text = property(getText)