Skip to content

Commit

Permalink
movie api
Browse files Browse the repository at this point in the history
* add movieresumepoint
  • Loading branch information
jbleyel committed May 26, 2024
1 parent 01f169f commit 5beb6dc
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 15 deletions.
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.1.1"
__version__ = "2.2.0"
92 changes: 81 additions & 11 deletions plugin/controllers/models/movies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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:])
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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,
}
22 changes: 19 additions & 3 deletions plugin/controllers/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 (?).
Expand Down

0 comments on commit 5beb6dc

Please sign in to comment.