[EPGSearch] - include PluginDescriptor.WHERE_CHANNEL_SELECTION_RED for other plugins...
[enigma2-plugins.git] / eurotictv / src / plugin.py
1 from Plugins.Plugin import PluginDescriptor
2 from Screens.Screen import Screen
3 from Screens.MessageBox import MessageBox
4 from Screens.InfoBarGenerics import InfoBarSeek, InfoBarCueSheetSupport
5 from Screens.HelpMenu import HelpableScreen
6 from Components.Sources.StaticText import StaticText
7 from Components.Sources.Boolean import Boolean
8 from Components.ActionMap import HelpableActionMap, ActionMap
9 from Components.ServiceEventTracker import ServiceEventTracker, InfoBarBase
10 from Components.VideoWindow import VideoWindow
11 from Components.Label import Label, MultiColorLabel
12 from Components.Pixmap import Pixmap
13 from Components.GUIComponent import GUIComponent
14 from Components.ConfigList import ConfigListScreen
15 from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigPassword, ConfigYesNo, ConfigText
16 from enigma import eListboxPythonMultiContent, eServiceReference, getDesktop, iPlayableService, eSize, ePicLoad, iServiceInformation
17 from ServiceReference import ServiceReference
18 from Tools.Directories import SCOPE_PLUGINS, resolveFilename
19
20 class EuroticTVPlayer(Screen, InfoBarBase, InfoBarSeek, HelpableScreen):
21         STATE_DISCONNECTED, STATE_CONNECTING, STATE_PLAYING, STATE_PAUSED, STATE_FAILURE = range(5)
22         STATE_NAMES = [_("disconnected"), _("connecting..."), _("LIVE"), _("pause"), _("No Connection")]
23         STREAM_DIM = (768, 576)
24         PIP_DIM = (432, 324)
25         STREAM_URI = "http://174.121.228.234/hls-live/livepkgr/_definst_/liveevent/etv-livestream_2.m3u86"
26         CENTER_POS = ((560-PIP_DIM[0])/2)
27
28         skin = """
29         <screen position="center,center" size="560,470" title="eUroticTV" flags="wfNoBorder">
30                 <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
31                 <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
32                 <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
33                 <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
34                 <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;19" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
35                 <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;19" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
36                 <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;19" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
37                 <widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" font="Regular;19" halign="center" valign="center" backgroundColor="#18188b" transparent="1" />
38
39                 <widget source="pig_mode" render="Pig" position="%i,60" size="%i,%i" zPosition="0" backgroundColor="transparent">
40                         <convert type="ConditionalShowHide" />
41                 </widget>
42                 <widget name="poster" position="%i,60" size="%i,%i" alphatest="on" zPosition="2" />
43                 <widget name="connection_label" position="85,422" size="384,48" font="Regular;24" valign="center" halign="center" foregroundColors="#000000,#FFFF00,#00FF00,#AAAAAA,#FF0000" />
44                 <widget source="do_blink" render="FixedLabel" text=" " position="85,434" zPosition="1" size="384,24">
45                         <convert type="ConditionalShowHide">Blink</convert>
46                 </widget>
47         </screen>""" % (CENTER_POS, PIP_DIM[0], PIP_DIM[1], CENTER_POS, PIP_DIM[0], PIP_DIM[1])
48
49         def __init__(self, session):
50                 Screen.__init__(self, session)
51                 InfoBarBase.__init__(self, steal_current_service = True)
52                 InfoBarSeek.__init__(self, actionmap = "CutlistSeekActions")
53                 HelpableScreen.__init__(self)
54                 self.old_service = session.nav.getCurrentlyPlayingServiceReference()
55                 self.session.nav.stopService()
56
57                 self["key_red"] = StaticText(_("Exit"))
58                 self["key_green"] = StaticText(_("Play"))
59                 self["key_yellow"] = StaticText((""))
60                 self["key_blue"] = StaticText(_("Fullscreen"))
61                 self["connection_label"] = MultiColorLabel()
62                 self["do_blink"] = Boolean(False)
63                 self["pig_mode"] = Boolean(True)
64
65                 self["poster"] = Pixmap()
66                 self.picload = ePicLoad()
67                 self.picload_conn = self.picload.PictureData.connect(self.paintPosterPixmapCB)
68
69                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions", "InfobarSeekActions", "MediaPlayerActions"],
70                 {
71                                 "ok": self.keyOK,
72                                 "cancel": self.exit,
73                                 "stop": self.disconnect,
74                                 "playpauseService": self.playpauseService,
75                                 "red": self.exit,
76                                 "green": self.keyOK,
77                                 "blue": self.keyBlue,
78                                 "yellow": self.keyYellow,
79                                 "seekFwd": self.keyPass
80                         }, -4)
81
82                 self.__event_tracker = ServiceEventTracker(screen = self, eventmap =
83                         {
84                                 iPlayableService.evStart: self.__serviceStarted,
85                                 iPlayableService.evUpdatedEventInfo: self.__streamStarted,
86                                 iPlayableService.evTuneFailed: self.__streamFailed,
87                                 iPlayableService.evEOF: self.__evEOF,
88                                 iPlayableService.evUser+15: self.__streamFailed
89                         })      
90
91                 self.onClose.append(self.__onClose)
92                 self.onExecBegin.append(self.__onExecBegin)
93                 
94                 self.setState(self.STATE_DISCONNECTED)
95
96         def __onExecBegin(self):
97                 from Components.AVSwitch import AVSwitch
98                 sc = AVSwitch().getFramebufferScale()
99                 self.picload.setPara((self["poster"].instance.size().width(), self["poster"].instance.size().height(), self.PIP_DIM[0], self.PIP_DIM[1], False, 1, "#00000000"))
100                 self.picload.startDecode(resolveFilename(SCOPE_PLUGINS)+"Extensions/eUroticTV/"+"eurotic.jpg")
101
102         def setState(self, state):
103                 if state <= self.STATE_FAILURE:
104                         self.state = state
105
106                 self["connection_label"].setForegroundColorNum(self.state)
107                 self["connection_label"].setText(self.STATE_NAMES[self.state])
108                 
109                 if self.state in (self.STATE_CONNECTING, self.STATE_PAUSED):
110                         self["do_blink"].setBoolean(True)
111                 else:
112                         self["do_blink"].setBoolean(False)
113
114                 if self.state in (self.STATE_DISCONNECTED, self.STATE_CONNECTING, self.STATE_FAILURE):
115                         self.togglePIG(fullscreen=False)
116                 
117                 if self.state in (self.STATE_PLAYING, self.STATE_PAUSED):
118                         self["poster"].hide()
119                         self["pig_mode"].setBoolean(True)
120                 else: 
121                         self["poster"].show()
122                         self["pig_mode"].setBoolean(False)
123
124         def paintPosterPixmapCB(self, picInfo=None):
125                 ptr = self.picload.getData()
126                 if ptr != None:
127                         self["poster"].instance.setPixmap(ptr)
128                         self["poster"].show()
129
130         def __streamStarted(self):
131                 print "__streamStarted"
132                 if self.state != self.STATE_PAUSED:
133                         self.setState(self.STATE_PLAYING)
134
135         def __serviceStarted(self):
136                 print "__streamStarted"
137                 self.setState(self.STATE_CONNECTING)
138
139         def __streamFailed(self):
140                 print "__streamFailed"
141                 currPlay = self.session.nav.getCurrentService()
142                 message = currPlay.info().getInfoString(iServiceInformation.sUser+12)
143                 self.setState(self.STATE_FAILURE)
144                 self["connection_label"].setText(_("Streaming error: %s") % message)
145
146         def __evEOF(self):
147                 print "__evEOF"
148                 if self.state != self.STATE_FAILURE:
149                         self.setState(self.STATE_DISCONNECTED)
150
151         def keyPass(self):
152                 print "keyPass"
153
154         def keyOK(self):
155                 if self.state in (self.STATE_DISCONNECTED, self.STATE_FAILURE):
156                         self.start()
157                 elif self.state == self.STATE_PAUSED:
158                         self.playpauseService()
159
160         def keyYellow(self):
161                 if self.state in (self.STATE_PLAYING, self.STATE_PAUSED):
162                         self.playpauseService()
163
164         def togglePIG(self, fullscreen=False):
165                 if fullscreen == True:
166                         self.hide()
167                 else:
168                         self.show()
169                 self["pig_mode"].setBoolean(not fullscreen)
170
171         def keyBlue(self):
172                 if self["pig_mode"].getBoolean() == True:
173                         self.togglePIG(True)
174                 else:
175                         self.togglePIG(fullscreen=False)
176
177         def playpauseService(self):
178                 if self.seekstate == self.SEEK_STATE_PLAY:
179                         self.setState(self.STATE_PAUSED)
180                         self.pauseService()
181                 elif self.seekstate == self.SEEK_STATE_PAUSE:
182                         self.setState(self.STATE_PLAYING)
183                         self.unPauseService()
184
185         def checkSkipShowHideLock(self):
186                 pass
187
188         def start(self):
189                 sref = eServiceReference(4097,0,self.STREAM_URI)
190                 sref.setName("eUroticTV Live Stream")
191                 self.session.nav.playService(sref)
192
193         def disconnect(self):
194                 self.session.nav.stopService()
195                 self.setState(self.STATE_DISCONNECTED)
196
197         def __onClose(self):
198                 self.session.nav.playService(self.old_service, forceRestart=True)
199
200         def exit(self):
201                 self.close()
202
203 def main(session, **kwargs):
204         session.open(EuroticTVPlayer)
205
206 def Plugins(**kwargs):
207         return PluginDescriptor(name="eUroticTV", description=_("Watch eUroticTV via HTTP Live Streaming"), where = PluginDescriptor.WHERE_PLUGINMENU, icon="plugin.png", needsRestart = True, fnc=main)