add MyVideo to EasyMedia
[enigma2-plugins.git] / easymedia / src / plugin.py
1 #######################################################################
2 #
3 #    EasyMedia for Dreambox-Enigma2
4 #    Coded by Vali (c)2010
5 #    Support: www.dreambox-tools.info
6 #
7 #
8 #  This plugin is licensed under the Creative Commons 
9 #  Attribution-NonCommercial-ShareAlike 3.0 Unported License.
10 #  To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/
11 #  or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
12 #
13 #  Alternatively, this plugin may be distributed and executed on hardware which
14 #  is licensed by Dream Multimedia GmbH.
15 #
16 #
17 #  This plugin is NOT free software. It is open source, you are allowed to
18 #  modify it (if you keep the license), but it may not be commercially 
19 #  distributed other than under the conditions noted above.
20 #
21 #
22 #######################################################################
23
24
25
26 from __init__ import _
27 from Screens.Screen import Screen
28 from Screens.MessageBox import MessageBox
29 from Screens.InfoBarGenerics import InfoBarPlugins
30 from Screens.InfoBar import InfoBar
31 from Screens.ChoiceBox import ChoiceBox
32 from Plugins.Plugin import PluginDescriptor
33 from Components.ActionMap import ActionMap
34 from Components.MenuList import MenuList
35 from Components.ConfigList import ConfigListScreen
36 from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigSelection
37 from Tools.Directories import fileExists
38 from Tools.LoadPixmap import LoadPixmap
39 from enigma import RT_HALIGN_LEFT, eListboxPythonMultiContent, gFont, getDesktop
40
41
42
43 EMbaseInfoBarPlugins__init__ = None
44 EMStartOnlyOneTime = False
45 EMsession = None
46 InfoBar_instance = None
47
48
49
50 config.plugins.easyMedia  = ConfigSubsection()
51 config.plugins.easyMedia.music = ConfigSelection(default="mediaplayer", choices = [("no", _("Disabled")), ("mediaplayer", _("MediaPlayer")), ("merlinmp", _("MerlinMusicPlayer"))])
52 config.plugins.easyMedia.files = ConfigSelection(default="dreamexplorer", choices = [("no", _("Disabled")), ("filebrowser", _("Filebrowser")), ("dreamexplorer", _("DreamExplorer")), ("tuxcom", _("TuxCom"))])
53 config.plugins.easyMedia.bookmarks = ConfigSelection(default="no", choices = [("no", _("Disabled")), ("yes", _("Enabled"))])
54 config.plugins.easyMedia.mytube = ConfigSelection(default="no", choices = [("no", _("Disabled")), ("yes", _("Enabled"))])
55 config.plugins.easyMedia.vlc = ConfigSelection(default="no", choices = [("no", _("Disabled")), ("yes", _("Enabled"))])
56 config.plugins.easyMedia.dvd = ConfigSelection(default="no", choices = [("no", _("Disabled")), ("yes", _("Enabled"))])
57 config.plugins.easyMedia.weather = ConfigSelection(default="yes", choices = [("no", _("Disabled")), ("yes", _("Enabled"))])
58 config.plugins.easyMedia.iradio = ConfigSelection(default="no", choices = [("no", _("Disabled")), ("yes", _("Enabled"))])
59 config.plugins.easyMedia.idream = ConfigSelection(default="no", choices = [("no", _("Disabled")), ("yes", _("Enabled"))])
60 config.plugins.easyMedia.zdfmedia = ConfigSelection(default="no", choices = [("no", _("Disabled")), ("yes", _("Enabled"))])
61 config.plugins.easyMedia.radio = ConfigSelection(default="yes", choices = [("no", _("Disabled")), ("yes", _("Enabled"))])
62 config.plugins.easyMedia.myvideo = ConfigSelection(default="no", choices = [("no", _("Disabled")), ("yes", _("Enabled"))])
63
64
65
66 def Plugins(**kwargs):
67         return [PluginDescriptor(where = PluginDescriptor.WHERE_SESSIONSTART, fnc = EasyMediaAutostart),
68                         PluginDescriptor(name="EasyMedia", description=_("Not easy way to start EasyMedia"), where = PluginDescriptor.WHERE_PLUGINMENU, fnc=notEasy),]
69
70
71
72 def EasyMediaAutostart(reason, **kwargs):
73         global EMbaseInfoBarPlugins__init__
74         if "session" in kwargs:
75                 global EMsession
76                 EMsession = kwargs["session"]
77                 if EMbaseInfoBarPlugins__init__ is None:
78                         EMbaseInfoBarPlugins__init__ = InfoBarPlugins.__init__
79                 InfoBarPlugins.__init__ = InfoBarPlugins__init__
80                 InfoBarPlugins.pvr = pvr
81
82
83
84 def InfoBarPlugins__init__(self):
85         global EMStartOnlyOneTime
86         if not EMStartOnlyOneTime: 
87                 EMStartOnlyOneTime = True
88                 global InfoBar_instance
89                 InfoBar_instance = self
90                 self["EasyMediaActions"] = ActionMap(["EasyMediaActions"],
91                         {"video_but": self.pvr}, -1)
92         else:
93                 InfoBarPlugins.__init__ = InfoBarPlugins.__init__
94                 InfoBarPlugins.pvr = None
95         EMbaseInfoBarPlugins__init__(self)
96
97
98
99 def pvr(self):
100         self.session.openWithCallback(MPcallbackFunc, EasyMedia)
101
102
103
104 def notEasy(session, **kwargs):
105         session.openWithCallback(MPcallbackFunc, EasyMedia)
106
107
108
109 def MPanelEntryComponent(key, text):
110         res = [ text ]
111         res.append((eListboxPythonMultiContent.TYPE_TEXT, 160, 15, 300, 60, 0, RT_HALIGN_LEFT, text[0]))
112         png = LoadPixmap('/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/' + key + ".png")
113         if png is not None:
114                 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 30, 5, 100, 50, png))
115         return res
116
117
118
119 class MPanelList(MenuList):
120         def __init__(self, list, selection = 0, enableWrapAround=True):
121                 MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
122                 self.l.setFont(0, gFont("Regular", 24))
123                 self.l.setItemHeight(60)
124                 self.selection = selection
125         def postWidgetCreate(self, instance):
126                 MenuList.postWidgetCreate(self, instance)
127                 self.moveToIndex(self.selection)
128
129
130
131 def BookmarksCallback(choice):
132         choice = choice and choice[1]
133         if choice:
134                 config.movielist.last_videodir.value = choice
135                 config.movielist.last_videodir.save()
136                 if InfoBar_instance:
137                         InfoBar_instance.showMovies()
138
139
140
141 def TvRadioCallback(choice):
142         choice = choice and choice[1]
143         if choice == "TM":
144                 if InfoBar_instance:
145                         InfoBar_instance.showTv()
146         elif choice == "RM":
147                 if InfoBar_instance:
148                         InfoBar_instance.showRadio()
149
150
151
152 class ConfigEasyMedia(ConfigListScreen, Screen):
153         skin = """
154                 <screen name="ConfigEasyMedia" position="center,center" size="600,410" title="EasyMedia settings...">
155                         <widget name="config" position="5,5" scrollbarMode="showOnDemand" size="590,380"/>
156                         <eLabel font="Regular;20" foregroundColor="#00ff4A3C" halign="center" position="20,388" size="120,26" text="Cancel"/>
157                         <eLabel font="Regular;20" foregroundColor="#0056C856" halign="center" position="165,388" size="120,26" text="Save"/>
158                 </screen>"""
159         def __init__(self, session):
160                 Screen.__init__(self, session)
161                 self.setTitle(_("EasyMedia settings..."))
162                 list = []
163                 list.append(getConfigListEntry(_("Music player:"), config.plugins.easyMedia.music))
164                 list.append(getConfigListEntry(_("Files browser:"), config.plugins.easyMedia.files))
165                 list.append(getConfigListEntry(_("Show bookmarks:"), config.plugins.easyMedia.bookmarks))
166                 list.append(getConfigListEntry(_("Show tv/radio switch:"), config.plugins.easyMedia.radio))
167                 list.append(getConfigListEntry(_("YouTube player:"), config.plugins.easyMedia.mytube))
168                 list.append(getConfigListEntry(_("VLC player:"), config.plugins.easyMedia.vlc))
169                 list.append(getConfigListEntry(_("DVD player:"), config.plugins.easyMedia.dvd))
170                 list.append(getConfigListEntry(_("Weather plugin:"), config.plugins.easyMedia.weather))
171                 list.append(getConfigListEntry(_("NetRadio player:"), config.plugins.easyMedia.iradio))
172                 list.append(getConfigListEntry(_("Show Merlin-iDream:"), config.plugins.easyMedia.idream))
173                 list.append(getConfigListEntry(_("ZDFmediathek player:"), config.plugins.easyMedia.zdfmedia))
174                 list.append(getConfigListEntry(_("MyVideo player:"), config.plugins.easyMedia.myvideo))
175                 ConfigListScreen.__init__(self, list)
176                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"], {"green": self.save, "red": self.exit, "cancel": self.exit}, -1)
177
178         def save(self):
179                 for x in self["config"].list:
180                         x[1].save()
181                 self.close()
182
183         def exit(self):
184                 for x in self["config"].list:
185                         x[1].cancel()
186                 self.close()
187
188
189
190 class EasyMedia(Screen):
191         sz_w = getDesktop(0).size().width()
192         if sz_w > 1100:
193                 skin = """
194                 <screen flags="wfNoBorder" position="0,0" size="450,720" title="Easy Media">
195                         <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/bg.png" position="0,0" size="450,576"/>
196                         <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/bg.png" position="0,576" size="450,145"/>
197                         <widget name="list" position="60,30" size="350,660" scrollbarMode="showNever" transparent="1" zPosition="2"/>
198                 </screen>"""
199         elif sz_w > 1000:
200                 skin = """
201                 <screen flags="wfNoBorder" position="-20,0" size="450,576" title="Easy Media">
202                         <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/bg.png" position="0,0" size="450,576"/>
203                         <widget name="list" position="70,48" size="320,480" scrollbarMode="showNever" transparent="1" zPosition="2"/>
204                 </screen>"""
205         else:
206                 skin = """
207                 <screen position="center,center" size="320,440" title="Easy Media">
208                         <widget name="list" position="10,10" size="300,420" scrollbarMode="showOnDemand" />
209                 </screen>"""
210         def __init__(self, session):
211                 Screen.__init__(self, session)
212                 self.session = session
213                 self.list = []
214                 self.__keys = []
215                 MPaskList = []
216                 if True:
217                         self.__keys.append("movies")
218                         MPaskList.append((_("Movies"), "PLAYMOVIES"))
219                 if config.plugins.easyMedia.bookmarks.value != "no":
220                         self.__keys.append("bookmarks")
221                         MPaskList.append((_("Bookmarks"), "BOOKMARKS"))
222                 if True:
223                         self.__keys.append("pictures")
224                         MPaskList.append((_("Pictures"), "PICTURES"))
225                 if config.plugins.easyMedia.music.value != "no":
226                         self.__keys.append("music")
227                         MPaskList.append((_("Music"), "MUSIC"))
228                 if config.plugins.easyMedia.radio.value != "no":
229                         self.__keys.append("radio")
230                         MPaskList.append((_("Tv/Radio"), "RADIO"))
231                 if config.plugins.easyMedia.dvd.value != "no":
232                         self.__keys.append("dvd")
233                         MPaskList.append((_("DVD Player"), "DVD"))
234                 if config.plugins.easyMedia.weather.value != "no":
235                         self.__keys.append("weather")
236                         MPaskList.append((_("Weather"), "WEATHER"))
237                 if config.plugins.easyMedia.files.value != "no":
238                         self.__keys.append("files")
239                         MPaskList.append((_("Files"), "FILES"))
240                 if config.plugins.easyMedia.iradio.value != "no":
241                         self.__keys.append("shoutcast")
242                         MPaskList.append((_("SHOUTcast"), "SHOUTCAST"))
243                 if config.plugins.easyMedia.idream.value != "no":
244                         self.__keys.append("idream")
245                         MPaskList.append((_("iDream"), "IDREAM"))
246                 if config.plugins.easyMedia.mytube.value != "no":
247                         self.__keys.append("mytube")
248                         MPaskList.append((_("MyTube Player"), "MYTUBE"))
249                 if config.plugins.easyMedia.vlc.value != "no":
250                         self.__keys.append("vlc")
251                         MPaskList.append((_("VLC Player"), "VLC"))
252                 if config.plugins.easyMedia.zdfmedia.value != "no":
253                         self.__keys.append("zdf")
254                         MPaskList.append((_("ZDFmediathek"), "ZDF"))
255                 if config.plugins.easyMedia.myvideo.value != "no":
256                         self.__keys.append("myvideo")
257                         MPaskList.append((_("MyVideo"), "MYVIDEO"))
258                 self.keymap = {}
259                 pos = 0
260                 for x in MPaskList:
261                         strpos = str(self.__keys[pos])
262                         self.list.append(MPanelEntryComponent(key = strpos, text = x))
263                         if self.__keys[pos] != "":
264                                 self.keymap[self.__keys[pos]] = MPaskList[pos]
265                         pos += 1
266                 self["list"] = MPanelList(list = self.list, selection = 0)
267                 self["actions"] = ActionMap(["WizardActions", "MenuActions"],
268                 {
269                         "ok": self.go,
270                         "back": self.cancel,
271                         "menu": self.emContextMenu
272                 }, -1)
273
274         def cancel(self):
275                 self.close(None)
276
277         def go(self):
278                 cursel = self["list"].l.getCurrentSelection()
279                 if cursel:
280                         self.goEntry(cursel[0])
281                 else:
282                         self.cancel()
283
284         def goEntry(self, entry):
285                 if len(entry) > 2 and isinstance(entry[1], str) and entry[1] == "CALLFUNC":
286                         arg = self["list"].l.getCurrentSelection()[0]
287                         entry[2](arg)
288                 else:
289                         self.close(entry)
290
291         def emContextMenu(self):
292                 self.session.open(ConfigEasyMedia)
293
294
295
296 def MPcallbackFunc(answer):
297         answer = answer and answer[1]
298         if answer == "PLAYMOVIES":
299                 if InfoBar_instance:
300                         InfoBar_instance.showMovies()
301         elif answer == "RADIO":
302                 askBM = []
303                 askBM.append((_("TV-mode"), "TM"))
304                 askBM.append((_("Radio-mode"), "RM"))
305                 askBM.append((_("Nothing"), "NO"))
306                 EMsession.openWithCallback(TvRadioCallback, ChoiceBox, title="EasyMedia...", list = askBM)
307         elif answer == "BOOKMARKS":
308                 tmpBookmarks = config.movielist.videodirs
309                 myBookmarks = tmpBookmarks and tmpBookmarks.value[:] or []
310                 if len(myBookmarks)>0:
311                         askBM = []
312                         for s in myBookmarks:
313                                 askBM.append((s, s))
314                         EMsession.openWithCallback(BookmarksCallback, ChoiceBox, title=_("Select bookmark..."), list = askBM)
315         elif answer == "PICTURES":
316                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/PicturePlayer/plugin.pyo"):
317                         from Plugins.Extensions.PicturePlayer.plugin import picshow
318                         EMsession.open(picshow)
319                 else:
320                         EMsession.open(MessageBox, text = _('Picture-player is not installed!'), type = MessageBox.TYPE_ERROR)
321         elif answer == "MUSIC":
322                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MerlinMusicPlayer/plugin.pyo") and (config.plugins.easyMedia.music.value == "merlinmp"):
323                         from Plugins.Extensions.MerlinMusicPlayer.plugin import MerlinMusicPlayerFileList
324                         servicelist = None
325                         EMsession.open(MerlinMusicPlayerFileList, servicelist)
326                 elif fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MediaPlayer/plugin.pyo") and (config.plugins.easyMedia.music.value == "mediaplayer"):
327                         from Plugins.Extensions.MediaPlayer.plugin import MediaPlayer
328                         EMsession.open(MediaPlayer)
329                 else:
330                         EMsession.open(MessageBox, text = _('No Music-Player installed!'), type = MessageBox.TYPE_ERROR)
331         elif answer == "FILES":
332                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/Tuxcom/plugin.pyo") and (config.plugins.easyMedia.files.value == "tuxcom"):
333                         from Plugins.Extensions.Tuxcom.plugin import TuxComStarter
334                         EMsession.open(TuxComStarter)
335                 elif fileExists("/usr/lib/enigma2/python/Plugins/Extensions/DreamExplorer/plugin.pyo") and (config.plugins.easyMedia.files.value == "dreamexplorer"):
336                         from Plugins.Extensions.DreamExplorer.plugin import DreamExplorerII
337                         EMsession.open(DreamExplorerII)
338                 elif fileExists("/usr/lib/enigma2/python/Plugins/Extensions/Filebrowser/plugin.pyo") and (config.plugins.easyMedia.files.value == "filebrowser"):
339                         from Plugins.Extensions.Filebrowser.plugin import FilebrowserScreen
340                         EMsession.open(FilebrowserScreen)
341                 else:
342                         EMsession.open(MessageBox, text = _('No File-Manager installed!'), type = MessageBox.TYPE_ERROR)
343         elif answer == "WEATHER":
344                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/WeatherPlugin/plugin.pyo"):
345                         from Plugins.Extensions.WeatherPlugin.plugin import WeatherPlugin
346                         EMsession.open(WeatherPlugin)
347                 else:
348                         EMsession.open(MessageBox, text = _('Weather Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
349         elif answer == "DVD":
350                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/DVDPlayer/plugin.pyo"):
351                         from Plugins.Extensions.DVDPlayer.plugin import DVDPlayer
352                         EMsession.open(DVDPlayer)
353                 else:
354                         EMsession.open(MessageBox, text = _('DVDPlayer Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
355         elif answer == "MYTUBE":
356                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MyTube/plugin.pyo"):
357                         from Plugins.Extensions.MyTube.plugin import *
358                         MyTubeMain(EMsession)
359                 else:
360                         EMsession.open(MessageBox, text = _('MyTube Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
361         elif answer == "SHOUTCAST":
362                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/SHOUTcast/plugin.pyo"):
363                         from Plugins.Extensions.SHOUTcast.plugin import SHOUTcastWidget
364                         EMsession.open(SHOUTcastWidget)
365                 else:
366                         EMsession.open(MessageBox, text = _('SHOUTcast Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
367         elif answer == "ZDF":
368                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/ZDFMediathek/plugin.pyo"):
369                         from Plugins.Extensions.ZDFMediathek.plugin import ZDFMediathek
370                         EMsession.open(ZDFMediathek)
371                 else:
372                         EMsession.open(MessageBox, text = _('ZDFmediathek Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
373         elif answer == "VLC":
374                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/VlcPlayer/plugin.pyo"):
375                         from Plugins.Extensions.VlcPlayer.plugin import *
376                         main(EMsession)
377                 else:
378                         EMsession.open(MessageBox, text = _('VLC Player is not installed!'), type = MessageBox.TYPE_ERROR)
379         elif answer == "IDREAM":
380                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MerlinMusicPlayer/plugin.pyo"):
381                         from Plugins.Extensions.MerlinMusicPlayer.plugin import iDreamMerlin
382                         servicelist = None
383                         EMsession.open(iDreamMerlin, servicelist)
384                 else:
385                         EMsession.open(MessageBox, text = _('Merlin iDream is not installed!'), type = MessageBox.TYPE_ERROR)
386         elif answer == "MYVIDEO":
387                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MyVideoPlayer/plugin.pyo"):
388                         from Plugins.Extensions.MyVideoPlayer.plugin import Vidtype
389                         EMsession.open(Vidtype)
390                 else:
391                         EMsession.open(MessageBox, text = _('MyVideo Player is not installed!'), type = MessageBox.TYPE_ERROR)
392
393
394