IMDb: fix runtime parsing
[enigma2-plugins.git] / epgsearch / src / plugin.py
1 from enigma import eServiceCenter
2 from Components.config import config
3
4 # Plugin
5 from EPGSearch import EPGSearch, EPGSearchEPGSelection, searchEvent, pzyP4TInit, autoTimerAvailable
6 from EPGSearchFilter import searchEventWithFilter, addSearchFilterFromMovieList
7
8 # Plugin definition
9 from Plugins.Plugin import PluginDescriptor
10
11 # Autostart
12 def autostart(reason, **kwargs):
13         if reason == 0:
14                 try:
15                         # for blue and audio key activating in EPG-Screens
16                         pzyP4TInit()
17                 except Exception:
18                         import traceback
19                         traceback.print_exc()
20
21 # Mainfunction
22 def main(session, *args, **kwargs):
23         s = session.nav.getCurrentService()
24         if s:
25                 info = s.info()
26                 event = info.getEvent(0) # 0 = now, 1 = next
27                 name = event and event.getEventName() or ''
28                 session.open(EPGSearch, name, config.plugins.epgsearch.add_history_onOpen.value)
29         else:
30                 session.open(EPGSearch)
31
32 # Event Info
33 def eventinfo(session, *args, **kwargs):
34         ref = session.nav.getCurrentlyPlayingServiceReference()
35         session.open(EPGSearchEPGSelection, ref, True)
36
37 # Movielist
38 def movielist(session, service, **kwargs):
39         serviceHandler = eServiceCenter.getInstance()
40         info = serviceHandler.info(service)
41         name = info and info.getName(service) or ''
42
43         session.open(EPGSearch, name, config.plugins.epgsearch.add_history_onOpen.value)
44
45 def openHistory(session, event, service):
46         kwargs = {"startWithHistory": True}
47         session.open(EPGSearch, **kwargs)
48
49 def Plugins(**kwargs):
50         
51         l = [PluginDescriptor(
52                 where = PluginDescriptor.WHERE_AUTOSTART,
53                 fnc = autostart, needsRestart = False)]
54         
55         l.append(PluginDescriptor(
56                 name = "EPGSearch", 
57                 # TRANSLATORS: description of EPGSearch in PluginBrowser
58                 description = _("Search EPG"),
59                 where = PluginDescriptor.WHERE_PLUGINMENU,
60                 fnc = main, icon = "EPGSearch.png", needsRestart = False))
61         
62         l.append(PluginDescriptor(
63                 # TRANSLATORS: EPGSearch title in EventInfo dialog (requires the user to select an event to search for)
64                 name = _("search EPG..."),
65                 where = PluginDescriptor.WHERE_EVENTINFO,
66                 fnc = eventinfo, needsRestart = False))
67         
68         l.append(PluginDescriptor(
69                 # TRANSLATORS: EPGSearch title in MovieList (does not require further user interaction)
70                 description = _("Search EPG"),
71                 where = PluginDescriptor.WHERE_MOVIELIST,
72                 fnc = movielist, needsRestart = False))
73         
74         searchEventDescriptors = []
75         if config.plugins.epgsearch.searchEPG_menu.value in ("all", "blue"):
76                 searchEventDescriptors = [PluginDescriptor.WHERE_EPG_SELECTION_SINGLE_BLUE, PluginDescriptor.WHERE_EVENTVIEW]
77         if config.plugins.epgsearch.searchEPG_menu.value in ("all", "red"):
78                 searchEventDescriptors.append(PluginDescriptor.WHERE_CHANNEL_SELECTION_RED)
79         if searchEventDescriptors:
80                 l.append(PluginDescriptor(
81                         name=_("Search EPG"), 
82                         where = searchEventDescriptors, 
83                         fnc = searchEvent))
84
85         openHistoryDescriptors = []
86         if config.plugins.epgsearch.openSearchFilter_menu.value in ("all", "blue"):
87                 openHistoryDescriptors = [PluginDescriptor.WHERE_EPG_SELECTION_SINGLE_BLUE, PluginDescriptor.WHERE_EVENTVIEW]
88         if config.plugins.epgsearch.openSearchFilter_menu.value in ("all", "red"):
89                 openHistoryDescriptors.append(PluginDescriptor.WHERE_CHANNEL_SELECTION_RED)
90         if openHistoryDescriptors:
91                 l.append(PluginDescriptor(
92                         name=_("open EPGSearch search list"),
93                         where = openHistoryDescriptors,
94                         fnc = openHistory))
95         
96         #add only if AutoTimer-Plugin is found
97         if autoTimerAvailable:
98                 l.append(PluginDescriptor(
99                         name=_("add search filter to EPGSearch"),
100                         description= _("add search filter to EPGSearch"),
101                         where = [PluginDescriptor.WHERE_MOVIELIST],
102                         fnc = addSearchFilterFromMovieList))
103         
104                 searchEventWithFilterDescriptors = []
105                 if config.plugins.epgsearch.addSearchFilter_menu.value in ("all", "blue"):
106                         searchEventWithFilterDescriptors = [PluginDescriptor.WHERE_EPG_SELECTION_SINGLE_BLUE, PluginDescriptor.WHERE_EVENTVIEW]
107                 if config.plugins.epgsearch.addSearchFilter_menu.value in ("all", "red"):
108                                 searchEventWithFilterDescriptors.append(PluginDescriptor.WHERE_CHANNEL_SELECTION_RED)
109                 if searchEventWithFilterDescriptors:
110                         l.append(PluginDescriptor(
111                                 name=_("add search filter to EPGSearch"),
112                                 where = searchEventWithFilterDescriptors,
113                                 fnc = searchEventWithFilter))
114         
115         return l
116