From 5beb6dc82a54d656cd491c89178cad3a6dc14087 Mon Sep 17 00:00:00 2001 From: jbleyel Date: Sun, 26 May 2024 20:11:47 +0200 Subject: [PATCH] movie api * add movieresumepoint --- CHANGES.md | 9 +++ plugin/__init__.py | 2 +- plugin/controllers/models/movies.py | 92 +++++++++++++++++++++++++---- plugin/controllers/web.py | 22 ++++++- 4 files changed, 110 insertions(+), 15 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b9a4d581..f7a41025 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,12 @@ +## Version 2.2.0 +* add movieresumepoint to movie api +* add streamrelay flag to epg api +* add showstreamrelay, showall, noiptv parameter to getservices api +* add support for new ConfigSelectionInteger +* add support for new allowDefault setup.xml attribute +* add new url parameter "returntimer" for timeradd and timerchange api to return the timerdata in response +* add api/epgservicenownext + ## Version 2.1.1 * show lcn in bouquet editor * add more options to servicelist reload api diff --git a/plugin/__init__.py b/plugin/__init__.py index 58039f50..8a124bf6 100644 --- a/plugin/__init__.py +++ b/plugin/__init__.py @@ -1 +1 @@ -__version__ = "2.1.1" +__version__ = "2.2.0" diff --git a/plugin/controllers/models/movies.py b/plugin/controllers/models/movies.py index 2f0ab58f..9e9fa78f 100644 --- a/plugin/controllers/models/movies.py +++ b/plugin/controllers/models/movies.py @@ -22,7 +22,7 @@ from os.path import join as pathjoin, split as pathsplit, realpath, abspath, isdir, splitext, exists, isfile, normpath from struct import Struct -from time import localtime +from time import localtime, time from urllib.parse import unquote from glob import glob @@ -174,7 +174,7 @@ def getMovieList(rargs=None, locations=None, directory=None): # BAD fix _serviceref = serviceref.toString().replace('%25', '%') - length_minutes = 0 + length = 0 txtdesc = "" filename = '/'.join(_serviceref.split("/")[1:]) filename = '/' + filename @@ -205,14 +205,14 @@ def getMovieList(rargs=None, locations=None, directory=None): movie['begintime'] = FuzzyTime2(rtime) try: - length_minutes = info.getLength(serviceref) + length = info.getLength(serviceref) except: # nosec # noqa: E722 pass - if length_minutes: - movie['length'] = "%d:%02d" % (length_minutes / 60, length_minutes % 60) + if length: + movie['length'] = "%d:%02d" % (length / 60, length % 60) if fields is None or 'pos' in fields: - movie['lastseen'] = moviePlayState(filename + '.cuts', serviceref, length_minutes) or 0 + movie['lastseen'] = moviePlayState(filename + '.cuts', serviceref, length) or 0 if fields is None or 'desc' in fields: txtfile = name + '.txt' @@ -596,7 +596,7 @@ def getMovieDetails(sref=None): service = ServiceReference(sref) if service is not None: serviceref = service.ref - length_minutes = 0 + length = 0 txtdesc = "" fullpath = serviceref.getPath() filename = '/'.join(fullpath.split("/")[1:]) @@ -631,13 +631,13 @@ def getMovieDetails(sref=None): movie['begintime'] = FuzzyTime2(rtime) try: - length_minutes = info.getLength(serviceref) + length = info.getLength(serviceref) except: # nosec # noqa: E722 pass - if length_minutes: - movie['length'] = "%d:%02d" % (length_minutes / 60, length_minutes % 60) - movie['lastseen'] = moviePlayState(filename + '.cuts', serviceref, length_minutes) or 0 + if length: + movie['length'] = "%d:%02d" % (length / 60, length % 60) + movie['lastseen'] = moviePlayState(filename + '.cuts', serviceref, length) or 0 txtfile = name + '.txt' if ext.lower() != '.ts' and isfile(txtfile): @@ -677,3 +677,73 @@ def getMovieDetails(sref=None): return { "result": False, } + + +def setMovieResumePoint(sref, resumepoint): + service = ServiceReference(sref) + if service is not None: + try: + servicehandler = eServiceCenter.getInstance() + info = servicehandler.info(service.ref) + length = info.getLength(service.ref) + except: # nosec # noqa: E722 + length = 0 + + if length: + try: + from Screens.InfoBarGenerics import resumePointCache + resumePointCache[service.ref.toString()] = (int(time()), resumepoint, length * 90000) + except: + pass + + fullpath = service.ref.getPath() + srcPath, srcName = pathsplit(fullpath) + + cutsfilename = pathjoin(srcPath, f"{srcName}.cuts") + if exists(cutsfilename): + oldcuts = [] + oldresume = 0 + try: + with open(cutsfilename, 'rb') as fd: + while True: + data = fd.read(cutsParser.size) + if len(data) < cutsParser.size: + break + _pos, _type = cutsParser.unpack(data) + oldcuts.append((_pos, _type)) + if _type == 3: + oldresume = _pos + except OSError as err: + return { + "result": False, + "error": str(err) + } + + try: + newcuts = [] + if oldresume: + for cut in oldcuts: + if cut[1] == 3: + newcuts.append((resumepoint, cut[1])) + else: + newcuts.append((cut[0], cut[1])) + else: + newcuts = oldcuts + newcuts.append((resumepoint, 3)) + + with open(cutsfilename, 'wb') as fd: + for cut in newcuts: + fd.write(cutsParser.pack(int(cut[0]), int(cut[1]))) + except OSError as err: + return { + "result": False, + "error": str(err) + } + + return { + "result": True + } + + return { + "result": False, + } diff --git a/plugin/controllers/web.py b/plugin/controllers/web.py index d0d4b1d7..1479e904 100644 --- a/plugin/controllers/web.py +++ b/plugin/controllers/web.py @@ -31,7 +31,7 @@ from .models.locations import getLocations, getCurrentLocation, addLocation, removeLocation from .models.timers import getTimers, addTimer, addTimerByEventId, editTimer, removeTimer, toggleTimerStatus, cleanupTimer, writeTimerList, recordNow, tvbrowser, getSleepTimer, setSleepTimer, getPowerTimer, setPowerTimer, getVPSChannels from .models.message import sendMessage, getMessageAnswer -from .models.movies import getMovieList, removeMovie, getMovieInfo, movieAction, getAllMovies, getMovieDetails, MOVIETAGFILE +from .models.movies import getMovieList, removeMovie, getMovieInfo, movieAction, getAllMovies, getMovieDetails, setMovieResumePoint, MOVIETAGFILE from .models.config import getSettings, addCollapsedMenu, removeCollapsedMenu, saveConfig, getConfigs, getConfigsSections, getUtcOffset from .models.stream import getStream, getTS, getStreamSubservices, GetSession from .models.servicelist import reloadServicesLists @@ -1005,8 +1005,24 @@ def P_moviedetails(self, request): "result": False } - # a duplicate api ?? - def P_gettags(self, request): + def P_movieresumepoint(self, request): + sref = getUrlArg(request, "sRef") + if sref is None: + sref = getUrlArg(request, "sref") + + try: + resumepoint = int(request.args[b"resumepoint"][0]) * 90000 # in seconds + except (ValueError, KeyError): # nosec # noqa: E722 + resumepoint = None + + if sref and resumepoint: + return setMovieResumePoint(sref, resumepoint) + else: + return { + "result": False + } + + def P_gettags(self, request): # a duplicate api ?? """ Request handler for the `gettags` endpoint. Get tags of movie file (?).