1
0
mirror of https://github.com/fHDHR/fHDHR_NextPVR.git synced 2025-12-06 04:26:57 -05:00

Implement w3u standard

This commit is contained in:
deathbybandaid 2021-01-12 11:56:17 -05:00
parent 8c80c51c2a
commit 887b60b80d
3 changed files with 93 additions and 0 deletions

View File

@ -7,6 +7,7 @@ from .settings import Settings
from .channels import Channels
from .xmltv import xmlTV
from .m3u import M3U
from .w3u import W3U
from .epg import EPG
from .tuners import Tuners
from .debug import Debug_JSON
@ -30,6 +31,7 @@ class fHDHR_API():
self.channels = Channels(fhdhr)
self.xmltv = xmlTV(fhdhr)
self.m3u = M3U(fhdhr)
self.w3u = W3U(fhdhr)
self.epg = EPG(fhdhr)
self.tuners = Tuners(fhdhr)
self.debug = Debug_JSON(fhdhr)

89
fHDHR_web/api/w3u.py Normal file
View File

@ -0,0 +1,89 @@
from flask import Response, request, redirect
import urllib.parse
import json
from fHDHR.tools import channel_sort
class W3U():
endpoints = ["/api/w3u"]
endpoint_name = "api_w3u"
endpoint_methods = ["GET", "POST"]
def __init__(self, fhdhr):
self.fhdhr = fhdhr
def __call__(self, *args):
return self.get(*args)
def get(self, *args):
base_url = request.url_root[:-1]
method = request.args.get('method', default="get", type=str)
channel = request.args.get('channel', default="all", type=str)
redirect_url = request.args.get('redirect', default=None, type=str)
if method == "get":
channel_info_m3u = {
"name": self.fhdhr.config.dict["fhdhr"]["friendlyname"],
"image": '%s/favicon.ico' % base_url,
"epg": '%s/api/xmltv' % base_url,
"stations": []
}
channel_items = []
if channel == "all":
fileName = "channels.w3u"
for fhdhr_id in [x["id"] for x in self.fhdhr.device.channels.get_channels()]:
channel_obj = self.fhdhr.device.channels.list[fhdhr_id]
if channel_obj.enabled:
channel_items.append(channel_obj)
elif str(channel) in [str(x) for x in self.fhdhr.device.channels.get_channel_list("number")]:
channel_obj = self.fhdhr.device.channels.get_channel_obj("number", channel)
fileName = "%s.w3u" % channel_obj.number
if channel_obj.enabled:
channel_items.append(channel_obj)
else:
return "Channel Disabled"
else:
return "Invalid Channel"
channels_info = {}
for channel_obj in channel_items:
if self.fhdhr.config.dict["epg"]["images"] == "proxy" or not channel_obj.thumbnail:
logourl = ('%s/api/images?method=get&type=channel&id=%s' %
(base_url, str(channel_obj.dict['origin_id'])))
else:
logourl = channel_obj.thumbnail
channels_info[channel_obj.number] = {
"name": str(channel_obj.dict['name']),
"url": "%s%s" % (base_url, channel_obj.api_stream_url),
"epgId": str(channel_obj.dict['origin_id']),
"image": logourl,
}
# Sort the channels
sorted_channel_list = channel_sort(list(channels_info.keys()))
for channel in sorted_channel_list:
channel_info_m3u["stations"].append(channels_info[channel])
channels_info_json = json.dumps(channel_info_m3u, indent=4)
resp = Response(status=200, response=channels_info_json, mimetype='application/json')
resp.headers["content-disposition"] = "attachment; filename=%s" % fileName
return resp
return Response(status=200,
response=channels_info_json,
mimetype='application/json')
if redirect_url:
return redirect("%s?retmessage=%s" % (redirect_url, urllib.parse.quote("%s Success" % method)))
else:
return "%s Success" % method

View File

@ -28,6 +28,8 @@
<a class="pull-right" style="padding: 5px;" href="/api/xmltv?method=get&source={{ fhdhr.device.epg.def_method }}">xmltv</a>
<a class="pull-right" style="padding: 5px;" href="/api/m3u?method=get&channel=all">m3u</a>
<a class="pull-right" style="padding: 5px;" href="/api/w3u?method=get&channel=all">w3u</a>
<form class="pull-right" style="padding: 5px;" method="post" action="/api/settings?method=update&redirect={{ request.path }}">
<input type="hidden" name="config_section" value="web_ui">
<input type="hidden" name="config_name" value="access_level">