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

Further Channel Enhancements

This commit is contained in:
deathbybandaid 2020-11-29 19:04:22 -05:00
parent e8672c39bb
commit 27917cc818
7 changed files with 130 additions and 11 deletions

View File

@ -11,7 +11,8 @@
<th>Channel CallSign</th>
<th>Channel Number</th>
<th>Channel Thumbnail</th>
<th>Status</th>
<th>Enabled</th>
<th>Favorite</th>
<th>Update</th>
<th>Reset</th>
</tr>
@ -41,6 +42,17 @@
{% endif %}
</select>
</td>
<td>
<select name="favorite">
{% if chan_dict["favorite"] %}
<option value=1 selected>Yes</option>
<option value=0>No</option>
{% else %}
<option value=1>Yes</option>
<option value=0 selected>No</option>
{% endif %}
</select>
</td>
<td data-th="Update"><input type="submit" value="Update"></td>
</form>

View File

@ -33,6 +33,12 @@ class Channels():
def set_channel_status(self, keyfind, valfind, updatedict):
self.get_channel_obj(keyfind, valfind).set_status(updatedict)
def set_channel_enablement(self, keyfind, valfind, enablement):
self.get_channel_obj(keyfind, valfind).set_enablement(enablement)
def set_channel_favorite(self, keyfind, valfind, enablement):
self.get_channel_obj(keyfind, valfind).set_favorite(enablement)
def get_db_channels(self):
self.fhdhr.logger.info("Checking for Channel information stored in the database.")
channel_ids = self.fhdhr.db.get_fhdhr_value("channels", "list") or []

View File

@ -62,6 +62,10 @@ class Channel():
if not self.dict["thumbnail"]:
self.dict["thumbnail"] = self.dict["origin_thumbnail"]
if "HD" not in list(channel_info.keys()):
channel_info["HD"] = 0
self.dict["HD"] = channel_info["HD"]
self.fhdhr.db.set_channel_value(self.dict["id"], "dict", self.dict)
def default_dict(self, channel_id):
@ -71,8 +75,9 @@ class Channel():
"callsign": None, "origin_callsign": None,
"number": None, "origin_number": None,
"tags": [], "origin_tags": [],
"enabled": True,
"thumbnail": None, "origin_thumbnail": None
"thumbnail": None, "origin_thumbnail": None,
"enabled": True, "favorite": 0,
"HD": 0,
}
def destroy(self):
@ -95,6 +100,8 @@ class Channel():
'GuideName': self.dict['name'],
'Tags': ",".join(self.dict['tags']),
'URL': self.stream_url(),
'HD': self.dict["HD"],
"Favorite": self.dict["favorite"],
}
def stream_url(self):
@ -103,6 +110,25 @@ class Channel():
def play_url(self):
return ('/api/m3u?method=get&channel=%s' % self.dict['number'])
def set_favorite(self, enablement):
if enablement == "+":
self.dict["favorite"] = 1
elif enablement == "+":
self.dict["favorite"] = 0
self.fhdhr.db.set_channel_value(self.dict["fhdhr_id"], "info", self.dict)
def set_enablement(self, enablement):
if enablement == "disable":
self.dict["enabled"] = False
elif enablement == "enable":
self.dict["enabled"] = True
elif enablement == "toggle":
if self.dict["enabled"]:
self.dict["enabled"] = False
else:
self.dict["enabled"] = True
self.fhdhr.db.set_channel_value(self.dict["fhdhr_id"], "info", self.dict)
def __getattr__(self, name):
''' will only get called for undefined attributes '''
if name in list(self.dict.keys()):

View File

@ -1,4 +1,4 @@
from flask import request, redirect, Response
from flask import request, redirect, Response, abort
import urllib.parse
import json
@ -33,6 +33,46 @@ class Channels():
response=channels_info_json,
mimetype='application/json')
elif method == "favorite":
channel = request.args.get('channel', default=None, type=str)
if not channel:
if redirect_url:
return redirect(redirect_url + "?retmessage=" + urllib.parse.quote("%s Failed" % method))
else:
return "%s Falied" % method
if channel.startstwith(tuple(["+", "-", "x"])):
channel_method = channel[0]
channel_number = channel[1:]
if str(channel_number) not in [str(x) for x in self.fhdhr.device.channels.get_channel_list("number")]:
response = Response("Not Found", status=404)
response.headers["X-fHDHR-Error"] = "801 - Unknown Channel"
self.fhdhr.logger.error(response.headers["X-fHDHR-Error"])
abort(response)
if channel_method == "+":
self.fhdhr.device.channels.set_channel_enablement("number", channel_number, channel_method)
elif channel_method == "-":
self.fhdhr.device.channels.set_channel_enablement("number", channel_number, channel_method)
elif channel_method == "x":
self.fhdhr.device.channels.set_channel_enablement("number", channel_number, "toggle")
else:
self.fhdhr.logger.warning("Unknown favorite command " + request.args['favorite'])
return abort(200, "Not a valid favorite command")
elif method in ["enable", "disable"]:
channel = request.args.get('channel', default=None, type=str)
if not channel or str(channel) not in [str(x) for x in self.fhdhr.device.channels.get_channel_list("number")]:
if redirect_url:
return redirect(redirect_url + "?retmessage=" + urllib.parse.quote("%s Failed" % method))
else:
return "%s Falied" % method
self.fhdhr.device.channels.set_channel_enablement("number", channel, method)
elif method == "update":
channel_id = request.form.get('id', None)
updatedict = {}
@ -49,6 +89,8 @@ class Channels():
elif str(confvalue).lower() in ["true"]:
confvalue = True
updatedict[key] = confvalue
elif key in ["favorite", "HD"]:
updatedict[key] = int(request.form.get(key))
self.fhdhr.device.channels.set_channel_status("id", channel_id, updatedict)
elif method == "scan":

View File

@ -27,5 +27,28 @@ class Lineup_Post():
self.fhdhr.logger.warning("Unknown scan command " + request.args['scan'])
return abort(200, "Not a valid scan command")
elif 'favorite' in list(request.args.keys()):
if request.args['favorite'].startstwith(tuple(["+", "-", "x"])):
channel_method = request.args['favorite'][0]
channel_number = request.args['favorite'][1:]
if str(channel_number) not in [str(x) for x in self.fhdhr.device.channels.get_channel_list("number")]:
response = Response("Not Found", status=404)
response.headers["X-fHDHR-Error"] = "801 - Unknown Channel"
self.fhdhr.logger.error(response.headers["X-fHDHR-Error"])
abort(response)
if channel_method == "+":
self.fhdhr.device.channels.set_channel_enablement("number", channel_number, channel_method)
elif channel_method == "-":
self.fhdhr.device.channels.set_channel_enablement("number", channel_number, channel_method)
elif channel_method == "x":
self.fhdhr.device.channels.set_channel_enablement("number", channel_number, "toggle")
else:
self.fhdhr.logger.warning("Unknown favorite command " + request.args['favorite'])
return abort(200, "Not a valid favorite command")
else:
return abort(501, "Not a valid command")

View File

@ -16,12 +16,18 @@ class Lineup_JSON():
base_url = request.url_root[:-1]
show = request.args.get('show', default="all", type=str)
jsonlineup = []
for fhdhr_id in list(self.fhdhr.device.channels.list.keys()):
channel_obj = self.fhdhr.device.channels.list[fhdhr_id]
if channel_obj.enabled:
if channel_obj.enabled or show == "found":
lineup_dict = channel_obj.lineup_dict()
lineup_dict["URL"] = base_url + lineup_dict["URL"]
if show == "found" and channel_obj.enabled:
lineup_dict["Enabled"] = 1
elif show == "found" and not channel_obj.enabled:
lineup_dict["Enabled"] = 0
jsonlineup.append(lineup_dict)
lineup_json = json.dumps(jsonlineup, indent=4)

View File

@ -19,17 +19,21 @@ class Lineup_XML():
base_url = request.url_root[:-1]
show = request.args.get('show', default="all", type=str)
out = xml.etree.ElementTree.Element('Lineup')
for fhdhr_id in list(self.fhdhr.device.channels.list.keys()):
channel_obj = self.fhdhr.device.channels.list[fhdhr_id]
if channel_obj.enabled:
if channel_obj.enabled or show == "found":
program_out = sub_el(out, 'Program')
lineup_dict = channel_obj.lineup_dict()
lineup_dict["URL"] = base_url + lineup_dict["URL"]
program_out = sub_el(out, 'Program')
sub_el(program_out, 'GuideNumber', lineup_dict['GuideNumber'])
sub_el(program_out, 'GuideName', lineup_dict['GuideName'])
sub_el(program_out, 'Tags', lineup_dict['Tags'])
sub_el(program_out, 'URL', lineup_dict['URL'])
if show == "found" and channel_obj.enabled:
lineup_dict["Enabled"] = 1
elif show == "found" and not channel_obj.enabled:
lineup_dict["Enabled"] = 0
for key in list(lineup_dict.keys()):
sub_el(program_out, str(key), str(lineup_dict[key]))
fakefile = BytesIO()
fakefile.write(b'<?xml version="1.0" encoding="UTF-8"?>\n')