mirror of
https://github.com/fHDHR/fHDHR_NextPVR.git
synced 2025-12-06 10:16:58 -05:00
Merge pull request #65 from deathbybandaid/dev
Further Channel Enhancements
This commit is contained in:
commit
4c83b93a5d
@ -11,7 +11,8 @@
|
|||||||
<th>Channel CallSign</th>
|
<th>Channel CallSign</th>
|
||||||
<th>Channel Number</th>
|
<th>Channel Number</th>
|
||||||
<th>Channel Thumbnail</th>
|
<th>Channel Thumbnail</th>
|
||||||
<th>Status</th>
|
<th>Enabled</th>
|
||||||
|
<th>Favorite</th>
|
||||||
<th>Update</th>
|
<th>Update</th>
|
||||||
<th>Reset</th>
|
<th>Reset</th>
|
||||||
</tr>
|
</tr>
|
||||||
@ -41,6 +42,17 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</select>
|
</select>
|
||||||
</td>
|
</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>
|
<td data-th="Update"><input type="submit" value="Update"></td>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|||||||
@ -33,6 +33,12 @@ class Channels():
|
|||||||
def set_channel_status(self, keyfind, valfind, updatedict):
|
def set_channel_status(self, keyfind, valfind, updatedict):
|
||||||
self.get_channel_obj(keyfind, valfind).set_status(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):
|
def get_db_channels(self):
|
||||||
self.fhdhr.logger.info("Checking for Channel information stored in the database.")
|
self.fhdhr.logger.info("Checking for Channel information stored in the database.")
|
||||||
channel_ids = self.fhdhr.db.get_fhdhr_value("channels", "list") or []
|
channel_ids = self.fhdhr.db.get_fhdhr_value("channels", "list") or []
|
||||||
|
|||||||
@ -62,6 +62,10 @@ class Channel():
|
|||||||
if not self.dict["thumbnail"]:
|
if not self.dict["thumbnail"]:
|
||||||
self.dict["thumbnail"] = self.dict["origin_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)
|
self.fhdhr.db.set_channel_value(self.dict["id"], "dict", self.dict)
|
||||||
|
|
||||||
def default_dict(self, channel_id):
|
def default_dict(self, channel_id):
|
||||||
@ -71,8 +75,9 @@ class Channel():
|
|||||||
"callsign": None, "origin_callsign": None,
|
"callsign": None, "origin_callsign": None,
|
||||||
"number": None, "origin_number": None,
|
"number": None, "origin_number": None,
|
||||||
"tags": [], "origin_tags": [],
|
"tags": [], "origin_tags": [],
|
||||||
"enabled": True,
|
"thumbnail": None, "origin_thumbnail": None,
|
||||||
"thumbnail": None, "origin_thumbnail": None
|
"enabled": True, "favorite": 0,
|
||||||
|
"HD": 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
def destroy(self):
|
def destroy(self):
|
||||||
@ -95,6 +100,8 @@ class Channel():
|
|||||||
'GuideName': self.dict['name'],
|
'GuideName': self.dict['name'],
|
||||||
'Tags': ",".join(self.dict['tags']),
|
'Tags': ",".join(self.dict['tags']),
|
||||||
'URL': self.stream_url(),
|
'URL': self.stream_url(),
|
||||||
|
'HD': self.dict["HD"],
|
||||||
|
"Favorite": self.dict["favorite"],
|
||||||
}
|
}
|
||||||
|
|
||||||
def stream_url(self):
|
def stream_url(self):
|
||||||
@ -103,6 +110,25 @@ class Channel():
|
|||||||
def play_url(self):
|
def play_url(self):
|
||||||
return ('/api/m3u?method=get&channel=%s' % self.dict['number'])
|
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):
|
def __getattr__(self, name):
|
||||||
''' will only get called for undefined attributes '''
|
''' will only get called for undefined attributes '''
|
||||||
if name in list(self.dict.keys()):
|
if name in list(self.dict.keys()):
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
from flask import request, redirect, Response
|
from flask import request, redirect, Response, abort
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import json
|
import json
|
||||||
|
|
||||||
@ -33,6 +33,46 @@ class Channels():
|
|||||||
response=channels_info_json,
|
response=channels_info_json,
|
||||||
mimetype='application/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":
|
elif method == "update":
|
||||||
channel_id = request.form.get('id', None)
|
channel_id = request.form.get('id', None)
|
||||||
updatedict = {}
|
updatedict = {}
|
||||||
@ -49,6 +89,8 @@ class Channels():
|
|||||||
elif str(confvalue).lower() in ["true"]:
|
elif str(confvalue).lower() in ["true"]:
|
||||||
confvalue = True
|
confvalue = True
|
||||||
updatedict[key] = confvalue
|
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)
|
self.fhdhr.device.channels.set_channel_status("id", channel_id, updatedict)
|
||||||
|
|
||||||
elif method == "scan":
|
elif method == "scan":
|
||||||
|
|||||||
@ -27,5 +27,28 @@ class Lineup_Post():
|
|||||||
self.fhdhr.logger.warning("Unknown scan command " + request.args['scan'])
|
self.fhdhr.logger.warning("Unknown scan command " + request.args['scan'])
|
||||||
return abort(200, "Not a valid scan command")
|
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:
|
else:
|
||||||
return abort(501, "Not a valid command")
|
return abort(501, "Not a valid command")
|
||||||
|
|||||||
@ -16,12 +16,18 @@ class Lineup_JSON():
|
|||||||
|
|
||||||
base_url = request.url_root[:-1]
|
base_url = request.url_root[:-1]
|
||||||
|
|
||||||
|
show = request.args.get('show', default="all", type=str)
|
||||||
|
|
||||||
jsonlineup = []
|
jsonlineup = []
|
||||||
for fhdhr_id in list(self.fhdhr.device.channels.list.keys()):
|
for fhdhr_id in list(self.fhdhr.device.channels.list.keys()):
|
||||||
channel_obj = self.fhdhr.device.channels.list[fhdhr_id]
|
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 = channel_obj.lineup_dict()
|
||||||
lineup_dict["URL"] = base_url + lineup_dict["URL"]
|
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)
|
jsonlineup.append(lineup_dict)
|
||||||
|
|
||||||
lineup_json = json.dumps(jsonlineup, indent=4)
|
lineup_json = json.dumps(jsonlineup, indent=4)
|
||||||
|
|||||||
@ -19,17 +19,21 @@ class Lineup_XML():
|
|||||||
|
|
||||||
base_url = request.url_root[:-1]
|
base_url = request.url_root[:-1]
|
||||||
|
|
||||||
|
show = request.args.get('show', default="all", type=str)
|
||||||
|
|
||||||
out = xml.etree.ElementTree.Element('Lineup')
|
out = xml.etree.ElementTree.Element('Lineup')
|
||||||
for fhdhr_id in list(self.fhdhr.device.channels.list.keys()):
|
for fhdhr_id in list(self.fhdhr.device.channels.list.keys()):
|
||||||
channel_obj = self.fhdhr.device.channels.list[fhdhr_id]
|
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 = channel_obj.lineup_dict()
|
||||||
lineup_dict["URL"] = base_url + lineup_dict["URL"]
|
lineup_dict["URL"] = base_url + lineup_dict["URL"]
|
||||||
program_out = sub_el(out, 'Program')
|
if show == "found" and channel_obj.enabled:
|
||||||
sub_el(program_out, 'GuideNumber', lineup_dict['GuideNumber'])
|
lineup_dict["Enabled"] = 1
|
||||||
sub_el(program_out, 'GuideName', lineup_dict['GuideName'])
|
elif show == "found" and not channel_obj.enabled:
|
||||||
sub_el(program_out, 'Tags', lineup_dict['Tags'])
|
lineup_dict["Enabled"] = 0
|
||||||
sub_el(program_out, 'URL', lineup_dict['URL'])
|
for key in list(lineup_dict.keys()):
|
||||||
|
sub_el(program_out, str(key), str(lineup_dict[key]))
|
||||||
|
|
||||||
fakefile = BytesIO()
|
fakefile = BytesIO()
|
||||||
fakefile.write(b'<?xml version="1.0" encoding="UTF-8"?>\n')
|
fakefile.write(b'<?xml version="1.0" encoding="UTF-8"?>\n')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user