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

Merge pull request #128 from deathbybandaid/dev

Dev
This commit is contained in:
Deathbybandaid 2021-01-12 12:05:21 -05:00 committed by GitHub
commit 7348101eea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 94 additions and 2 deletions

View File

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

View File

@ -1,6 +1,5 @@
from flask import Response, request, redirect, abort, stream_with_context, session from flask import Response, request, redirect, abort, stream_with_context, session
import urllib.parse import urllib.parse
import uuid
import json import json
from fHDHR.exceptions import TunerError from fHDHR.exceptions import TunerError
@ -75,7 +74,7 @@ class Tuners():
"transcode": transcode, "transcode": transcode,
"accessed": accessed_url, "accessed": accessed_url,
"client": client_address, "client": client_address,
"client_id": "%s_%s" % (client_address, uuid.uuid4()) "client_id": session["session_id"]
} }
try: try:

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/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/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 }}"> <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_section" value="web_ui">
<input type="hidden" name="config_name" value="access_level"> <input type="hidden" name="config_name" value="access_level">