move translations to https://github.com/opendreambox/enigma2-plugins-po
[enigma2-plugins.git] / tubelib / src / plugin.py
1 from enigma import eServiceReference
2 from Plugins.Plugin import PluginDescriptor
3 from Tools.Log import Log
4
5 from ChannelListTubeServiceHelper import ChannelListTubeServiceHelper
6
7 try:
8         from enigma import eUriResolver
9         from youtube.YoutubeUriResolver import YoutubeUriResolver
10         YoutubeUriResolver.instance = YoutubeUriResolver()
11         eUriResolver.addResolver(YoutubeUriResolver.instance)
12 except ImportError as e:
13         Log.w(e)
14
15 def isBouquetAndOrRoot(csel):
16         if csel.movemode:
17                 return (False, False)
18         inBouquet = csel.getMutableList() is not None
19         current_root = csel.getRoot()
20         current_root_path = current_root and current_root.getPath()
21         inBouquetRootList = current_root_path and current_root_path.find('FROM BOUQUET "bouquets.') != -1 #FIXME HACK
22         Log.w("inBouquet: %s, current_root_path %s, inBouquetRootList %s" %(inBouquet, current_root_path, inBouquetRootList))
23         return (inBouquet, inBouquetRootList)
24
25 def check_channel(csel):
26         inBouquet, inBouquetRootList = isBouquetAndOrRoot(csel)
27         return inBouquet and not inBouquetRootList
28
29 def main_channellist(session, ref, csel, **kwargs):
30         Log.i(kwargs)
31         if ref:
32                 ChannelListTubeServiceHelper(session, csel, onChannelSelected)
33
34 def onChannelSelected(csel, data, bouquetName=None):
35         if not csel or not data:
36                 return
37         if bouquetName:
38                 csel.addBouquet(bouquetName, data)
39                 return
40         if csel.inBouquet() and data:
41                 if isinstance(data, eServiceReference):
42                         csel.addServiceToBouquet(csel.getRoot(), service=data)
43
44 def Plugins(path, **kwargs):
45         return [
46                 PluginDescriptor(
47                         name=_("Add Live-Streaming Channel"),
48                         description=_("Add Live-Streaming Channel"),
49                         where = PluginDescriptor.WHERE_CHANNEL_CONTEXT_MENU,
50                         fnc=main_channellist,
51                         helperfnc=check_channel,
52                         icon="plugin.png"),
53                 ]