Tools/Directories.py: Get rid of "fallback" in resolveFilename
[openblackhole/openblackhole-enigma2.git] / ServiceReference.py
1 from enigma import eServiceReference, eServiceCenter, getBestPlayableServiceReference
2 import NavigationInstance
3
4 class ServiceReference(eServiceReference):
5         def __init__(self, ref, reftype = eServiceReference.idInvalid, flags = 0, path = ''):
6                 if reftype != eServiceReference.idInvalid:
7                         self.ref = eServiceReference(reftype, flags, path)
8                 elif not isinstance(ref, eServiceReference):
9                         self.ref = eServiceReference(ref or "")
10                 else:
11                         self.ref = ref
12                 self.serviceHandler = eServiceCenter.getInstance()
13
14         def __str__(self):
15                 return self.ref.toString()
16
17         def getServiceName(self):
18                 info = self.info()
19                 return info and info.getName(self.ref) or ""
20
21         def info(self):
22                 return self.serviceHandler.info(self.ref)
23
24         def list(self):
25                 return self.serviceHandler.list(self.ref)
26
27         def getType(self):
28                 return self.ref.type
29
30         def getPath(self):
31                 return self.ref.getPath()
32
33         def getFlags(self):
34                 return self.ref.flags
35
36         def isRecordable(self):
37                 ref = self.ref
38                 return ref.flags & eServiceReference.isGroup or (ref.type == eServiceReference.idDVB or ref.type == eServiceReference.idDVB + 0x100 or ref.type == 0x2000 or ref.type == 0x1001)
39
40 def getPlayingref(ref):
41         playingref = None
42         if NavigationInstance.instance:
43                 playingref = NavigationInstance.instance.getCurrentlyPlayingServiceReference()
44         if not playingref:
45                 playingref = eServiceReference()
46         return playingref
47
48 def isPlayableForCur(ref):
49         info = eServiceCenter.getInstance().info(ref)
50         return info and info.isPlayable(ref, getPlayingref(ref))
51
52 def resolveAlternate(ref):
53         nref = None
54         if ref.flags & eServiceReference.isGroup:
55                 nref = getBestPlayableServiceReference(ref, getPlayingref(ref))
56                 if not nref:
57                         nref = getBestPlayableServiceReference(ref,
58                          eServiceReference(), True)
59         return nref