moviesearch: serienfilm-plugin support
[enigma2-plugins.git] / moviesearch / src / plugin.py
1 from Plugins.Plugin import PluginDescriptor
2 from NTIVirtualKeyBoard import NTIVirtualKeyBoard
3 from Tools.BoundFunction import boundFunction
4 from Screens.MessageBox import MessageBox
5 from enigma import eServiceCenter, eServiceReference, \
6                 iStaticServiceInformationPtr
7
8 titleCmp = lambda x, y: x.lower() in y.lower() # force case-insensitive for now
9
10 def vkCallback(movieContextMenu, searchString=None):
11         isEmc = False
12         if not movieContextMenu: return
13         else:
14                 if hasattr(movieContextMenu, 'csel'):
15                         csel = movieContextMenu.csel
16                 else: #if hasattr(cur_dialog, 'mlist'):
17                         csel = movieContextMenu.mlist
18                         isEmc = True
19         if not searchString:
20                 if isEmc: csel.reload(csel.loadPath)
21                 else: csel.reloadList()
22                 return movieContextMenu.close()
23
24         if isEmc:
25                 serviceHandler = eServiceCenter.getInstance()
26                 movieList = csel.list
27                 newList = []
28                 for movie in movieList:
29                         # we have no idea what this input could be, just add it back
30                         if len(movie) != 8: newList.append(movie)
31                         else:
32                                 if not isinstance(movie[0], eServiceReference): newList.append(movie)
33                                 else:
34                                         info = serviceHandler.info(movie[0])
35                                         if not info: newList.append(movie)
36                                         else:
37                                                 name = info.getName(movie[0])
38                                                 if titleCmp(searchString, name): newList.append(movie)
39                 csel.list = newList
40                 csel.l.setList(newList)
41         else:
42                 movieList = csel["list"].list
43                 newList = []
44                 for movie in movieList:
45                         # we have no idea what this input could be, just add it back
46                         if len(movie) < 2: newList.append(movie)
47                         else:
48                                 if len(movie) == 4 and isinstance(movie[3], list): # assume serienfilm-plugin
49                                         tinfo = movie[3]
50                                         type = tinfo[0]
51                                         if type == 0:
52                                                 name = movie[1].getName(movie[0])
53                                                 if titleCmp(searchString, name): newList.append(movie)
54                                         elif type == 4:
55                                                 if titleCmp(searchString, tinfo[2]): newList.append(movie)
56                                         else:
57                                                 newList.append(movie)
58                                 elif isinstance(movie[0], eServiceReference) and isinstance(movie[1], iStaticServiceInformationPtr):
59                                         name = movie[1].getName(movie[0])
60                                         if titleCmp(searchString, name): newList.append(movie)
61                                 else:
62                                         newList.append(movie)
63                 csel["list"].list = newList
64                 csel["list"].l.setList(newList)
65         movieContextMenu.close()
66
67 def main(session, service, **kwargs):
68         cur_dialog = session.current_dialog
69         if hasattr(cur_dialog, 'csel'):
70                 csel = session.current_dialog.csel
71                 if not "list" in csel:
72                         print "[MovieSearch] No list, goodbye!"
73                         csel = None
74         elif hasattr(cur_dialog, 'mlist'):
75                 csel = cur_dialog.mlist
76         else:
77                 print "[MovieSearch] Unknown current dialog of type", type(cur_dialog)
78                 csel = None
79
80         if csel is not None:
81                 session.openWithCallback(
82                                 boundFunction(vkCallback, session.current_dialog),
83                                 NTIVirtualKeyBoard,
84                                 title=_("Enter text to search for")
85                 )
86         else:
87                 session.open(
88                         MessageBox,
89                         _("Improperly launched plugin.\nAborting!"),
90                         type = MessageBox.TYPE_ERROR
91                 )
92
93
94 def Plugins(**kwargs):
95         return PluginDescriptor(name="MovieSearch", description=_("search..."), where=PluginDescriptor.WHERE_MOVIELIST, fnc=main)
96