- save service names in xml,
[enigma2-plugins.git] / epgrefresh / src / plugin.py
1 # Config
2 from Components.config import config, ConfigEnableDisable, ConfigInteger, ConfigSubsection, ConfigClock
3
4 # Calculate default begin/end
5 from time import time, localtime, mktime
6 now = localtime()
7 begin = mktime((now.tm_year, now.tm_mon, now.tm_mday, 20, 15, 0, now.tm_wday, now.tm_yday, now.tm_isdst))
8 end = mktime((now.tm_year, now.tm_mon, now.tm_mday, 06, 30, 0, now.tm_wday, now.tm_yday, now.tm_isdst))
9
10 config.plugins.epgrefresh = ConfigSubsection()
11 config.plugins.epgrefresh.enabled = ConfigEnableDisable(default = False)
12 config.plugins.epgrefresh.begin = ConfigClock(default = int(begin))
13 config.plugins.epgrefresh.end = ConfigClock(default = int(end))
14 config.plugins.epgrefresh.interval = ConfigInteger(default = 2, limits=(1, 10))
15 config.plugins.epgrefresh.delay_standby = ConfigInteger(default = 10, limits=(1, 60))
16 config.plugins.epgrefresh.inherit_autotimer = ConfigEnableDisable(default = False)
17 config.plugins.epgrefresh.afterevent = ConfigEnableDisable(default = False)
18 config.plugins.epgrefresh.force = ConfigEnableDisable(default = False)
19 config.plugins.epgrefresh.lastscan = ConfigInteger(default = 0)
20
21 del now, begin, end
22
23 # Plugin
24 from EPGRefresh import epgrefresh
25 from EPGRefreshConfiguration import EPGRefreshConfiguration
26
27 # Plugin definition
28 from Plugins.Plugin import PluginDescriptor
29
30 # Autostart
31 def autostart(reason, **kwargs):
32         if config.plugins.epgrefresh.enabled.value and reason == 0 and kwargs.has_key("session"):
33                 epgrefresh.start(kwargs["session"])
34
35         elif reason == 1:
36                 epgrefresh.stop()
37
38 def getNextWakeup():
39         # Return invalid time if not automatically refreshing
40         if not config.plugins.epgrefresh.enabled.value:
41                 return -1
42         now = localtime()
43         begin = int(mktime(
44                 (now.tm_year, now.tm_mon, now.tm_mday,
45                 config.plugins.epgrefresh.begin.value[0],
46                 config.plugins.epgrefresh.begin.value[1],
47                 0, now.tm_wday, now.tm_yday, now.tm_isdst)
48         ))
49         # todays timespan has not yet begun
50         if begin > time():
51                 return begin
52         # otherwise add 1 day
53         return begin+86400
54
55 # Mainfunction
56 def main(session, **kwargs):
57         epgrefresh.stop()
58         session.openWithCallback(
59                 doneConfiguring,
60                 EPGRefreshConfiguration
61         )
62
63 def doneConfiguring(session, **kwargs):
64         if config.plugins.epgrefresh.enabled.value:
65                 epgrefresh.start(session)
66
67 def Plugins(**kwargs):
68         return [
69                 PluginDescriptor(name="EPGRefresh", description = "Automated EPGRefresher", where = [PluginDescriptor.WHERE_AUTOSTART, PluginDescriptor.WHERE_SESSIONSTART], fnc = autostart, wakeupfnc = getNextWakeup),
70                 PluginDescriptor(name="EPGRefresh", description = "Automated EPGRefresher", where = PluginDescriptor.WHERE_PLUGINMENU, fnc = main)
71         ]