Enigma2 plugin to to play various online streams (mostly Latvian).

iptvplayer.py 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. from Screens.Screen import Screen
  2. from Screens.InfoBarGenerics import InfoBarSeek, InfoBarAudioSelection, InfoBarNotifications, InfoBarSubtitleSupport, InfoBarShowHide
  3. from Screens.HelpMenu import HelpableScreen
  4. from Components.ActionMap import HelpableActionMap
  5. from Components.config import config
  6. from Components.AVSwitch import eAVSwitch
  7. from Screens.ChoiceBox import ChoiceBox
  8. from Components.ServiceEventTracker import ServiceEventTracker
  9. from enigma import iPlayableService, eTimer
  10. from iptvtools import printDBG, printExc, eConnectCallback
  11. class customMoviePlayer(InfoBarShowHide, InfoBarSeek, InfoBarAudioSelection, InfoBarSubtitleSupport, HelpableScreen, InfoBarNotifications, Screen):
  12. STATE_IDLE = 0
  13. STATE_PLAYING = 1
  14. STATE_PAUSED = 2
  15. ENABLE_RESUME_SUPPORT = True
  16. ALLOW_SUSPEND = True
  17. def __init__(self, session, service, lastPosition=None, bugEOFworkaround=0):
  18. Screen.__init__(self, session)
  19. self.skinName = "MoviePlayer"
  20. self.__event_tracker = ServiceEventTracker(screen = self, eventmap =
  21. {
  22. iPlayableService.evEOF: self.__evEOF,
  23. iPlayableService.evSOF: self.__evEOF,
  24. })
  25. self["actions"] = HelpableActionMap(self, "MoviePlayerActions",
  26. {
  27. "leavePlayer": (self.leavePlayer, _("leave movie player...")),
  28. }, -5)
  29. for x in HelpableScreen, InfoBarShowHide, InfoBarSeek, InfoBarAudioSelection, InfoBarSubtitleSupport, InfoBarNotifications:
  30. x.__init__(self)
  31. # InfoBarServiceNotifications
  32. self.onClose.append(self.__onClose)
  33. self.mainTimer = eTimer()
  34. self.mainTimer_conn = eConnectCallback(self.mainTimer.timeout, self.timerCallBack)
  35. self.mainTimer.start(1000)
  36. self.bugEOFworkaround = bugEOFworkaround
  37. self.session.nav.playService(service)
  38. if lastPosition != None and (lastPosition / 90000) > 10:
  39. self.position = 0
  40. self.lastPosition = lastPosition
  41. self.doSeekToLastPosition = True
  42. else:
  43. self.position = 0
  44. self.lastPosition = 0
  45. self.doSeekToLastPosition = False
  46. self.waitForSeekToLastPosition = 0
  47. self.stopTimeFix = 0
  48. self.returning = False
  49. self.aspectratiomode = "1"
  50. self.isClosing = False
  51. def getPosition(self):
  52. time = 0
  53. length = 0
  54. service = self.session.nav.getCurrentService()
  55. seek = service and service.seek()
  56. if seek != None:
  57. r = seek.getLength()
  58. if not r[0]:
  59. length = r[1]
  60. r = seek.getPlayPosition()
  61. if not r[0]:
  62. time = r[1] #float(float(r[1]) / float(90000))
  63. return time, length
  64. def doSeekRelative(self, pts):
  65. printDBG("doSeekRelative pts[%r]" % pts)
  66. InfoBarSeek.doSeekRelative(self, pts)
  67. self.waitForSeekToLastPosition = -1
  68. def timerCallBack(self):
  69. try:
  70. position, length = self.getPosition()
  71. if self.doSeekToLastPosition and self.seekstate == self.SEEK_STATE_PLAY:
  72. printDBG("timerCallBack doSeekToLastPosition[%r]" % self.lastPosition)
  73. # not sure why but riginal MP doSeek method does nothing, so I use on seeking only doSeekRelative
  74. self.doSeekRelative(self.lastPosition - position)
  75. self.doSeekToLastPosition = False
  76. self.stopTimeFix = 0
  77. self.lastPosition = 0
  78. return
  79. if -1 == self.waitForSeekToLastPosition:
  80. if position > 0:
  81. self.waitForSeekToLastPosition = position
  82. printDBG('________waitForSeekToLastPosition position[%r]' % (position) )
  83. return
  84. printDBG('________timerCallBack position [%r], length[%r], seekstate[%r]' % (position, length, self.seekstate) )
  85. if self.waitForSeekToLastPosition > 0 and self.waitForSeekToLastPosition >= position: return
  86. self.waitForSeekToLastPosition = 0
  87. if self.bugEOFworkaround == 0 or position == 0 or self.seekstate != self.SEEK_STATE_PLAY: return #== self.SEEK_STATE_PAUSE: return
  88. self.lastPosition = position
  89. except:
  90. printExc()
  91. return
  92. if position != self.position:
  93. self.position = position
  94. self.stopTimeFix = 0
  95. else:
  96. self.stopTimeFix += 1
  97. if self.stopTimeFix >= self.bugEOFworkaround:
  98. self.mainTimer.stop()
  99. self.leavePlayer(True)
  100. def aspectChange(self):
  101. printDBG("Aspect Ratio [%r]" % self.aspectratiomode)
  102. if self.aspectratiomode == "1": #letterbox
  103. eAVSwitch.getInstance().setAspectRatio(0)
  104. self.aspectratiomode = "2"
  105. return
  106. elif self.aspectratiomode == "2": #nonlinear
  107. self.aspectratiomode = "3"
  108. elif self.aspectratiomode == "3": #nonlinear
  109. eAVSwitch.getInstance().setAspectRatio(2)
  110. self.aspectratiomode = "4"
  111. elif self.aspectratiomode == "4": #panscan
  112. eAVSwitch.getInstance().setAspectRatio(3)
  113. self.aspectratiomode = "1"
  114. def pauseBeforeClose(self):
  115. printDBG("pauseBeforeClose")
  116. service = self.session.nav.getCurrentService()
  117. if service is None:
  118. printDBG("No Service found")
  119. return False
  120. pauseable = service.pause()
  121. if pauseable is None:
  122. printDBG("not pauseable.")
  123. else:
  124. printDBG("pausable")
  125. pauseable.pause()
  126. return True
  127. def leavePlayer(self, endFile=False):
  128. printDBG("customMoviePlayer.leavePlayer isClosing[%r], endFile[%r]" % (self.isClosing, endFile))
  129. if False == self.isClosing:
  130. self.pauseBeforeClose()
  131. #self.session.nav.playService(None)
  132. if endFile:
  133. self._doClose(1)
  134. else:
  135. self._doClose(0)
  136. def doEofInternal(self, playing):
  137. printDBG( "--- eofint movieplayer ---" )
  138. self.leavePlayer(True)
  139. def _doClose(self, sts):
  140. printDBG("_doClose sts[%r], lastPosition[%r]" % (sts, self.lastPosition) )
  141. try:
  142. self.hide()
  143. self.isClosing = True
  144. self.onShow = []
  145. self.onHide = []
  146. self.hideTimer.stop()
  147. except:
  148. printExc(customMoviePlayer._doClose)
  149. self.close(sts, self.lastPosition)
  150. def __evEOF(self):
  151. printDBG( "evEOF=%d" % iPlayableService.evEOF)
  152. self.leavePlayer(True)
  153. def __onClose(self):
  154. printDBG("customMoviePlayer.__onClose")
  155. self.mainTimer.stop()
  156. self.mainTimer_conn = None
  157. self.onClose.remove(self.__onClose)
  158. def show(self):
  159. if False == self.isClosing:
  160. Screen.show(self)
  161. else:
  162. printExc("customMoviePlayer.show")
  163. def doShow(self):
  164. if False == self.isClosing:
  165. InfoBarShowHide.doShow(self)
  166. else:
  167. printExc("customMoviePlayer.doShow")
  168. def openEventView(self, *args, **kwargs):
  169. pass
  170. #####################################################
  171. # movie player by j00zek
  172. #####################################################
  173. from Screens.InfoBar import MoviePlayer as standardMoviePlayer
  174. from enigma import eServiceReference
  175. class IPTVStandardMoviePlayer(standardMoviePlayer):
  176. def __init__(self, session, uri, title):
  177. self.session = session
  178. self.WithoutStopClose = True
  179. #if '://' not in uri: uri = 'file://' + uri
  180. fileRef = eServiceReference(4097,0,uri)
  181. fileRef.setName (title)
  182. standardMoviePlayer.__init__(self, self.session, fileRef)
  183. self.skinName = "MoviePlayer"
  184. standardMoviePlayer.skinName = "MoviePlayer"
  185. class IPTVMiniMoviePlayer(customMoviePlayer):
  186. def __init__(self, session, uri, title, lastPosition=None, bugEOFworkaround=0):
  187. self.session = session
  188. self.WithoutStopClose = True
  189. #if '://' not in uri: uri = 'file://' + uri
  190. fileRef = eServiceReference(4097,0,uri)
  191. fileRef.setName (title)
  192. customMoviePlayer.__init__(self, self.session, fileRef, lastPosition, bugEOFworkaround)
  193. #####################################################