Skip to content

Commit 29375ab

Browse files
DimitarCCfairbird
authored andcommitted
Nav extensions
1 parent c7092e1 commit 29375ab

File tree

4 files changed

+77
-11
lines changed

4 files changed

+77
-11
lines changed

lib/python/Components/Sources/CurrentService.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,18 @@ def serviceEvent(self, event):
3838
def getCurrentService(self):
3939
return self.srv or self.navcore.getCurrentService()
4040

41+
def getCurrentServiceReference(self):
42+
return self.navcore.getCurrentlyPlayingServiceReference()
43+
4144
service = property(getCurrentService)
4245

46+
def getCurrentServiceWithFallback(self):
47+
return self.srv or self.navcore.getCurrentService()
48+
49+
# this gets current service (set manually) with a fallback to the selected service from navigation.
50+
# Typically that is used in ServiceName convertor.
51+
servicealt = property(getCurrentServiceWithFallback)
52+
4353
@cached
4454
def getCurrentServiceRef(self):
4555
if self.ref:
@@ -48,6 +58,9 @@ def getCurrentServiceRef(self):
4858
return self.srv or NavigationInstance.instance.getCurrentlyPlayingServiceOrGroup()
4959
return None
5060

61+
# Setter added for iptv-m3u-reader plugin. For more info see:
62+
# https://github.com/DimitarCC/iptv-m3u-reader/commit/08d93986f0f00de6d0ff172abd0bb7b641921bda#diff-834f0679bc61d0427df924d74c20767d5b8fa62227d824361dd81555df6f6725R477-R482
63+
5164
def setCurrentServiceRef(self, ref):
5265
self.ref = ref
5366

lib/python/Navigation.py

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525

2626
class Navigation:
27+
playServiceExtensions = []
28+
recordServiceExtensions = []
2729
def __init__(self):
2830
if NavigationInstance.instance is not None:
2931
raise NavigationInstance.instance
@@ -44,6 +46,7 @@ def __init__(self):
4446
self.currentlyPlayingServiceReference = None
4547
self.currentlyPlayingServiceOrGroup = None
4648
self.currentlyPlayingService = None
49+
self.originalPlayingServiceReference = None
4750
self.isCurrentServiceStreamRelay = False
4851
self.RecordTimer = RecordTimer.RecordTimer()
4952
self.__wasTimerWakeup = getFPWasTimerWakeup()
@@ -117,7 +120,14 @@ def serviceHook(self, ref):
117120
AddPopup(text=wrappererror, type=MessageBox.TYPE_ERROR, timeout=5, id="channelzapwrapper")
118121
return nref, wrappererror
119122

120-
def playService(self, ref, checkParentalControl=True, forceRestart=False, adjust=True, ignoreStreamRelay=False):
123+
def playService(self, ref, checkParentalControl=True, forceRestart=False, adjust=True, ignoreStreamRelay=False, event=None):
124+
# Some plugins send None as ref becasue want to shutdown enigma play system.
125+
# So we have to stop current service if someone send None.
126+
if ref is None:
127+
self.stopService()
128+
return 0
129+
130+
InfoBarInstance = InfoBar.instance
121131
session = None
122132
startPlayingServiceOrGroup = None
123133
count = isinstance(adjust, list) and len(adjust) or 0
@@ -127,15 +137,33 @@ def playService(self, ref, checkParentalControl=True, forceRestart=False, adjust
127137
startPlayingServiceOrGroup = adjust[2]
128138
adjust = adjust[0]
129139
oldref = self.currentlyPlayingServiceOrGroup
140+
current_service_source = None
141+
is_handled = False
142+
if InfoBarInstance:
143+
current_service_source = InfoBarInstance.session.screen["CurrentService"]
144+
145+
if "%3a//" in ref.toString():
146+
self.currentlyPlayingServiceReference = None
147+
self.currentlyPlayingService = None
148+
if current_service_source:
149+
current_service_source.newService(False)
150+
130151
if ref and oldref and ref == oldref and not forceRestart:
131152
print("[Navigation] ignore request to play already running service(1)")
132153
return 1
133-
print("[Navigation] playing: ", ref and ref.toString())
134-
if ref is None:
135-
self.stopService()
136-
return 0
137-
from Components.ServiceEventTracker import InfoBarCount
138-
InfoBarInstance = InfoBarCount == 1 and InfoBar.instance
154+
print("[Navigation] playing ref", ref and ref.toString())
155+
156+
self.currentlyPlayingServiceReference = ref
157+
self.currentlyPlayingServiceOrGroup = ref
158+
self.originalPlayingServiceReference = ref
159+
160+
if InfoBarInstance and current_service_source:
161+
current_service_source.serviceref = ref
162+
current_service_source.newService(ref)
163+
InfoBarInstance.session.screen["Event_Now"].updateSource(self.currentlyPlayingServiceReference)
164+
InfoBarInstance.session.screen["Event_Next"].updateSource(self.currentlyPlayingServiceReference)
165+
InfoBarInstance.serviceStarted()
166+
139167
isStreamRelay = False
140168
if not checkParentalControl or parentalControl.isServicePlayable(ref, boundFunction(self.playService, checkParentalControl=False, forceRestart=forceRestart, adjust=(count > 1 and [0, session] or adjust)), session=session):
141169
if ref.flags & eServiceReference.isGroup:
@@ -165,6 +193,7 @@ def playService(self, ref, checkParentalControl=True, forceRestart=False, adjust
165193
print("[Navigation] Failed to start: ", alternativeref.toString())
166194
self.currentlyPlayingServiceReference = None
167195
self.currentlyPlayingServiceOrGroup = None
196+
self.originalPlayingServiceReference = None
168197
if oldref and ("://" in oldref.getPath() or streamrelay.checkService(oldref)):
169198
print("[Navigation] Streaming was active -> try again") # use timer to give the streamserver the time to deallocate the tuner
170199
self.retryServicePlayTimer = eTimer()
@@ -193,6 +222,13 @@ def playService(self, ref, checkParentalControl=True, forceRestart=False, adjust
193222
if wrappererror:
194223
return 1
195224
print("[Navigation] playref", playref.toString())
225+
226+
if BoxInfo.getItem("FCCactive") and "%3a//" in ref.toString() and not isStreamRelay:
227+
self.pnav.stopService()
228+
229+
for f in Navigation.playServiceExtensions:
230+
playref, is_handled = f(self, playref, event, InfoBarInstance)
231+
196232
self.currentlyPlayingServiceOrGroup = ref
197233
if startPlayingServiceOrGroup and startPlayingServiceOrGroup.flags & eServiceReference.isGroup and not ref.flags & eServiceReference.isGroup:
198234
self.currentlyPlayingServiceOrGroup = startPlayingServiceOrGroup
@@ -239,9 +275,11 @@ def playService(self, ref, checkParentalControl=True, forceRestart=False, adjust
239275
self.firstStart = False
240276
self.retryServicePlayTimer.start(delay, True)
241277
return 0
242-
elif self.pnav.playService(playref):
278+
elif not is_handled and self.pnav.playService(playref):
243279
print("[Navigation] Failed to start: ", playref.toString())
280+
current_service_source.serviceref = None
244281
self.currentlyPlayingServiceReference = None
282+
self.originalPlayingServiceReference = None
245283
self.currentlyPlayingServiceOrGroup = None
246284
if oldref and ("://" in oldref.getPath() or streamrelay.checkService(oldref)):
247285
print("[Navigation] Streaming was active -> try again") # use timer to give the streamserver the time to deallocate the tuner
@@ -252,6 +290,9 @@ def playService(self, ref, checkParentalControl=True, forceRestart=False, adjust
252290
self.isCurrentServiceStreamRelay = True
253291
if setPriorityFrontend:
254292
setPreferredTuner(int(config.usage.frontend_priority.value))
293+
if InfoBarInstance and "%3a//" in playref.toString() and not is_handled:
294+
current_service_source.serviceref = None
295+
InfoBarInstance.serviceStarted()
255296
return 0
256297
elif oldref and InfoBarInstance and InfoBarInstance.servicelist.servicelist.setCurrent(oldref, adjust):
257298
self.currentlyPlayingServiceOrGroup = InfoBarInstance.servicelist.servicelist.getCurrent()
@@ -261,7 +302,12 @@ def getCurrentlyPlayingServiceReference(self):
261302
return self.currentlyPlayingServiceReference
262303

263304
def getCurrentlyPlayingServiceOrGroup(self):
264-
return self.currentlyPlayingServiceOrGroup
305+
if not self.currentlyPlayingServiceOrGroup:
306+
return None
307+
return self.originalPlayingServiceReference or self.currentlyPlayingServiceOrGroup
308+
309+
def getCurrentServiceReferenceOriginal(self):
310+
return self.originalPlayingServiceReference
265311

266312
def getCurrentServiceRef(self):
267313
curPlayService = self.getCurrentService()
@@ -283,6 +329,8 @@ def recordService(self, ref, simulate=False):
283329
if ref:
284330
if ref.flags & eServiceReference.isGroup:
285331
ref = getBestPlayableServiceReference(ref, eServiceReference(), simulate)
332+
for f in Navigation.recordServiceExtensions:
333+
ref = f(self, ref)
286334
if type != (pNavigation.isPseudoRecording | pNavigation.isFromEPGrefresh):
287335
ref, isStreamRelay = streamrelay.streamrelayChecker(ref)
288336
#if not isStreamRelay:

lib/python/Screens/InfoBarGenerics.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ def __setData(self, value):
269269
data = property(__getData, __setData)
270270

271271
def streamrelayChecker(self, playref):
272+
is_stream_relay = False
272273
playrefstring = playref.toCompareString()
273274
if "%3a//" not in playrefstring and playrefstring in self.__services:
274275
url = f'http://{".".join("%d" % d for d in config.misc.softcam_streamrelay_url.value)}:{config.misc.softcam_streamrelay_port.value}/'
@@ -277,10 +278,11 @@ def streamrelayChecker(self, playref):
277278
else:
278279
playrefmod = playrefstring
279280
playref = eServiceReference("%s%s%s:%s" % (playrefmod, url.replace(":", "%3a"), playrefstring.replace(":", "%3a"), ServiceReference(playref).getServiceName()))
281+
is_stream_relay = True
280282
print(f"[{self.__class__.__name__}] Play service {playref.toCompareString()} via streamrelay")
281283
playref.setAlternativeUrl(playrefstring)
282-
return playref, True
283-
return playref, False
284+
return playref, True, is_stream_relay
285+
return playref, False, is_stream_relay
284286

285287
def checkService(self, service):
286288
return service and service.toCompareString() in self.__services

lib/python/Screens/PictureInPicture.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class PictureInPictureZapping(Screen):
5757

5858

5959
class PictureInPicture(Screen):
60+
playServiceExtensions = []
6061
def __init__(self, session):
6162
global pip_config_initialized
6263
Screen.__init__(self, session)
@@ -195,6 +196,8 @@ def playService(self, service):
195196
return False
196197
from Screens.InfoBarGenerics import streamrelay
197198
ref, isStreamRelay = streamrelay.streamrelayChecker(self.resolveAlternatePipService(service))
199+
for f in PictureInPicture.playServiceExtensions:
200+
ref = f(self, ref)
198201
if ref:
199202
if BoxInfo.getItem("CanNotDoSimultaneousTranscodeAndPIP") and StreamServiceList:
200203
self.pipservice = None

0 commit comments

Comments
 (0)