-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEventList.py
92 lines (84 loc) · 2.96 KB
/
EventList.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# -*- coding: utf-8 -*-
#
# EventList - Converter
#
# Coded by Dr.Best (c) 2013
# Support: www.dreambox-tools.info
# E-Mail: [email protected]
#
# This plugin is open source but it is NOT free software.
#
# This plugin may only be distributed to and executed on hardware which
# is licensed by Dream Property GmbH.
# In other words:
# It's NOT allowed to distribute any parts of this plugin or its source code in ANY way
# to hardware which is NOT licensed by Dream Property GmbH.
# It's NOT allowed to execute this plugin and its source code or even parts of it in ANY way
# on hardware which is NOT licensed by Dream Property GmbH.
#
# If you want to use or modify the code or parts of it,
# you have to keep MY license and inform me about the modifications by mail.
#
from Components.Converter.Converter import Converter
from Components.Element import cached
from enigma import eEPGCache, eServiceReference
from time import localtime, strftime, mktime, time
from datetime import datetime, timedelta
class EventList(Converter, object):
def __init__(self, type):
Converter.__init__(self, type)
self.epgcache = eEPGCache.getInstance()
self.primetime = 0
self.eventcount = 0
self.beginOnly = False
if (len(type)):
args = type.split(',')
i = 0
while i <= len(args) - 1:
type_c, value = args[i].split('=')
if type_c == "eventcount":
self.eventcount = int(value)
elif type_c == "primetime":
if value == "yes":
self.primetime = 1
elif type_c == "beginOnly":
if value == "yes":
self.beginOnly = True
i += 1
@cached
def getContent(self):
contentList = []
ref = self.source.service
info = ref and self.source.info
if info is None:
return []
event = self.source.getCurrentEvent()
if not event:
return contentList
i = 1
while i <= (self.eventcount) and event:
event = self.epgcache.lookupEventTime(eServiceReference(ref.toString()), event.getBeginTime() + event.getDuration())
if event:
contentList.append(self.getEventTuple(event),)
i += 1
if self.primetime == 1:
now = localtime(time())
dt = datetime(now.tm_year, now.tm_mon, now.tm_mday, 20, 15)
if time() > mktime(dt.timetuple()):
dt += timedelta(days=1) # skip to next day...
primeTime = int(mktime(dt.timetuple()))
event = self.epgcache.lookupEventTime(eServiceReference(ref.toString()), primeTime)
if event and (event.getBeginTime() <= int(mktime(dt.timetuple()))):
contentList.append(self.getEventTuple(event),)
return contentList
def getEventTuple(self, event):
if self.beginOnly:
time = "%s" % ( strftime("%H:%M", localtime(event.getBeginTime())), )
else:
time = "%s - %s" % (strftime("%H:%M", localtime(event.getBeginTime())), strftime("%H:%M", localtime(event.getBeginTime() + event.getDuration())))
title = event.getEventName()
duration = "%d min" % (event.getDuration() / 60)
return (time, title, duration)
def changed(self, what):
if what[0] != self.CHANGED_SPECIFIC:
Converter.changed(self, what)