initially add eUroticTV HTTP live streaming plugin
[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
17 from ServiceReference import ServiceReference
18 from Tools.Directories import SCOPE_PLUGINS, resolveFilename
19 from __init__ import __
20
21 class EuroticTVPlayer(Screen, InfoBarBase, InfoBarSeek, HelpableScreen):
22         STATE_DISCONNECTED, STATE_CONNECTING, STATE_PLAYING, STATE_PAUSED, STATE_FAILURE = range(5)
23         STATE_NAMES = [__("disconnected"), __("connecting..."), __("LIVE"), __("pause"), __("No Connection")]
24         STREAM_DIM = (768, 576)
25         PIP_DIM = (432, 324)
26         STREAM_URI = "http://174.121.228.234/hls-live/livepkgr/_definst_/liveevent/etv-livestream_2.m3u86"
27         CENTER_POS = ((560-PIP_DIM[0])/2)
28
29         skin = """
30         <screen position="center,center" size="560,470" title="eUroticTV" flags="wfNoBorder">
31                 <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
32                 <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
33                 <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
34                 <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
35                 <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" />
36                 <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" />
37                 <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" />
38                 <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" />
39
40                 <widget source="pig_mode" render="Pig" position="%i,60" size="%i,%i" zPosition="0" backgroundColor="transparent">
41                         <convert type="ConditionalShowHide" />
42                 </widget>
43                 <widget name="poster" position="%i,60" size="%i,%i" alphatest="on" zPosition="2" />
44                 <widget name="connection_label" position="85,434" size="384,24" font="Regular;24" halign="center" foregroundColors="#000000,#FFFF00,#00FF00,#AAAAAA,#FF0000" />
45                 <widget source="do_blink" render="FixedLabel" text=" " position="85,434" zPosition="1" size="384,24">
46                         <convert type="ConditionalShowHide">Blink</convert>
47                 </widget>
48         </screen>""" % (CENTER_POS, PIP_DIM[0], PIP_DIM[1], CENTER_POS, PIP_DIM[0], PIP_DIM[1])
49
50         def __init__(self, session):
51                 Screen.__init__(self, session)
52                 InfoBarBase.__init__(self, steal_current_service = True)
53                 InfoBarSeek.__init__(self, actionmap = "CutlistSeekActions")
54                 HelpableScreen.__init__(self)
55                 self.old_service = session.nav.getCurrentlyPlayingServiceReference()
56                 self.session.nav.stopService()
57
58                 self["key_red"] = StaticText(__("Exit"))
59                 self["key_green"] = StaticText(__("Play"))
60                 self["key_yellow"] = StaticText((""))
61                 self["key_blue"] = StaticText(__("Fullscreen"))
62                 self["connection_label"] = MultiColorLabel()
63                 self["do_blink"] = Boolean(False)
64                 self["pig_mode"] = Boolean(True)
65
66                 self["poster"] = Pixmap()
67                 self.picload = ePicLoad()
68                 self.picload.PictureData.get().append(self.paintPosterPixmapCB)
69
70                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions", "InfobarSeekActions", "MediaPlayerActions"],
71                 {
72                                 "ok": self.keyOK,
73                                 "cancel": self.exit,
74                                 "stop": self.disconnect,
75                                 "playpauseService": self.playpauseService,
76                                 "red": self.exit,
77                                 "green": self.keyOK,
78                                 "blue": self.keyBlue,
79                                 "yellow": self.keyYellow,
80                                 "seekFwd": self.keyPass
81                         }, -4)
82
83                 self.__event_tracker = ServiceEventTracker(screen = self, eventmap =
84                         {
85                                 iPlayableService.evStart: self.__serviceStarted,
86                                 iPlayableService.evUpdatedEventInfo: self.__streamStarted,
87                                 iPlayableService.evTuneFailed: self.__streamFailed,
88                                 iPlayableService.evEOF: self.__evEOF,
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.__deref__())
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                 self.setState(self.STATE_FAILURE)
142
143         def __evEOF(self):
144                 print "__evEOF"
145                 self.setState(self.STATE_DISCONNECTED)
146
147         def keyPass(self):
148                 print "keyPass"
149
150         def keyOK(self):
151                 if self.state in (self.STATE_DISCONNECTED, self.STATE_FAILURE):
152                         self.start()
153                 elif self.state == self.STATE_PAUSED:
154                         self.playpauseService()
155
156         def keyYellow(self):
157                 if self.state in (self.STATE_PLAYING, self.STATE_PAUSED):
158                         self.playpauseService()
159
160         def togglePIG(self, fullscreen=False):
161                 if fullscreen == True:
162                         self.hide()
163                 else:
164                         self.show()
165                 self["pig_mode"].setBoolean(not fullscreen)
166
167         def keyBlue(self):
168                 if self["pig_mode"].getBoolean() == True:
169                         self.togglePIG(True)
170                 else:
171                         self.togglePIG(fullscreen=False)
172
173         def playpauseService(self):
174                 if self.seekstate == self.SEEK_STATE_PLAY:
175                         self.setState(self.STATE_PAUSED)
176                         self.pauseService()
177                 elif self.seekstate == self.SEEK_STATE_PAUSE:
178                         self.setState(self.STATE_PLAYING)
179                         self.unPauseService()
180
181         def checkSkipShowHideLock(self):
182                 pass
183
184         def start(self):
185                 sref = eServiceReference(4097,0,self.STREAM_URI)
186                 sref.setName("eUroticTV Live Stream")
187                 self.session.nav.playService(sref)
188
189         def disconnect(self):
190                 self.session.nav.stopService()
191                 self.setState(self.STATE_DISCONNECTED)
192
193         def __onClose(self):
194                 self.session.nav.playService(self.old_service, forceRestart=True)
195
196         def exit(self):
197                 self.close()
198
199 def main(session, **kwargs):
200         session.open(EuroticTVPlayer)
201
202 def Plugins(**kwargs):
203         return PluginDescriptor(name="eUroticTV", description=__("Watch eUroticTV via HTTP Live Streaming"), where = PluginDescriptor.WHERE_PLUGINMENU, icon="plugin.png", needsRestart = False, fnc=main)