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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  1. from Tools.Profile import profile
  2. # workaround for required config entry dependencies.
  3. import Screens.MovieSelection
  4. from Components.PluginComponent import plugins
  5. from Plugins.Plugin import PluginDescriptor
  6. from Screens.Screen import Screen
  7. from Screens.MessageBox import MessageBox
  8. from Components.Label import Label
  9. from Components.Pixmap import MultiPixmap
  10. from Tools.Directories import fileExists
  11. from Screens.ButtonSetup import InfoBarButtonSetup
  12. profile("LOAD:enigma")
  13. import enigma
  14. from boxbranding import getBoxType, getMachineBrand, getBrandOEM, getMachineBuild, getMachineName
  15. boxtype = getBoxType()
  16. profile("LOAD:InfoBarGenerics")
  17. from Screens.InfoBarGenerics import InfoBarShowHide, \
  18. InfoBarNumberZap, InfoBarChannelSelection, InfoBarMenu, InfoBarRdsDecoder, InfoBarRedButton, InfoBarTimerButton, InfoBarVmodeButton, \
  19. InfoBarEPG, InfoBarSeek, InfoBarInstantRecord, InfoBarINFOpanel, InfoBarResolutionSelection, InfoBarAspectSelection, \
  20. InfoBarAudioSelection, InfoBarAdditionalInfo, InfoBarNotifications, InfoBarDish, InfoBarUnhandledKey, InfoBarLongKeyDetection, \
  21. InfoBarSubserviceSelection, InfoBarShowMovies, \
  22. InfoBarServiceNotifications, InfoBarPVRState, InfoBarCueSheetSupport, InfoBarSimpleEventView, InfoBarBuffer, \
  23. InfoBarSummarySupport, InfoBarMoviePlayerSummarySupport, InfoBarTimeshiftState, InfoBarTeletextPlugin, InfoBarExtensions, \
  24. InfoBarSubtitleSupport, InfoBarPiP, InfoBarPlugins, InfoBarServiceErrorPopupSupport, InfoBarJobman, InfoBarZoom, InfoBarSleepTimer, InfoBarOpenOnTopHelper, \
  25. InfoBarHdmi, setResumePoint, delResumePoint
  26. from Screens.ButtonSetup import InfoBarButtonSetup
  27. profile("LOAD:InitBar_Components")
  28. from Components.ActionMap import HelpableActionMap
  29. from Components.Timeshift import InfoBarTimeshift
  30. from Components.config import config
  31. from Components.ServiceEventTracker import ServiceEventTracker, InfoBarBase
  32. profile("LOAD:HelpableScreen")
  33. from Screens.HelpMenu import HelpableScreen
  34. class InfoBar(InfoBarBase, InfoBarShowHide,
  35. InfoBarNumberZap, InfoBarChannelSelection, InfoBarMenu, InfoBarEPG, InfoBarRdsDecoder,
  36. InfoBarInstantRecord, InfoBarAudioSelection, InfoBarRedButton, InfoBarTimerButton, InfoBarINFOpanel, InfoBarResolutionSelection, InfoBarAspectSelection, InfoBarVmodeButton,
  37. HelpableScreen, InfoBarAdditionalInfo, InfoBarNotifications, InfoBarDish, InfoBarUnhandledKey, InfoBarLongKeyDetection,
  38. InfoBarSubserviceSelection, InfoBarTimeshift, InfoBarSeek, InfoBarCueSheetSupport, InfoBarBuffer,
  39. InfoBarSummarySupport, InfoBarTimeshiftState, InfoBarTeletextPlugin, InfoBarExtensions,
  40. InfoBarPiP, InfoBarPlugins, InfoBarSubtitleSupport, InfoBarServiceErrorPopupSupport, InfoBarJobman, InfoBarZoom, InfoBarSleepTimer, InfoBarOpenOnTopHelper,
  41. InfoBarHdmi, InfoBarButtonSetup, Screen):
  42. ALLOW_SUSPEND = True
  43. instance = None
  44. def __init__(self, session):
  45. Screen.__init__(self, session)
  46. if config.usage.show_infobar_lite.value and (config.skin.primary_skin.value == "DMConcinnity-HD/skin.xml" or config.skin.primary_skin.value.startswith('MetrixHD/')):
  47. self.skinName = "InfoBarLite"
  48. self["actions"] = HelpableActionMap(self, "InfobarActions",
  49. {
  50. "showMovies": (self.showMovies, _("Play recorded movies...")),
  51. "showRadio": (self.showRadioButton, _("Show the radio player...")),
  52. "showTv": (self.showTvButton, _("Show the tv player...")),
  53. "toogleTvRadio": (self.toogleTvRadio, _("Toggels between tv and radio...")),
  54. "openBouquetList": (self.openBouquetList, _("Open bouquetlist...")),
  55. "showMediaPlayer": (self.showMediaPlayer, _("Show the media player...")),
  56. "openTimerList": (self.openTimerList, _("Open Timerlist...")),
  57. "openAutoTimerList": (self.openAutoTimerList, _("Open AutoTimerlist...")),
  58. "openEPGSearch": (self.openEPGSearch, _("Open EPGSearch...")),
  59. "openIMDB": (self.openIMDB, _("Open IMDB...")),
  60. "showMC": (self.showMediaCenter, _("Show the media center...")),
  61. "openSleepTimer": (self.openPowerTimerList, _("Show the Sleep Timer...")),
  62. 'ZoomInOut': (self.ZoomInOut, _('Zoom In/Out TV...')),
  63. 'ZoomOff': (self.ZoomOff, _('Zoom Off...')),
  64. 'HarddiskSetup': (self.HarddiskSetup, _('Select HDD')),
  65. "showWWW": (self.showPORTAL, _("Open MediaPortal...")),
  66. "showSetup": (self.showSetup, _("Show setup...")),
  67. "showFormat": (self.showFormat, _("Show Format Setup...")),
  68. "showPluginBrowser": (self.showPluginBrowser, _("Show the plugins...")),
  69. "showBoxPortal": (self.showBoxPortal, _("Show Box Portal...")),
  70. }, prio=2)
  71. self["key_red"] = Label()
  72. self["key_yellow"] = Label()
  73. self["key_blue"] = Label()
  74. self["key_green"] = Label()
  75. self.allowPiP = True
  76. self.radioTV = 0
  77. for x in HelpableScreen, \
  78. InfoBarBase, InfoBarShowHide, \
  79. InfoBarNumberZap, InfoBarChannelSelection, InfoBarMenu, InfoBarEPG, InfoBarRdsDecoder, \
  80. InfoBarInstantRecord, InfoBarAudioSelection, InfoBarRedButton, InfoBarTimerButton, InfoBarUnhandledKey, InfoBarLongKeyDetection, InfoBarINFOpanel, InfoBarResolutionSelection, InfoBarVmodeButton, \
  81. InfoBarAdditionalInfo, InfoBarNotifications, InfoBarDish, InfoBarSubserviceSelection, InfoBarAspectSelection, InfoBarBuffer, \
  82. InfoBarTimeshift, InfoBarSeek, InfoBarCueSheetSupport, InfoBarSummarySupport, InfoBarTimeshiftState, \
  83. InfoBarTeletextPlugin, InfoBarExtensions, InfoBarPiP, InfoBarSubtitleSupport, InfoBarJobman, InfoBarZoom, InfoBarSleepTimer, InfoBarOpenOnTopHelper, \
  84. InfoBarHdmi, InfoBarPlugins, InfoBarServiceErrorPopupSupport, InfoBarButtonSetup:
  85. x.__init__(self)
  86. self.helpList.append((self["actions"], "InfobarActions", [("showMovies", _("Watch recordings..."))]))
  87. self.helpList.append((self["actions"], "InfobarActions", [("showRadio", _("Listen to the radio..."))]))
  88. self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
  89. {
  90. enigma.iPlayableService.evUpdatedEventInfo: self.__eventInfoChanged
  91. })
  92. self.current_begin_time=0
  93. assert InfoBar.instance is None, "class InfoBar is a singleton class and just one instance of this class is allowed!"
  94. InfoBar.instance = self
  95. if config.misc.initialchannelselection.value:
  96. self.onShown.append(self.showMenu)
  97. self.zoomrate = 0
  98. self.zoomin = 1
  99. self.onShow.append(self.doButtonsCheck)
  100. def showMenu(self):
  101. self.onShown.remove(self.showMenu)
  102. config.misc.initialchannelselection.value = False
  103. config.misc.initialchannelselection.save()
  104. self.mainMenu()
  105. def doButtonsCheck(self):
  106. if config.plisettings.ColouredButtons.value:
  107. self["key_yellow"].setText(_("Search"))
  108. if config.usage.defaultEPGType.value == "Graphical EPG..." or config.usage.defaultEPGType.value == "None":
  109. self["key_red"].setText(_("Single EPG"))
  110. else:
  111. self["key_red"].setText(_("ViX EPG"))
  112. if not config.plisettings.Subservice.value:
  113. self["key_green"].setText(_("Timers"))
  114. else:
  115. self["key_green"].setText(_("Subservices"))
  116. self["key_blue"].setText(_("Extensions"))
  117. def __onClose(self):
  118. InfoBar.instance = None
  119. def __eventInfoChanged(self):
  120. if self.execing:
  121. service = self.session.nav.getCurrentService()
  122. old_begin_time = self.current_begin_time
  123. info = service and service.info()
  124. ptr = info and info.getEvent(0)
  125. self.current_begin_time = ptr and ptr.getBeginTime() or 0
  126. if config.usage.show_infobar_on_event_change.value:
  127. if old_begin_time and old_begin_time != self.current_begin_time:
  128. self.doShow()
  129. def __checkServiceStarted(self):
  130. self.__serviceStarted(True)
  131. self.onExecBegin.remove(self.__checkServiceStarted)
  132. def serviceStarted(self): #override from InfoBarShowHide
  133. new = self.servicelist.newServicePlayed()
  134. if self.execing:
  135. InfoBarShowHide.serviceStarted(self)
  136. self.current_begin_time=0
  137. elif not self.__checkServiceStarted in self.onShown and new:
  138. self.onShown.append(self.__checkServiceStarted)
  139. def __checkServiceStarted(self):
  140. self.serviceStarted()
  141. self.onShown.remove(self.__checkServiceStarted)
  142. def openBouquetList(self):
  143. if config.usage.tvradiobutton_mode.value == "MovieList":
  144. self.showTvChannelList(True)
  145. self.showMovies()
  146. elif config.usage.tvradiobutton_mode.value == "ChannelList":
  147. self.showTvChannelList(True)
  148. elif config.usage.tvradiobutton_mode.value == "BouquetList":
  149. self.showTvChannelList(True)
  150. self.servicelist.showFavourites()
  151. def showTvButton(self):
  152. if boxtype.startswith('gb') or boxtype in ('classm', 'genius', 'evo', 'galaxym6'):
  153. self.toogleTvRadio()
  154. elif boxtype in ('uniboxhd1', 'uniboxhd2', 'uniboxhd3', 'sezam5000hd', 'mbtwin'):
  155. self.showMovies()
  156. else:
  157. self.showTv()
  158. def showTv(self):
  159. if config.usage.tvradiobutton_mode.value == "MovieList":
  160. self.showTvChannelList(True)
  161. self.showMovies()
  162. elif config.usage.tvradiobutton_mode.value == "BouquetList":
  163. self.showTvChannelList(True)
  164. if config.usage.show_servicelist.value:
  165. self.servicelist.showFavourites()
  166. else:
  167. self.showTvChannelList(True)
  168. def showRadioButton(self):
  169. if boxtype.startswith('gb') or boxtype.startswith('azbox') or boxtype in ('classm', 'genius', 'evo', 'galaxym6', 'uniboxhd1', 'uniboxhd2', 'uniboxhd3', 'sezam5000hd', 'mbtwin', 'beyonwizt3'):
  170. self.toogleTvRadio()
  171. else:
  172. self.showRadio()
  173. def showRadio(self):
  174. if config.usage.e1like_radio_mode.value:
  175. if config.usage.tvradiobutton_mode.value == "BouquetList":
  176. self.showRadioChannelList(True)
  177. if config.usage.show_servicelist.value:
  178. self.servicelist.showFavourites()
  179. else:
  180. self.showRadioChannelList(True)
  181. else:
  182. self.rds_display.hide() # in InfoBarRdsDecoder
  183. from Screens.ChannelSelection import ChannelSelectionRadio
  184. self.session.openWithCallback(self.ChannelSelectionRadioClosed, ChannelSelectionRadio, self)
  185. def toogleTvRadio(self):
  186. if self.radioTV == 1:
  187. self.radioTV = 0
  188. self.showTv()
  189. else:
  190. self.radioTV = 1
  191. self.showRadio()
  192. def ChannelSelectionRadioClosed(self, *arg):
  193. self.rds_display.show() # in InfoBarRdsDecoder
  194. self.radioTV = 0
  195. self.doShow()
  196. def showMovies(self, defaultRef=None):
  197. if getMachineBrand() == 'GI' or boxtype.startswith('azbox') or boxtype.startswith('ini') or boxtype.startswith('venton'):
  198. from Screens.BoxPortal import BoxPortal
  199. self.session.open(BoxPortal)
  200. else:
  201. self.lastservice = self.session.nav.getCurrentlyPlayingServiceOrGroup()
  202. if self.lastservice and ':0:/' in self.lastservice.toString():
  203. self.lastservice = enigma.eServiceReference(config.movielist.curentlyplayingservice.value)
  204. self.session.openWithCallback(self.movieSelected, Screens.MovieSelection.MovieSelection, defaultRef, timeshiftEnabled = self.timeshiftEnabled())
  205. def movieSelected(self, service):
  206. ref = self.lastservice
  207. del self.lastservice
  208. if service is None:
  209. if ref and not self.session.nav.getCurrentlyPlayingServiceOrGroup():
  210. self.session.nav.playService(ref)
  211. else:
  212. self.session.open(MoviePlayer, service, slist = self.servicelist, lastservice = ref)
  213. def showMediaPlayer(self):
  214. try:
  215. from Plugins.Extensions.MediaPlayer.plugin import MediaPlayer
  216. self.session.open(MediaPlayer)
  217. no_plugin = False
  218. except Exception, e:
  219. self.session.open(MessageBox, _("The MediaPlayer plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
  220. def showMediaCenter(self):
  221. try:
  222. from Plugins.Extensions.BMediaCenter.plugin import DMC_MainMenu
  223. self.session.open(DMC_MainMenu)
  224. no_plugin = False
  225. except Exception, e:
  226. self.session.open(MessageBox, _("The MediaCenter plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
  227. def openSleepTimer(self):
  228. from Screens.SleepTimerEdit import SleepTimerEdit
  229. self.session.open(SleepTimerEdit)
  230. def openTimerList(self):
  231. from Screens.TimerEdit import TimerEditList
  232. self.session.open(TimerEditList)
  233. def openPowerTimerList(self):
  234. from Screens.PowerTimerEdit import PowerTimerEditList
  235. self.session.open(PowerTimerEditList)
  236. def openAutoTimerList(self):
  237. try:
  238. for plugin in plugins.getPlugins([PluginDescriptor.WHERE_PLUGINMENU ,PluginDescriptor.WHERE_EXTENSIONSMENU, PluginDescriptor.WHERE_EVENTINFO]):
  239. if plugin.name == _("AutoTimer"):
  240. self.runPlugin(plugin)
  241. break
  242. except Exception, e:
  243. self.session.open(MessageBox, _("The AutoTimer plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
  244. def openEPGSearch(self):
  245. try:
  246. for plugin in plugins.getPlugins([PluginDescriptor.WHERE_PLUGINMENU ,PluginDescriptor.WHERE_EXTENSIONSMENU, PluginDescriptor.WHERE_EVENTINFO]):
  247. if plugin.name == _("EPGSearch") or plugin.name == _("search EPG...") or plugin.name == "Durchsuche EPG...":
  248. self.runPlugin(plugin)
  249. break
  250. except Exception, e:
  251. self.session.open(MessageBox, _("The EPGSearch plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
  252. def openIMDB(self):
  253. try:
  254. for plugin in plugins.getPlugins([PluginDescriptor.WHERE_PLUGINMENU ,PluginDescriptor.WHERE_EXTENSIONSMENU, PluginDescriptor.WHERE_EVENTINFO]):
  255. if plugin.name == _("IMDb Details"):
  256. self.runPlugin(plugin)
  257. break
  258. except Exception, e:
  259. self.session.open(MessageBox, _("The IMDb plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
  260. def ZoomInOut(self):
  261. zoomval = 0
  262. if self.zoomrate > 3:
  263. self.zoomin = 0
  264. elif self.zoomrate < -9:
  265. self.zoomin = 1
  266. if self.zoomin == 1:
  267. self.zoomrate += 1
  268. else:
  269. self.zoomrate -= 1
  270. if self.zoomrate < 0:
  271. zoomval = abs(self.zoomrate) + 10
  272. else:
  273. zoomval = self.zoomrate
  274. print 'zoomRate:', self.zoomrate
  275. print 'zoomval:', zoomval
  276. if fileExists("/proc/stb/vmpeg/0/zoomrate"):
  277. file = open('/proc/stb/vmpeg/0/zoomrate', 'w')
  278. file.write('%d' % int(zoomval))
  279. file.close()
  280. def ZoomOff(self):
  281. self.zoomrate = 0
  282. self.zoomin = 1
  283. if fileExists("/proc/stb/vmpeg/0/zoomrate"):
  284. file = open('/proc/stb/vmpeg/0/zoomrate', 'w')
  285. file.write(str(0))
  286. file.close()
  287. def HarddiskSetup(self):
  288. from Screens.HarddiskSetup import HarddiskSelection
  289. self.session.open(HarddiskSelection)
  290. def showPORTAL(self):
  291. try:
  292. from Plugins.Extensions.MediaPortal.plugin import MPmain as MediaPortal
  293. MediaPortal(self.session)
  294. no_plugin = False
  295. except Exception, e:
  296. self.session.open(MessageBox, _("The MediaPortal plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
  297. def showSetup(self):
  298. from Screens.Menu import MainMenu, mdom
  299. root = mdom.getroot()
  300. for x in root.findall("menu"):
  301. y = x.find("id")
  302. if y is not None:
  303. id = y.get("val")
  304. if id and id == "setup":
  305. self.session.infobar = self
  306. self.session.open(MainMenu, x)
  307. return
  308. def showFormat(self):
  309. try:
  310. from Plugins.SystemPlugins.Videomode.plugin import videoSetupMain
  311. self.session.instantiateDialog(videoSetupMain)
  312. no_plugin = False
  313. except Exception, e:
  314. self.session.open(MessageBox, _("The VideoMode plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
  315. def showPluginBrowser(self):
  316. from Screens.PluginBrowser import PluginBrowser
  317. self.session.open(PluginBrowser)
  318. def showBoxPortal(self):
  319. if getMachineBrand() == 'GI' or boxtype.startswith('azbox') or boxtype.startswith('ini') or boxtype.startswith('venton'):
  320. from Screens.BoxPortal import BoxPortal
  321. self.session.open(BoxPortal)
  322. else:
  323. self.showMovies()
  324. def setAudioTrack(service):
  325. try:
  326. from Tools.ISO639 import LanguageCodes as langC
  327. tracks = service and service.audioTracks()
  328. nTracks = tracks and tracks.getNumberOfTracks() or 0
  329. if not nTracks: return
  330. idx = 0
  331. trackList = []
  332. for i in xrange(nTracks):
  333. audioInfo = tracks.getTrackInfo(i)
  334. lang = audioInfo.getLanguage()
  335. if langC.has_key(lang):
  336. lang = langC[lang][0]
  337. desc = audioInfo.getDescription()
  338. track = idx, lang, desc
  339. idx += 1
  340. trackList += [track]
  341. seltrack = tracks.getCurrentTrack()
  342. # we need default selected language from image
  343. # to set the audiotrack if "config.autolanguage.audio_autoselect...values" are not set
  344. from Components.Language import language
  345. syslang = language.getLanguage()[:2]
  346. syslang = langC[syslang][0]
  347. if (config.autolanguage.audio_autoselect1.value or config.autolanguage.audio_autoselect2.value or config.autolanguage.audio_autoselect3.value or config.autolanguage.audio_autoselect4.value) != "---":
  348. audiolang = [config.autolanguage.audio_autoselect1.value, config.autolanguage.audio_autoselect2.value, config.autolanguage.audio_autoselect3.value, config.autolanguage.audio_autoselect4.value]
  349. caudiolang = True
  350. else:
  351. audiolang = syslang
  352. caudiolang = False
  353. useAc3 = config.autolanguage.audio_defaultac3.value
  354. if useAc3:
  355. matchedAc3 = tryAudioTrack(tracks, audiolang, caudiolang, trackList, seltrack, useAc3)
  356. if matchedAc3: return
  357. matchedMpeg = tryAudioTrack(tracks, audiolang, caudiolang, trackList, seltrack, False)
  358. if matchedMpeg: return
  359. tracks.selectTrack(0) # fallback to track 1(0)
  360. return
  361. else:
  362. matchedMpeg = tryAudioTrack(tracks, audiolang, caudiolang, trackList, seltrack, False)
  363. if matchedMpeg: return
  364. matchedAc3 = tryAudioTrack(tracks, audiolang, caudiolang, trackList, seltrack, useAc3)
  365. if matchedAc3: return
  366. tracks.selectTrack(0) # fallback to track 1(0)
  367. except Exception, e:
  368. print("[MoviePlayer] audioTrack exception:\n" + str(e))
  369. def tryAudioTrack(tracks, audiolang, caudiolang, trackList, seltrack, useAc3):
  370. for entry in audiolang:
  371. if caudiolang:
  372. # we need here more replacing for other language, or new configs with another list !!!
  373. # choice gives only the value, never the description
  374. # so we can also make some changes in "config.py" to get the description too, then we dont need replacing here !
  375. entry = entry.replace('eng qaa Englisch', 'English').replace('deu ger', 'German')
  376. for x in trackList:
  377. if entry == x[1] and seltrack == x[0]:
  378. if useAc3:
  379. if x[2].startswith('AC'):
  380. print("[MoviePlayer] audio track is current selected track: " + str(x))
  381. return True
  382. else:
  383. print("[MoviePlayer] audio track is current selected track: " + str(x))
  384. return True
  385. elif entry == x[1] and seltrack != x[0]:
  386. if useAc3:
  387. if x[2].startswith('AC'):
  388. print("[MoviePlayer] audio track match: " + str(x))
  389. tracks.selectTrack(x[0])
  390. return True
  391. else:
  392. print("[MoviePlayer] audio track match: " + str(x))
  393. tracks.selectTrack(x[0])
  394. return True
  395. return False
  396. class MoviePlayer(InfoBarAspectSelection, InfoBarSimpleEventView, InfoBarBase, InfoBarShowHide, InfoBarLongKeyDetection, InfoBarMenu, InfoBarEPG, \
  397. InfoBarSeek, InfoBarShowMovies, InfoBarInstantRecord, InfoBarAudioSelection, HelpableScreen, InfoBarNotifications,
  398. InfoBarServiceNotifications, InfoBarPVRState, InfoBarCueSheetSupport,
  399. InfoBarMoviePlayerSummarySupport, InfoBarSubtitleSupport, Screen, InfoBarTeletextPlugin,
  400. InfoBarServiceErrorPopupSupport, InfoBarExtensions, InfoBarPlugins, InfoBarPiP, InfoBarZoom, InfoBarHdmi, InfoBarButtonSetup):
  401. ENABLE_RESUME_SUPPORT = True
  402. ALLOW_SUSPEND = True
  403. instance = None
  404. def __init__(self, session, service, slist = None, lastservice = None):
  405. Screen.__init__(self, session)
  406. InfoBarAspectSelection.__init__(self)
  407. InfoBarAudioSelection.__init__(self)
  408. InfoBarSimpleEventView.__init__(self)
  409. self.pts_pvrStateDialog = ""
  410. self["key_yellow"] = Label()
  411. self["key_blue"] = Label()
  412. self["key_green"] = Label()
  413. self["eventname"] = Label()
  414. self["state"] = Label()
  415. self["speed"] = Label()
  416. self["statusicon"] = MultiPixmap()
  417. self["actions"] = HelpableActionMap(self, "MoviePlayerActions",
  418. {
  419. "leavePlayer": (self.leavePlayer, _("leave movie player...")),
  420. "leavePlayerOnExit": (self.leavePlayerOnExit, _("leave movie player..."))
  421. })
  422. self.allowPiP = True
  423. for x in HelpableScreen, InfoBarShowHide, InfoBarLongKeyDetection, InfoBarMenu, InfoBarEPG, \
  424. InfoBarBase, InfoBarSeek, InfoBarShowMovies, InfoBarInstantRecord, \
  425. InfoBarAudioSelection, InfoBarNotifications, InfoBarSimpleEventView, \
  426. InfoBarServiceNotifications, InfoBarPVRState, InfoBarCueSheetSupport, \
  427. InfoBarMoviePlayerSummarySupport, InfoBarSubtitleSupport, \
  428. InfoBarTeletextPlugin, InfoBarServiceErrorPopupSupport, InfoBarExtensions, \
  429. InfoBarPlugins, InfoBarPiP, InfoBarZoom, InfoBarButtonSetup:
  430. x.__init__(self)
  431. self.onChangedEntry = [ ]
  432. self.servicelist = slist
  433. self.lastservice = lastservice or session.nav.getCurrentlyPlayingServiceOrGroup()
  434. session.nav.playService(service)
  435. self.cur_service = service
  436. self.returning = False
  437. self.onClose.append(self.__onClose)
  438. self.onShow.append(self.doButtonsCheck)
  439. self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
  440. {
  441. enigma.iPlayableService.evStart: self.__evStart
  442. })
  443. assert MoviePlayer.instance is None, "class InfoBar is a singleton class and just one instance of this class is allowed!"
  444. MoviePlayer.instance = self
  445. # is needed for every first call of MoviePlayer
  446. self.__evStart()
  447. def __evStart(self):
  448. self.switchAudioTimer = enigma.eTimer()
  449. self.switchAudioTimer.callback.append(self.switchAudio)
  450. self.switchAudioTimer.start(750, True) # 750 is a safe-value
  451. def switchAudio(self):
  452. service = self.session.nav.getCurrentlyPlayingServiceOrGroup()
  453. if service:
  454. # we go this way for other extensions as own records(they switch over pmt)
  455. path = service.getPath()
  456. import os
  457. ext = os.path.splitext(path)[1].lower()
  458. exts = [".mkv", ".avi", ".divx", ".mp4"] # we need more extensions here ?
  459. if ext.lower() in exts:
  460. service = self.session.nav.getCurrentService()
  461. if service:
  462. setAudioTrack(service)
  463. def doButtonsCheck(self):
  464. if config.plisettings.ColouredButtons.value:
  465. self["key_yellow"].setText(_("Search"))
  466. self["key_green"].setText(_("Timers"))
  467. self["key_blue"].setText(_("Extensions"))
  468. def __onClose(self):
  469. MoviePlayer.instance = None
  470. from Screens.MovieSelection import playlist
  471. del playlist[:]
  472. if not config.movielist.stop_service.value:
  473. Screens.InfoBar.InfoBar.instance.callServiceStarted()
  474. self.session.nav.playService(self.lastservice)
  475. config.usage.last_movie_played.value = self.cur_service.toString()
  476. config.usage.last_movie_played.save()
  477. def handleLeave(self, how):
  478. self.is_closing = True
  479. if how == "ask":
  480. if config.usage.setup_level.index < 2: # -expert
  481. list = (
  482. (_("Yes"), "quit"),
  483. (_("No"), "continue")
  484. )
  485. else:
  486. list = (
  487. (_("Yes"), "quit"),
  488. (_("Yes, returning to movie list"), "movielist"),
  489. (_("Yes, and delete this movie"), "quitanddelete"),
  490. (_("Yes, delete this movie and return to movie list"), "deleteandmovielist"),
  491. (_("No"), "continue"),
  492. (_("No, but restart from begin"), "restart")
  493. )
  494. from Screens.ChoiceBox import ChoiceBox
  495. self.session.openWithCallback(self.leavePlayerConfirmed, ChoiceBox, title=_("Stop playing this movie?"), list = list)
  496. else:
  497. self.leavePlayerConfirmed([True, how])
  498. def leavePlayer(self):
  499. setResumePoint(self.session)
  500. self.handleLeave(config.usage.on_movie_stop.value)
  501. def leavePlayerOnExit(self):
  502. if self.shown:
  503. self.hide()
  504. elif self.session.pipshown and "popup" in config.usage.pip_hideOnExit.value:
  505. if config.usage.pip_hideOnExit.value == "popup":
  506. self.session.openWithCallback(self.hidePipOnExitCallback, MessageBox, _("Disable Picture in Picture"), simple=True)
  507. else:
  508. self.hidePipOnExitCallback(True)
  509. elif config.usage.leave_movieplayer_onExit.value == "popup":
  510. self.session.openWithCallback(self.leavePlayerOnExitCallback, MessageBox, _("Exit movie player?"), simple=True)
  511. elif config.usage.leave_movieplayer_onExit.value == "without popup":
  512. self.leavePlayerOnExitCallback(True)
  513. def leavePlayerOnExitCallback(self, answer):
  514. if answer:
  515. setResumePoint(self.session)
  516. self.handleLeave("quit")
  517. def hidePipOnExitCallback(self, answer):
  518. if answer:
  519. self.showPiP()
  520. def deleteConfirmed(self, answer):
  521. if answer:
  522. self.leavePlayerConfirmed((True, "quitanddeleteconfirmed"))
  523. def deleteAndMovielistConfirmed(self, answer):
  524. if answer:
  525. self.leavePlayerConfirmed((True, "deleteandmovielistconfirmed"))
  526. def movielistAgain(self):
  527. from Screens.MovieSelection import playlist
  528. del playlist[:]
  529. self.session.nav.playService(self.lastservice)
  530. self.leavePlayerConfirmed((True, "movielist"))
  531. def leavePlayerConfirmed(self, answer):
  532. answer = answer and answer[1]
  533. if answer is None:
  534. return
  535. if answer in ("quitanddelete", "quitanddeleteconfirmed", "deleteandmovielist", "deleteandmovielistconfirmed"):
  536. ref = self.session.nav.getCurrentlyPlayingServiceOrGroup()
  537. serviceHandler = enigma.eServiceCenter.getInstance()
  538. if answer in ("quitanddelete", "deleteandmovielist"):
  539. msg = ''
  540. if config.usage.movielist_trashcan.value:
  541. import Tools.Trashcan
  542. try:
  543. trash = Tools.Trashcan.createTrashFolder(ref.getPath())
  544. Screens.MovieSelection.moveServiceFiles(ref, trash)
  545. # Moved to trash, okay
  546. if answer == "quitanddelete":
  547. self.close()
  548. else:
  549. self.movielistAgain()
  550. return
  551. except Exception, e:
  552. print "[InfoBar] Failed to move to .Trash folder:", e
  553. msg = _("Cannot move to trash can") + "\n" + str(e) + "\n"
  554. info = serviceHandler.info(ref)
  555. name = info and info.getName(ref) or _("this recording")
  556. msg += _("Do you really want to delete %s?") % name
  557. if answer == "quitanddelete":
  558. self.session.openWithCallback(self.deleteConfirmed, MessageBox, msg)
  559. elif answer == "deleteandmovielist":
  560. self.session.openWithCallback(self.deleteAndMovielistConfirmed, MessageBox, msg)
  561. return
  562. elif answer in ("quitanddeleteconfirmed", "deleteandmovielistconfirmed"):
  563. offline = serviceHandler.offlineOperations(ref)
  564. if offline.deleteFromDisk(0):
  565. self.session.openWithCallback(self.close, MessageBox, _("You cannot delete this!"), MessageBox.TYPE_ERROR)
  566. if answer == "deleteandmovielistconfirmed":
  567. self.movielistAgain()
  568. return
  569. if answer in ("quit", "quitanddeleteconfirmed"):
  570. self.close()
  571. elif answer in ("movielist", "deleteandmovielistconfirmed"):
  572. if config.movielist.stop_service.value:
  573. ref = self.session.nav.getCurrentlyPlayingServiceOrGroup()
  574. else:
  575. ref = self.lastservice
  576. self.returning = True
  577. self.session.openWithCallback(self.movieSelected, Screens.MovieSelection.MovieSelection, ref)
  578. self.session.nav.stopService()
  579. if not config.movielist.stop_service.value:
  580. self.session.nav.playService(self.lastservice)
  581. elif answer == "restart":
  582. self.doSeek(0)
  583. self.setSeekState(self.SEEK_STATE_PLAY)
  584. elif answer in ("playlist","playlistquit","loop"):
  585. ( next_service, item , length ) = self.getPlaylistServiceInfo(self.cur_service)
  586. if next_service is not None:
  587. if config.usage.next_movie_msg.value:
  588. self.displayPlayedName(next_service, item, length)
  589. self.session.nav.playService(next_service)
  590. self.cur_service = next_service
  591. else:
  592. if answer == "playlist":
  593. self.leavePlayerConfirmed([True,"movielist"])
  594. elif answer == "loop" and length > 0:
  595. self.leavePlayerConfirmed([True,"loop"])
  596. else:
  597. self.leavePlayerConfirmed([True,"quit"])
  598. elif answer in "repeatcurrent":
  599. if config.usage.next_movie_msg.value:
  600. (item, length) = self.getPlaylistServiceInfo(self.cur_service)
  601. self.displayPlayedName(self.cur_service, item, length)
  602. self.session.nav.stopService()
  603. self.session.nav.playService(self.cur_service)
  604. def doEofInternal(self, playing):
  605. if not self.execing:
  606. return
  607. if not playing :
  608. return
  609. ref = self.session.nav.getCurrentlyPlayingServiceOrGroup()
  610. if ref:
  611. delResumePoint(ref)
  612. self.handleLeave(config.usage.on_movie_eof.value)
  613. def up(self):
  614. slist = self.servicelist
  615. if slist and slist.dopipzap:
  616. if "keep" not in config.usage.servicelist_cursor_behavior.value:
  617. slist.moveUp()
  618. self.session.execDialog(slist)
  619. else:
  620. self.showMovies()
  621. def down(self):
  622. slist = self.servicelist
  623. if slist and slist.dopipzap:
  624. if "keep" not in config.usage.servicelist_cursor_behavior.value:
  625. slist.moveDown()
  626. self.session.execDialog(slist)
  627. else:
  628. self.showMovies()
  629. def right(self):
  630. # XXX: gross hack, we do not really seek if changing channel in pip :-)
  631. slist = self.servicelist
  632. if slist and slist.dopipzap:
  633. # XXX: We replicate InfoBarChannelSelection.zapDown here - we shouldn't do that
  634. if slist.inBouquet():
  635. prev = slist.getCurrentSelection()
  636. if prev:
  637. prev = prev.toString()
  638. while True:
  639. if config.usage.quickzap_bouquet_change.value and slist.atEnd():
  640. slist.nextBouquet()
  641. else:
  642. slist.moveDown()
  643. cur = slist.getCurrentSelection()
  644. if not cur or (not (cur.flags & 64)) or cur.toString() == prev:
  645. break
  646. else:
  647. slist.moveDown()
  648. slist.zap(enable_pipzap = True)
  649. else:
  650. InfoBarSeek.seekFwd(self)
  651. def left(self):
  652. slist = self.servicelist
  653. if slist and slist.dopipzap:
  654. # XXX: We replicate InfoBarChannelSelection.zapUp here - we shouldn't do that
  655. if slist.inBouquet():
  656. prev = slist.getCurrentSelection()
  657. if prev:
  658. prev = prev.toString()
  659. while True:
  660. if config.usage.quickzap_bouquet_change.value:
  661. if slist.atBegin():
  662. slist.prevBouquet()
  663. slist.moveUp()
  664. cur = slist.getCurrentSelection()
  665. if not cur or (not (cur.flags & 64)) or cur.toString() == prev:
  666. break
  667. else:
  668. slist.moveUp()
  669. slist.zap(enable_pipzap = True)
  670. else:
  671. InfoBarSeek.seekBack(self)
  672. def showPiP(self):
  673. slist = self.servicelist
  674. if self.session.pipshown:
  675. if slist and slist.dopipzap:
  676. slist.togglePipzap()
  677. if self.session.pipshown:
  678. del self.session.pip
  679. self.session.pipshown = False
  680. else:
  681. service = self.session.nav.getCurrentService()
  682. info = service and service.info()
  683. xres = str(info.getInfo(enigma.iServiceInformation.sVideoWidth))
  684. if int(xres) <= 720 or not getMachineBuild() == 'blackbox7405':
  685. from Screens.PictureInPicture import PictureInPicture
  686. self.session.pip = self.session.instantiateDialog(PictureInPicture)
  687. self.session.pip.show()
  688. if self.session.pip.playService(slist.getCurrentSelection()):
  689. self.session.pipshown = True
  690. self.session.pip.servicePath = slist.getCurrentServicePath()
  691. else:
  692. self.session.pipshown = False
  693. del self.session.pip
  694. else:
  695. self.session.open(MessageBox, _("Your %s %s does not support PiP HD") % (getMachineBrand(), getMachineName()), type = MessageBox.TYPE_INFO,timeout = 5 )
  696. def movePiP(self):
  697. if self.session.pipshown:
  698. InfoBarPiP.movePiP(self)
  699. def swapPiP(self):
  700. pass
  701. def showMovies(self):
  702. ref = self.session.nav.getCurrentlyPlayingServiceOrGroup()
  703. if ref and ':0:/' not in ref.toString():
  704. self.playingservice = ref # movie list may change the currently playing
  705. else:
  706. self.playingservice = enigma.eServiceReference(config.movielist.curentlyplayingservice.value)
  707. self.session.openWithCallback(self.movieSelected, Screens.MovieSelection.MovieSelection, ref)
  708. def movieSelected(self, service):
  709. if service is not None:
  710. self.cur_service = service
  711. self.is_closing = False
  712. self.session.nav.playService(service)
  713. self.returning = False
  714. elif self.returning:
  715. self.close()
  716. else:
  717. self.is_closing = False
  718. try:
  719. ref = self.playingservice
  720. del self.playingservice
  721. # no selection? Continue where we left off
  722. if ref and not self.session.nav.getCurrentlyPlayingServiceOrGroup():
  723. self.session.nav.playService(ref)
  724. except:
  725. pass
  726. def getPlaylistServiceInfo(self, service):
  727. from MovieSelection import playlist
  728. for i, item in enumerate(playlist):
  729. if item == service:
  730. if config.usage.on_movie_eof.value == "repeatcurrent":
  731. return i+1, len(playlist)
  732. i += 1
  733. if i < len(playlist):
  734. return playlist[i], i+1, len(playlist)
  735. elif config.usage.on_movie_eof.value == "loop":
  736. return playlist[0], 1, len(playlist)
  737. return None, 0, 0
  738. def displayPlayedName(self, ref, index, n):
  739. from Tools import Notifications
  740. Notifications.AddPopup(text = _("%s/%s: %s") % (index, n, self.ref2HumanName(ref)), type = MessageBox.TYPE_INFO, timeout = 5)
  741. def ref2HumanName(self, ref):
  742. return enigma.eServiceCenter.getInstance().info(ref).getName(ref)