/
MetrixHDPrimeTime.py
59 lines (49 loc) · 1.54 KB
/
MetrixHDPrimeTime.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from datetime import datetime
from time import localtime, mktime, time
from enigma import eLabel, eEPGCache
from Components.config import config
from Components.Renderer.Renderer import Renderer
from Components.VariableText import VariableText
class MetrixHDPrimeTime(Renderer, VariableText):
def __init__(self):
Renderer.__init__(self)
VariableText.__init__(self)
self.epgcache = eEPGCache.getInstance()
GUI_WIDGET = eLabel
def changed(self, what):
event = self.source.event
if event is None:
self.text = ""
return
service = self.source.service
text = ""
evt = None
if self.epgcache is not None:
evt = self.epgcache.lookupEvent(['IBDCT', (service.toString(), 0, -1, -1)])
if evt:
now = localtime(time())
try:
hour, minute = config.epgselection.graph_primetimehour.value, config.epgselection.graph_primetimemins.value
except Exception:
hour, minute = 20, 15
dt = datetime(now.tm_year, now.tm_mon, now.tm_mday, hour, minute)
primetime = int(mktime(dt.timetuple()))
next = False
for x in evt:
if x[4]:
begin = x[1]
end = x[1] + x[2]
if begin <= primetime and end > primetime or next:
if not next and end <= primetime + 1200: # 20 mins tolerance to starting next event
next = True
continue
t = localtime(begin)
text = text + "%02d:%02d %s\n" % (t[3], t[4], x[4])
break
if begin > primetime: # entry > primetime ? -> primetime not in epg
text = text + "n/a"
break
else:
text = text + "n/a"
break
self.text = text