add audiotrackactive for identifying active audiotrack
[enigma2-plugins.git] / webinterface / src / WebComponents / Sources / AudioTracks.py
1 from Components.Sources.Source import Source
2 from Tools.ISO639 import LanguageCodes
3
4 class AudioTracks( Source ):
5     
6     def __init__(self, session):
7         self.session = session
8         Source.__init__(self)
9         
10     def getList(self):
11         service = self.session.nav.getCurrentService()
12         audio = service and service.audioTracks()
13         currentTrack = audio.getCurrentTrack()
14         n = audio and audio.getNumberOfTracks() or 0
15         tlist = []
16
17         if n > 0:
18             print "[AudioTracks.py] got %s Audiotracks!" %(n)
19             
20             for x in range(n):
21                 i = audio.getTrackInfo(x)
22                 for name in dir(i):
23                     print getattr(i, name)
24                 language = i.getLanguage()
25                 description = i.getDescription()
26                 pid = i.getPID()
27                 
28                 if LanguageCodes.has_key(language):
29                     language = LanguageCodes[language][0]
30                 
31                 if len(description):
32                     description += " (" + language + ")"
33                 else:
34                     description = language
35                 
36                 if x == currentTrack:
37                     active = "True"
38                 else:
39                     active = "False"
40                 
41                 tlist.append((description, x, pid, active))
42         
43         return tlist
44     
45     list = property(getList)
46     lut = {"Description": 0, "Id": 1, "Pid": 2, "Active": 3}