mirror of
https://github.com/fHDHR/fHDHR_NextPVR.git
synced 2025-12-06 08:26:57 -05:00
61 lines
2.2 KiB
Python
61 lines
2.2 KiB
Python
from flask import Response, request, redirect
|
|
import urllib.parse
|
|
import json
|
|
|
|
|
|
class EPG():
|
|
"""Methods to create xmltv.xml"""
|
|
endpoints = ["/api/epg"]
|
|
endpoint_name = "api_epg"
|
|
endpoint_methods = ["GET", "POST"]
|
|
|
|
def __init__(self, fhdhr):
|
|
self.fhdhr = fhdhr
|
|
|
|
def __call__(self, *args):
|
|
return self.get(*args)
|
|
|
|
def get(self, *args):
|
|
|
|
method = request.args.get('method', default="get", type=str)
|
|
|
|
source = request.args.get('source', default=self.fhdhr.config.dict["epg"]["def_method"], type=str)
|
|
if source not in self.fhdhr.config.dict["epg"]["valid_epg_methods"]:
|
|
return "%s Invalid xmltv method" % source
|
|
|
|
redirect_url = request.args.get('redirect', default=None, type=str)
|
|
|
|
if method == "get":
|
|
|
|
epgdict = self.fhdhr.device.epg.get_epg(source)
|
|
if source in ["blocks", "origin", self.fhdhr.config.dict["main"]["dictpopname"]]:
|
|
epgdict = epgdict.copy()
|
|
for c in list(epgdict.keys()):
|
|
chan_obj = self.fhdhr.device.channels.get_channel_obj("origin_id", epgdict[c]["id"])
|
|
epgdict[chan_obj.dict["number"]] = epgdict.pop(c)
|
|
epgdict[chan_obj.dict["number"]]["name"] = chan_obj.dict["name"]
|
|
epgdict[chan_obj.dict["number"]]["callsign"] = chan_obj.dict["callsign"]
|
|
epgdict[chan_obj.dict["number"]]["number"] = chan_obj.dict["number"]
|
|
epgdict[chan_obj.dict["number"]]["id"] = chan_obj.dict["origin_id"]
|
|
epgdict[chan_obj.dict["number"]]["thumbnail"] = chan_obj.thumbnail
|
|
|
|
epg_json = json.dumps(epgdict, indent=4)
|
|
|
|
return Response(status=200,
|
|
response=epg_json,
|
|
mimetype='application/json')
|
|
|
|
elif method == "update":
|
|
self.fhdhr.device.epg.update(source)
|
|
|
|
elif method == "clearcache":
|
|
self.fhdhr.device.epg.clear_epg_cache(source)
|
|
|
|
else:
|
|
return "%s Invalid Method" % method
|
|
|
|
if redirect_url:
|
|
return redirect(redirect_url + "?retmessage=" + urllib.parse.quote("%s Success" % method))
|
|
else:
|
|
return "%s Success" % method
|