This commit is contained in:
doms9 2025-09-20 23:26:18 -04:00
parent 5a61e2a8d5
commit 00000d9db0
11 changed files with 809 additions and 162 deletions

View file

@ -39,21 +39,21 @@ dummies = {
"Golf.Dummy.us": live_img,
"Live.Event.us": live_img,
"MLB.Baseball.Dummy.us": None,
"MLS.Soccer.Dummy.us": None,
"NBA.Basketball.Dummy.us": None,
"NFL.Dummy.us": None,
"NHL.Hockey.Dummy.us": None,
"PPV.EVENTS.Dummy.us": live_img,
"Premier.League.Dummy.us": None,
"Racing.Dummy.us": None,
"Soccer.Dummy.us": live_img,
"Sports.Dummy.us": live_img,
"Tennis.Dummy.us": None,
"UEFA.Champions.League.Dummy.us": None,
"UFC.Fight.Pass.Dummy.us": live_img,
"WNBA.dummy.us": None,
}
replace_ids = {
"NCAA Sports": {"old": "Sports.Dummy.us", "new": "NCAA.Sports.Dummy.us"},
"UFC": {"old": "UFC.247.Dummy.us", "new": "UFC.Dummy.us"},
}
async def fetch_xml(url: str) -> ET.Element:
try:
@ -71,10 +71,60 @@ async def fetch_xml(url: str) -> ET.Element:
raise SystemExit(f'Failed to decompress and parse XML from "{url}"\n{e}') from e
def hijack_id(
old: str,
new: str,
text: str,
root: ET.Element,
) -> None:
og_channel = root.find(f"./channel[@id='{old}']")
if og_channel is not None:
new_channel = ET.Element(og_channel.tag, {**og_channel.attrib, "id": new})
display_name = og_channel.find("display-name")
if display_name is not None:
new_channel.append(ET.Element("display-name", display_name.attrib))
new_channel[-1].text = text
for child in og_channel:
if child.tag == "display-name":
continue
new_child = ET.Element(child.tag, child.attrib)
new_child.text = child.text
root.remove(og_channel)
root.append(new_channel)
for program in root.findall(f"./programme[@channel='{old}']"):
new_program = ET.Element(program.tag, {**program.attrib, "channel": new})
for child in program:
new_child = ET.Element(child.tag, child.attrib)
new_child.text = child.text
new_program.append(new_child)
for tag_name in ["title", "desc", "sub-title"]:
tag = new_program.find(tag_name)
if tag is not None:
tag.text = text
root.remove(program)
root.append(new_program)
async def main() -> None:
tvg_ids: dict[str, str] = json.loads(tvg_ids_file.read_text(encoding="utf-8"))
tvg_ids |= dummies
additions = dummies | {v["old"]: live_img for _, v in replace_ids.items()}
tvg_ids |= additions
root = ET.Element("tv")
@ -100,15 +150,20 @@ async def main() -> None:
tvg_id = program.get("channel")
if tvg_id in tvg_ids:
if (title_text := program.find("title").text) in [
"NHL Hockey",
"Live: NFL Football",
] and (subtitle := program.find("sub-title")) is not None:
title_text = program.find("title").text
subtitle = program.find("sub-title")
if (
title_text in ["NHL Hockey", "Live: NFL Football"]
and subtitle is not None
):
program.find("title").text = f"{title_text} {subtitle.text}"
root.append(program)
for k, v in replace_ids.items():
hijack_id(**v, text=k, root=root)
tree = ET.ElementTree(root)
tree.write(epg_file, encoding="utf-8", xml_declaration=True)