Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 25 additions & 21 deletions src/plugin/e2utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def toString(text):
return text
return str(text)


def getAspect():
val = AVSwitch().getAspectRatioSetting()
if val == 0 or val == 1:
Expand All @@ -36,32 +37,37 @@ def getAspect():
r = (16 * 576, 10 * 720)
return r


def getPlayPositionPts(session):
service = session.nav.getCurrentService()
seek = service and service.seek()
position = seek and seek.getPlayPosition()
position = position and not position[0] and position[1] or None
return position


def getPlayPositionInSeconds(session):
position = getPlayPositionPts(session)
if position is not None:
position = position / 90000
return position


def getDurationPts(session):
service = session.nav.getCurrentService()
seek = service and service.seek()
duration = seek and seek.getLength()
duration = duration and not duration[0] and duration[1] or None
return duration


def getDurationInSeconds(session):
duration = getDurationPts(session)
if duration is not None:
duration = duration / 90000
return duration


def seekToPts(session, pts):
service = session.nav.getCurrentService()
seek = service and service.seek()
Expand All @@ -82,7 +88,7 @@ def __init__(self, default=None, cachedir='/tmp/', caching=True):
self.picload.PictureData.get().append(self.setPixmapCB)

def applySkin(self, desktop, parent):
attribs = [ ]
attribs = []
if self.skinAttributes is not None:
for (attrib, value) in self.skinAttributes:
if attrib == "default":
Expand Down Expand Up @@ -169,8 +175,7 @@ def __init__(self, session, updateIntervalInMs=500):
self.updateIntervalInMs = updateIntervalInMs
self.updateTimer = eTimer()
self.updateTimer.callback.append(self.updateStatus)
self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
{
self.__event_tracker = ServiceEventTracker(screen=self, eventmap={
iPlayableService.evBuffering: self.__evBuffering,
iPlayableService.evStart: self.__evStart,
iPlayableService.evStopped: self.__evStopped,
Expand Down Expand Up @@ -211,30 +216,30 @@ def __init__(self):
self.onClose.append(self.bufferScreen.hide)
self.onClose.append(self.bufferScreen.doClose)


class InfoBarAspectChange(object):
"""
Simple aspect ratio changer
"""
V_DICT = {
'16_9_letterbox':{'aspect':'16:9', 'policy2':'letterbox', 'title':'16:9 ' + _("Letterbox")},
'16_9_panscan':{'aspect':'16:9', 'policy2':'panscan', 'title':'16:9 ' + _("Pan&scan")},
'16_9_nonlinear':{'aspect':'16:9', 'policy2':'panscan', 'title':'16:9 ' + _("Nonlinear")},
'16_9_bestfit':{'aspect':'16:9', 'policy2':'bestfit', 'title':'16:9 ' + _("Just scale")},
'16_9_4_3_pillarbox':{'aspect':'16:9', 'policy':'pillarbox', 'title':'4:3 ' + _("PillarBox")},
'16_9_4_3_panscan':{'aspect':'16:9', 'policy':'panscan', 'title':'4:3 ' + _("Pan&scan")},
'16_9_4_3_nonlinear':{'aspect':'16:9', 'policy':'nonlinear', 'title':'4:3 ' + _("Nonlinear")},
'16_9_4_3_bestfit':{'aspect':'16:9', 'policy':'bestfit', 'title':_("Just scale")},
'4_3_letterbox':{'aspect':'4:3', 'policy':'letterbox', 'policy2':'policy', 'title':_("Letterbox")},
'4_3_panscan':{'aspect':'4:3', 'policy':'panscan', 'policy2':'policy', 'title':_("Pan&scan")},
'4_3_bestfit':{'aspect':'4:3', 'policy':'bestfit', 'policy2':'policy', 'title':_("Just scale")}
'16_9_letterbox': {'aspect': '16:9', 'policy2': 'letterbox', 'title': '16:9 ' + _("Letterbox")},
'16_9_panscan': {'aspect': '16:9', 'policy2': 'panscan', 'title': '16:9 ' + _("Pan&scan")},
'16_9_nonlinear': {'aspect': '16:9', 'policy2': 'panscan', 'title': '16:9 ' + _("Nonlinear")},
'16_9_bestfit': {'aspect': '16:9', 'policy2': 'bestfit', 'title': '16:9 ' + _("Just scale")},
'16_9_4_3_pillarbox': {'aspect': '16:9', 'policy': 'pillarbox', 'title': '4:3 ' + _("PillarBox")},
'16_9_4_3_panscan': {'aspect': '16:9', 'policy': 'panscan', 'title': '4:3 ' + _("Pan&scan")},
'16_9_4_3_nonlinear': {'aspect': '16:9', 'policy': 'nonlinear', 'title': '4:3 ' + _("Nonlinear")},
'16_9_4_3_bestfit': {'aspect': '16:9', 'policy': 'bestfit', 'title': _("Just scale")},
'4_3_letterbox': {'aspect': '4:3', 'policy': 'letterbox', 'policy2': 'policy', 'title': _("Letterbox")},
'4_3_panscan': {'aspect': '4:3', 'policy': 'panscan', 'policy2': 'policy', 'title': _("Pan&scan")},
'4_3_bestfit': {'aspect': '4:3', 'policy': 'bestfit', 'policy2': 'policy', 'title': _("Just scale")}
}

V_MODES = ['16_9_letterbox', '16_9_panscan', '16_9_nonlinear', '16_9_bestfit',
'16_9_4_3_pillarbox', '16_9_4_3_panscan', '16_9_4_3_nonlinear', '16_9_4_3_bestfit',
'4_3_letterbox', '4_3_panscan', '4_3_bestfit'
]


def __init__(self):
self.postAspectChange = []
self.aspectChanged = False
Expand All @@ -254,7 +259,7 @@ def __init__(self):

self["aspectChangeActions"] = HelpableActionMap(self, "InfoBarAspectChangeActions",
{
"aspectChange":(self.toggleAspectRatio, _("Change aspect ratio"))
"aspectChange": (self.toggleAspectRatio, _("Change aspect ratio"))
}, -3)

self.onClose.append(self.__onClose)
Expand Down Expand Up @@ -348,8 +353,8 @@ def hideStatus(self):
# pretty much openpli's one but simplified
class InfoBarSubservicesSupport(object):
def __init__(self):
self["InfoBarSubservicesActions"] = HelpableActionMap(self,
"ColorActions", { "green": (self.showSubservices, _("Show subservices"))}, -2)
self["InfoBarSubservicesActions"] = HelpableActionMap(self,
"ColorActions", {"green": (self.showSubservices, _("Show subservices"))}, -2)
self.__timer = eTimer()
self.__timer.callback.append(self.__seekToCurrentPosition)
self.onClose.append(self.__timer.stop)
Expand All @@ -369,8 +374,8 @@ def showSubservices(self):
choice_list.append((subservice_ref.getName(), subservice_ref))
if numsubservices > 1:
self.session.openWithCallback(self.subserviceSelected, ChoiceBox,
title = _("Please select subservice..."), list = choice_list,
selection = selection, skin_name="SubserviceSelection")
title=_("Please select subservice..."), list=choice_list,
selection=selection, skin_name="SubserviceSelection")

def subserviceSelected(self, service_ref):
if service_ref:
Expand All @@ -388,4 +393,3 @@ def __seekToCurrentPosition(self):
else:
seekToPts(self.session, self.__playpos)
del self.__playpos

42 changes: 30 additions & 12 deletions src/plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
class SubsSupport(object):
def __init__(self, *args, **kwargs):
pass

class SubsSupportStatus(object):
def __init__(self, *args, **kwargs):
pass
Expand All @@ -52,40 +53,52 @@ def __init__(self, *args, **kwargs):
SERVER_THREAD = None

_g_dw, _g_dh = 1280, 720


def SaveDesktopInfo():
global _g_dw, _g_dh
try:
_g_dw = getDesktop(0).size().width()
_g_dh = getDesktop(0).size().height()
except: _g_dw,_g_dh = 1280,720
print "[XBMC] Desktop size [%dx%d]" % (_g_dw,_g_dh)
except:
_g_dw, _g_dh = 1280, 720
print "[XBMC] Desktop size [%dx%d]" % (_g_dw, _g_dh)
open("/tmp/dw.info", "w").write(str(_g_dw) + "x" + str(_g_dh))


SaveDesktopInfo()


def FBLock():
print"[KodiLauncher] FBLock"
fbClass.getInstance().lock()


def FBUnlock():
print "[KodiLauncher] FBUnlock"
fbClass.getInstance().unlock()


def RCLock():
print "[KodiLauncher] RCLock"
eRCInput.getInstance().lock()


def RCUnlock():
print "[KodiLauncher] RCUnlock"
eRCInput.getInstance().unlock()


def kodiStopped(data, retval, extraArgs):
print '[KodiLauncher] kodi stopped: retval = %d' % retval


def kodiResumeStopped(data, retval, extraArgs):
print '[KodiLauncher] kodi resume script stopped: retval = %d' % retval
if retval > 0:
KODI_LAUNCHER.stop()


class KodiVideoPlayer(InfoBarBase, SubsSupportStatus, SubsSupport, InfoBarShowHide, InfoBarSeek, InfoBarSubservicesSupport, InfoBarAspectChange, InfoBarAudioSelection, InfoBarNotifications, HelpableScreen, Screen):
skin = """
<screen title="custom service source" position="0, 500" size="1280,220" zPosition="1" backgroundColor="#55444444" flags="wfNoBorder">
Expand Down Expand Up @@ -158,7 +171,7 @@ def __init__(self, session, playlistCallback, nextItemCallback, prevItemCallback

self.eventTracker = ServiceEventTracker(self,
{
iPlayableService.evStart : self.__evStart,
iPlayableService.evStart: self.__evStart,
})
self.onClose.append(boundFunction(self.session.deleteDialog, self.statusScreen))
self.onClose.append(boundFunction(Notifications.RemovePopup, self.RESUME_POPUP_ID))
Expand All @@ -176,7 +189,6 @@ def __evStart(self):
type=MessageBox.TYPE_INFO, enable_input=False)
self.__timer.start(500, True)


def __seekToPosition(self):
if getPlayPositionInSeconds(self.session) is None:
self.__timer.start(500, True)
Expand Down Expand Up @@ -208,6 +220,7 @@ def showAspectChanged(self):
def doEofInternal(self, playing):
self.close()


class Meta(object):
def __init__(self, meta):
self.meta = meta
Expand All @@ -229,15 +242,15 @@ def getTitle(self):
except:
season = -1
if season > 0 and episode > 0:
title += u" S%02dE%02d"%(season, episode)
title += u" S%02dE%02d" % (season, episode)
episodeTitle = vTag.get("title")
if episodeTitle:
title += u" - " + episodeTitle
else:
title = vTag.get("title") or vTag.get("originaltitle")
year = vTag.get("year")
if year and title:
title+= u" (" + str(year) + u")"
title += u" (" + str(year) + u")"
if not title:
title = self.meta.get("title")
if not title:
Expand Down Expand Up @@ -312,7 +325,8 @@ def handlePlayStatusMessage(self, status, data):
self.messageIn.put((self.kodiPlayer is not None, json.dumps(statusMessage)))

def handlePlayStopMessage(self, status, data):
FBLock(); RCLock()
FBLock()
RCLock()
self.messageIn.put((True, None))

def handleSwitchToEnigma2Message(self, status, data):
Expand All @@ -329,7 +343,8 @@ def handlePlayMessage(self, status, data):
self.logger.error("handlePlayMessage: no data!")
self.messageIn.put((False, None))
return
FBUnlock(); RCUnlock()
FBUnlock()
RCUnlock()

# parse subtitles, play path and service type from data
sType = 4097
Expand Down Expand Up @@ -368,7 +383,7 @@ def handlePlayMessage(self, status, data):
meta = {}

# create Kodi player Screen
noneFnc = lambda:None
noneFnc = lambda: None
self.kodiPlayer = SESSION.openWithCallback(self.kodiPlayerExitCB, KodiVideoPlayer,
noneFnc, noneFnc, noneFnc, noneFnc, noneFnc)

Expand Down Expand Up @@ -398,6 +413,7 @@ def kodiPlayerExitCB(self, callback=None):
self.kodiPlayer = None
self.subtitles = []


class KodiLauncher(Screen):
skin = """<screen position="fill" backgroundColor="#00000000" flags="wfNoBorder" title=" "></screen>"""

Expand Down Expand Up @@ -425,7 +441,7 @@ def psCallback(data, retval, extraArgs):
kodiProc = p.split()
if kodiProc is not None:
kodiPid = int(kodiProc[0])
print "[KodiLauncher] startup: kodi is running, pid = %d , resuming..."% kodiPid
print "[KodiLauncher] startup: kodi is running, pid = %d , resuming..." % kodiPid
self.resumeKodi(kodiPid)
else:
print "[KodiLauncher] startup: kodi is not running, starting..."
Expand All @@ -448,6 +464,7 @@ def stop(self):
self.session.nav.playService(self.previousService)
self.close()


def autoStart(reason, **kwargs):
print "[KodiLauncher] autoStart - reason = %d" % reason
global SERVER_THREAD
Expand All @@ -458,19 +475,21 @@ def autoStart(reason, **kwargs):
except OSError:
pass
SERVER = E2KodiExtServer()
SERVER_THREAD = threading.Thread(target = SERVER.serve_forever)
SERVER_THREAD = threading.Thread(target=SERVER.serve_forever)
SERVER_THREAD.start()
elif reason == 1:
SERVER.shutdown()
SERVER_THREAD.join()


def startLauncher(session, **kwargs):
RCUnlock()
global SESSION
SESSION = session
global KODI_LAUNCHER
KODI_LAUNCHER = session.open(KodiLauncher)


def Plugins(**kwargs):
from enigma import getDesktop
screenwidth = getDesktop(0).size().width()
Expand All @@ -483,4 +502,3 @@ def Plugins(**kwargs):
PluginDescriptor("Kodi", PluginDescriptor.WHERE_AUTOSTART, "Kodi Launcher", fnc=autoStart),
PluginDescriptor("Kodi", PluginDescriptor.WHERE_EXTENSIONSMENU, "Kodi Launcher", fnc=startLauncher),
PluginDescriptor("Kodi", PluginDescriptor.WHERE_PLUGINMENU, "Kodi Launcher", icon=kodiext, fnc=startLauncher)]

3 changes: 2 additions & 1 deletion src/plugin/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

logging.basicConfig(level=loglevel, format='%(name)s: %(message)s',)


class KodiExtRequestHandler(SocketServer.BaseRequestHandler):

def __init__(self, request, client_address, server):
Expand All @@ -20,7 +21,7 @@ def __init__(self, request, client_address, server):
def handle(self):
hlen = struct.calcsize('ibi')
header = self.request.recv(hlen)
opcode, status, datalen = struct.unpack('ibi',header)
opcode, status, datalen = struct.unpack('ibi', header)
if datalen > 0:
data = self.request.recv(datalen)
else:
Expand Down