0824deb72badba463ded3c8f4e52308d3b97d0b2
[openblackhole/openblackhole-enigma2.git] / lib / python / Components / Converter / TransponderInfo.py
1 # -*- coding: utf-8 -*-
2 from Components.Converter.Converter import Converter
3 from enigma import iServiceInformation, iPlayableService, iPlayableServicePtr, eServiceCenter
4 from Components.Element import cached
5 from ServiceReference import resolveAlternate,  ServiceReference
6 from Tools.Transponder import ConvertToHumanReadable, getChannelNumber
7 from Components.NimManager import nimmanager
8 import Screens.InfoBar
9
10 class TransponderInfo(Converter, object):
11         def __init__(self, type):
12                 Converter.__init__(self, type)
13                 self.type = type.split(";")
14
15         @cached
16         def getText(self):
17                 service = self.source.service
18                 if isinstance(service, iPlayableServicePtr):
19                         info = service and service.info()
20                         ref = None
21                 else: # reference
22                         info = service and self.source.info
23                         ref = service
24                 if not info:
25                         return ""
26                 if ref:
27                         nref = resolveAlternate(ref)
28                         if nref:
29                                 ref = nref
30                                 info = eServiceCenter.getInstance().info(ref)
31                         transponderraw = info.getInfoObject(ref, iServiceInformation.sTransponderData)
32                 else:
33                         transponderraw = info.getInfoObject(iServiceInformation.sTransponderData)
34                 if "InRootOnly" in self.type and not self.rootBouquet():
35                         return ""
36                 if "NoRoot" in self.type and self.rootBouquet():
37                         return ""
38                 if transponderraw:
39                         transponderdata = ConvertToHumanReadable(transponderraw)
40                         if not transponderdata["system"]:
41                                 transponderdata["system"] = transponderraw.get("tuner_type", "None")
42                         if not transponderdata["system"]:
43                                 return ""
44                         if "DVB-T" in transponderdata["system"]:
45                                 return "%s %s %d MHz %s" % (transponderdata["system"], transponderdata["channel"], transponderdata["frequency"]/1000000 + 0.5 , transponderdata["bandwidth"])
46                         elif "DVB-C" in transponderdata["system"]:
47                                 return "%s %d MHz %d %s %s" % (transponderdata["system"], transponderdata["frequency"]/1000 + 0.5, transponderdata["symbol_rate"]/1000 + 0.5, transponderdata["fec_inner"], \
48                                         transponderdata["modulation"])
49                         return "%s %d %s %d %s %s %s" % (transponderdata["system"], transponderdata["frequency"]/1000 + 0.5, transponderdata["polarization_abbreviation"], transponderdata["symbol_rate"]/1000 + 0.5, \
50                                 transponderdata["fec_inner"], transponderdata["modulation"], transponderdata["detailed_satpos" in self.type and "orbital_position" or "orb_pos"])
51                 if ref:
52                         result = ref.toString()
53                 else:
54                         result = info.getInfoString(iServiceInformation.sServiceref)
55                 if "%3a//" in result:
56                         return _("Stream") + " " + result.rsplit("%3a//", 1)[1].split("/")[0]
57                 return ""
58
59         text = property(getText)
60
61         def rootBouquet(self):
62                 servicelist = Screens.InfoBar.InfoBar.instance.servicelist
63                 epg_bouquet = servicelist and servicelist.getRoot()
64                 if ServiceReference(epg_bouquet).getServiceName():
65                         return False
66                 return True
67
68         def changed(self, what):
69                 if what[0] != self.CHANGED_SPECIFIC or what[1] in (iPlayableService.evStart,):
70                         Converter.changed(self, what)
71