mirror of
https://github.com/fHDHR/fHDHR_NextPVR.git
synced 2025-12-06 13:26:57 -05:00
Enhance Channels System
This commit is contained in:
parent
84735271a8
commit
1a007abec0
@ -11,7 +11,8 @@
|
||||
<th>Channel CallSign</th>
|
||||
<th>Channel Number</th>
|
||||
<th>Status</th>
|
||||
<th>Options</th>
|
||||
<th>Update</th>
|
||||
<th>Reset</th>
|
||||
</tr>
|
||||
|
||||
{% for chan_dict in channelslist %}
|
||||
@ -21,25 +22,35 @@
|
||||
<a href="{{ chan_dict["play_url"] }}">Play</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ chan_dict["name"] }}</td>
|
||||
<td>{{ chan_dict["callsign"] }}</td>
|
||||
<td>{{ chan_dict["number"] }}</td>
|
||||
<td>
|
||||
{% if chan_dict["enabled"] %}
|
||||
Enabled
|
||||
{% elif not chan_dict["enabled"] %}
|
||||
Disabled
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
<div>
|
||||
{% if chan_dict["enabled"] %}
|
||||
<button onclick="OpenLink('/api/channels?method=disable&channel={{ chan_dict["number"] }}&redirect=%2Fchannels')">Disable</a></button>
|
||||
{% elif not chan_dict["enabled"] %}
|
||||
<button onclick="OpenLink('/api/channels?method=enable&channel={{ chan_dict["number"] }}&redirect=%2Fchannels')">Enable</a></button>
|
||||
{% endif %}
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<form method="post" action="/api/channels?method=update&redirect=%2Fchannels">
|
||||
<input type="hidden" name="id" value={{ chan_dict["id"] }}>
|
||||
<td data-th="Channel Name"><input type="text" size="50" name="name" value={{ chan_dict["name"] }}></td>
|
||||
<td data-th="Channel Calsign"><input type="text" size="50" name="callsign" value={{ chan_dict["callsign"] }}></td>
|
||||
<td data-th="Channel Number"><input type="text" size="50" name="number" value={{ chan_dict["number"] }}></td>
|
||||
<td>
|
||||
<select name="enabled">
|
||||
{% if chan_dict["enabled"] %}
|
||||
<option value=True selected>Enabled</option>
|
||||
<option value=False>Disabled</option>
|
||||
{% else %}
|
||||
<option value=True>Enabled</option>
|
||||
<option value=False selected>Disabled</option>
|
||||
{% endif %}
|
||||
</select>
|
||||
</td>
|
||||
<td data-th="Update"><input type="submit" value="Update"></td>
|
||||
</form>
|
||||
|
||||
<form method="post" action="/api/channels?method=update&redirect=%2Fchannels">
|
||||
<input type="hidden" name="id" value={{ chan_dict["id"] }}>
|
||||
<input type="hidden" name="name" value={{ chan_dict["origin_name"] }}>
|
||||
<input type="hidden" name="callsign" value={{ chan_dict["origin_callsign"] }}>
|
||||
<input type="hidden" name="number" value={{ chan_dict["origin_number"] }}>
|
||||
<input type="hidden" name="enabled" value=True>
|
||||
<td data-th="Reset"><input type="submit" value="Reset"></td>
|
||||
</form>
|
||||
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
|
||||
@ -26,14 +26,14 @@ class Channels():
|
||||
def get_channel_list(self, keyfind):
|
||||
return [self.list[x].dict[keyfind] for x in list(self.list.keys())]
|
||||
|
||||
def set_channel_status(self, keyfind, valfind, enablement):
|
||||
self.get_channel_obj(keyfind, valfind).set_status(enablement)
|
||||
def set_channel_status(self, keyfind, valfind, updatedict):
|
||||
self.get_channel_obj(keyfind, valfind).set_status(updatedict)
|
||||
|
||||
def get_db_channels(self):
|
||||
channel_ids = self.fhdhr.db.get_fhdhr_value("channels", "IDs") or []
|
||||
channel_ids = self.fhdhr.db.get_fhdhr_value("channels", "list") or []
|
||||
for channel_id in channel_ids:
|
||||
channel_obj = Channel(self.fhdhr, self.id_system, channel_id=channel_id)
|
||||
channel_id = channel_obj.dict["fhdhr_id"]
|
||||
channel_id = channel_obj.dict["id"]
|
||||
self.list[channel_id] = channel_obj
|
||||
|
||||
def get_channels(self, forceupdate=False):
|
||||
@ -56,7 +56,7 @@ class Channels():
|
||||
channel_dict_list = self.origin.get_channels()
|
||||
for channel_info in channel_dict_list:
|
||||
channel_obj = Channel(self.fhdhr, self.id_system, origin_id=channel_info["id"])
|
||||
channel_id = channel_obj.dict["fhdhr_id"]
|
||||
channel_id = channel_obj.dict["id"]
|
||||
channel_obj.basics(channel_info)
|
||||
self.list[channel_id] = channel_obj
|
||||
|
||||
|
||||
@ -6,28 +6,28 @@ class Channel_IDs():
|
||||
self.fhdhr = fhdhr
|
||||
|
||||
def get(self, origin_id):
|
||||
existing_ids = self.fhdhr.db.get_fhdhr_value("channels", "IDs") or []
|
||||
existing_channel_info = [self.fhdhr.db.get_channel_value(channel_id, "info") or {} for channel_id in existing_ids]
|
||||
existing_ids = self.fhdhr.db.get_fhdhr_value("channels", "list") or []
|
||||
existing_channel_info = [self.fhdhr.db.get_channel_value(channel_id, "dict") or {} for channel_id in existing_ids]
|
||||
for existing_channel in existing_channel_info:
|
||||
if existing_channel["origin_id"] == origin_id:
|
||||
return existing_channel["fhdhr_id"]
|
||||
return existing_channel["id"]
|
||||
return self.assign()
|
||||
|
||||
def assign(self):
|
||||
existing_ids = self.fhdhr.db.get_fhdhr_value("channels", "IDs") or []
|
||||
existing_ids = self.fhdhr.db.get_fhdhr_value("channels", "list") or []
|
||||
channel_id = None
|
||||
while not channel_id:
|
||||
unique_id = str(uuid.uuid4())
|
||||
if str(unique_id) not in existing_ids:
|
||||
channel_id = str(unique_id)
|
||||
existing_ids.append(channel_id)
|
||||
self.fhdhr.db.set_fhdhr_value("channels", "IDs", existing_ids)
|
||||
self.fhdhr.db.set_fhdhr_value("channels", "list", existing_ids)
|
||||
return channel_id
|
||||
|
||||
def get_number(self, channel_id):
|
||||
existing_ids = self.fhdhr.db.get_fhdhr_value("channels", "IDs") or []
|
||||
existing_channel_info = [self.fhdhr.db.get_channel_value(channel_id, "info") or {} for channel_id in existing_ids]
|
||||
cnumber = [existing_channel["number"] for existing_channel in existing_channel_info if existing_channel["fhdhr_id"] == channel_id] or None
|
||||
existing_ids = self.fhdhr.db.get_fhdhr_value("channels", "list") or []
|
||||
existing_channel_info = [self.fhdhr.db.get_channel_value(channel_id, "dict") or {} for channel_id in existing_ids]
|
||||
cnumber = [existing_channel["number"] for existing_channel in existing_channel_info if existing_channel["id"] == channel_id] or None
|
||||
if cnumber:
|
||||
return cnumber
|
||||
|
||||
|
||||
@ -12,63 +12,63 @@ class Channel():
|
||||
channel_id = id_system.get(origin_id)
|
||||
else:
|
||||
channel_id = id_system.assign()
|
||||
self.dict = self.fhdhr.db.get_channel_value(str(channel_id), "info") or self.create_empty_channel(channel_id)
|
||||
self.fhdhr.db.set_channel_value(self.dict["fhdhr_id"], "info", self.dict)
|
||||
self.dict = self.fhdhr.db.get_channel_value(str(channel_id), "dict") or self.create_empty_channel(channel_id)
|
||||
self.fhdhr.db.set_channel_value(self.dict["id"], "dict", self.dict)
|
||||
|
||||
def basics(self, channel_info):
|
||||
"""Some Channel Information is Critical"""
|
||||
|
||||
if "id" in list(channel_info.keys()):
|
||||
channel_info["origin_id"] = channel_info["id"]
|
||||
del channel_info["id"]
|
||||
|
||||
if "name" not in list(channel_info.keys()):
|
||||
channel_info["name"] = self.dict["fhdhr_id"]
|
||||
channel_info["name"] = self.dict["id"]
|
||||
self.dict["origin_name"] = channel_info["name"]
|
||||
if not self.dict["name"]:
|
||||
self.dict["name"] = self.dict["origin_name"]
|
||||
|
||||
if "id" not in list(channel_info.keys()):
|
||||
channel_info["id"] = channel_info["name"]
|
||||
self.dict["origin_id"] = channel_info["id"]
|
||||
|
||||
if "callsign" not in list(channel_info.keys()):
|
||||
channel_info["callsign"] = channel_info["name"]
|
||||
|
||||
if "origin_id" not in list(channel_info.keys()):
|
||||
channel_info["origin_id"] = channel_info["name"]
|
||||
self.dict["origin_callsign"] = channel_info["callsign"]
|
||||
if not self.dict["callsign"]:
|
||||
self.dict["callsign"] = self.dict["origin_callsign"]
|
||||
|
||||
if "tags" not in list(channel_info.keys()):
|
||||
channel_info["tags"] = []
|
||||
self.dict["origin_tags"] = channel_info["tags"]
|
||||
if not self.dict["tags"]:
|
||||
self.dict["tags"] = self.dict["origin_tags"]
|
||||
|
||||
if "number" not in list(channel_info.keys()):
|
||||
channel_info["number"] = self.id_system.get_number(channel_info["origin_id"])
|
||||
channel_info["number"] = str(float(channel_info["number"]))
|
||||
self.dict["origin_number"] = str(float(channel_info["number"]))
|
||||
if not self.dict["number"]:
|
||||
self.dict["number"] = self.dict["origin_number"]
|
||||
|
||||
self.append_channel_info(channel_info)
|
||||
self.fhdhr.db.set_channel_value(self.dict["id"], "dict", self.dict)
|
||||
|
||||
def create_empty_channel(self, channel_id):
|
||||
return {
|
||||
"fhdhr_id": str(channel_id),
|
||||
"origin_id": None,
|
||||
"name": None,
|
||||
"callsign": None,
|
||||
"number": None,
|
||||
"tags": [],
|
||||
"id": str(channel_id), "origin_id": None,
|
||||
"name": None, "origin_name": None,
|
||||
"callsign": None, "origin_callsign": None,
|
||||
"number": None, "origin_number": None,
|
||||
"tags": [], "origin_tags": [],
|
||||
"enabled": True
|
||||
}
|
||||
|
||||
def destroy(self):
|
||||
self.fhdhr.db.delete_channel_value(self.dict["fhdhr_id"], "info")
|
||||
channel_ids = self.fhdhr.db.get_fhdhr_value("channels", "IDs") or []
|
||||
if self.dict["fhdhr_id"] in channel_ids:
|
||||
channel_ids.remove(self.dict["fhdhr_id"])
|
||||
self.fhdhr.db.set_fhdhr_value("channels", "IDs", channel_ids)
|
||||
self.fhdhr.db.delete_channel_value(self.dict["id"], "dict")
|
||||
channel_ids = self.fhdhr.db.get_fhdhr_value("channels", "list") or []
|
||||
if self.dict["id"] in channel_ids:
|
||||
channel_ids.remove(self.dict["id"])
|
||||
self.fhdhr.db.set_fhdhr_value("channels", "list", channel_ids)
|
||||
|
||||
def append_channel_info(self, channel_info):
|
||||
for chankey in list(channel_info.keys()):
|
||||
self.dict[chankey] = channel_info[chankey]
|
||||
self.fhdhr.db.set_channel_value(self.dict["fhdhr_id"], "info", self.dict)
|
||||
|
||||
def set_status(self, enablement):
|
||||
if enablement == "disable":
|
||||
self.dict["enabled"] = False
|
||||
elif enablement == "enable":
|
||||
self.dict["enabled"] = True
|
||||
self.fhdhr.db.set_channel_value(self.dict["fhdhr_id"], "info", self.dict)
|
||||
def set_status(self, updatedict):
|
||||
for key in list(updatedict.keys()):
|
||||
self.dict[key] = updatedict[key]
|
||||
self.fhdhr.db.set_channel_value(self.dict["id"], "dict", self.dict)
|
||||
|
||||
def lineup_dict(self):
|
||||
return {
|
||||
|
||||
@ -33,14 +33,23 @@ class Channels():
|
||||
response=channels_info_json,
|
||||
mimetype='application/json')
|
||||
|
||||
elif method in ["enable", "disable"]:
|
||||
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
|
||||
self.fhdhr.device.channels.set_channel_status("number", channel, method)
|
||||
elif method == "update":
|
||||
channel_id = request.form.get('id', None)
|
||||
updatedict = {}
|
||||
for key in list(request.form.keys()):
|
||||
if key != "id":
|
||||
if key in ["name", "callsign"]:
|
||||
updatedict[key] = str(request.form.get(key))
|
||||
elif key in ["number"]:
|
||||
updatedict[key] = float(request.form.get(key))
|
||||
elif key in ["enabled"]:
|
||||
confvalue = request.form.get(key)
|
||||
if str(confvalue).lower() in ["false"]:
|
||||
confvalue = False
|
||||
elif str(confvalue).lower() in ["true"]:
|
||||
confvalue = True
|
||||
updatedict[key] = confvalue
|
||||
self.fhdhr.device.channels.set_channel_status("id", channel_id, updatedict)
|
||||
|
||||
elif method == "scan":
|
||||
self.fhdhr.device.station_scan.scan()
|
||||
|
||||
@ -41,11 +41,11 @@ class OriginChannels():
|
||||
return channel_list
|
||||
|
||||
def get_channel_stream(self, chandict):
|
||||
streamurl = ('%s%s:%s/live?channel=%s&client=%s' %
|
||||
streamurl = ('%s%s:%s/live?channel_id=%s&client=%s' %
|
||||
("https://" if self.fhdhr.config.dict["origin"]["ssl"] else "http://",
|
||||
self.fhdhr.config.dict["origin"]["address"],
|
||||
str(self.fhdhr.config.dict["origin"]["port"]),
|
||||
str(chandict["number"]),
|
||||
str(chandict["number"]),
|
||||
str(chandict["origin_id"]),
|
||||
"fhdhr_" + str(chandict["origin_number"]),
|
||||
))
|
||||
return streamurl
|
||||
|
||||
Loading…
Reference in New Issue
Block a user