RefToPiconName: small fix
[enigma2-plugins.git] / reftopiconname / src / RefToPiconName.py
1 # -*- coding: utf-8 -*-
2 #
3 # ServiceReference to PiconName  - Converter
4 #
5 # Coded by dre (c) 2014 - 2016
6 # Support: www.dreambox-tools.info
7 # E-Mail: dre@dreambox-tools.info
8 #
9 # This plugin is open source but it is NOT free software.
10 #
11 # This plugin may only be distributed to and executed on hardware which
12 # is licensed by Dream Multimedia GmbH.
13 # In other words:
14 # It's NOT allowed to distribute any parts of this plugin or its source code in ANY way
15 # to hardware which is NOT licensed by Dream Multimedia GmbH.
16 # It's NOT allowed to execute this plugin and its source code or even parts of it in ANY way
17 # on hardware which is NOT licensed by Dream Multimedia GmbH.
18 #
19 # If you want to use or modify the code or parts of it,
20 # you have to keep MY license and inform me about the modifications by mail.
21 #
22
23 from Components.Converter.Converter import Converter
24 from Components.Element import cached
25 from enigma import eServiceCenter, eServiceReference, iPlayableServicePtr, iServiceInformation
26
27 class RefToPiconName(Converter, object):
28         def __init__(self, type):
29                 Converter.__init__(self, type)
30
31         @cached
32         def getText(self):
33                 ref = self.source.service
34                 
35                 if ref is not None:
36                         if not isinstance(ref, iPlayableServicePtr):
37                                 #bouquet or marker
38                                 if ref.flags & (eServiceReference.isDirectory|eServiceReference.isMarker):
39                                         info = eServiceCenter.getInstance().info(ref)
40                                         if info:
41                                                 return info.getName(ref).replace(" ","_")
42                                 #alternatives
43                                 elif ref.flags & (eServiceReference.isGroup):
44                                         return eServiceCenter.getInstance().list(ref).getContent("S")[0]
45                                 #channel
46                                 return ref.toString()
47                         else:
48                                 info = ref and ref.info()
49                                 service = None
50                         
51                                 if info:
52                                         sRef = service and info.getInfoString(service, iServiceInformation.sServiceRef) or info.getInfoString(iServiceInformation.sServiceref)
53                                         if sRef is None or sRef is "":
54                                                 return info.getName().replace(" ","_")
55                                         else:
56                                                 return sRef
57                 
58         text = property(getText)