From 0a15e098052a7e83200faf19547045e56cb1987f Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Fri, 3 Oct 2025 13:30:20 -0500 Subject: [PATCH] Refactor XMLTV parsing to use iterparse for element. This fixes issues where Cloudflare is adding a root element and breaking the xml. Fixes #497: Cloudflare hosted EPG not supported in dispatcharr --- apps/epg/tasks.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/epg/tasks.py b/apps/epg/tasks.py index 66ec444e..0f2af709 100644 --- a/apps/epg/tasks.py +++ b/apps/epg/tasks.py @@ -875,15 +875,17 @@ def parse_channels_only(source): if process: logger.debug(f"[parse_channels_only] Memory after opening file: {process.memory_info().rss / 1024 / 1024:.2f} MB") - # Change iterparse to look for both channel and programme elements + # Use iterparse to find the element logger.debug(f"Creating iterparse context for channels and programmes") - channel_parser = etree.iterparse(source_file, events=('end',), tag=('channel', 'programme'), remove_blank_text=True, recover=True) + tv_finder = etree.iterparse(source_file, events=('start',), tag='tv', remove_blank_text=True, recover=True) + _, tv_root = next(tv_finder) if process: logger.debug(f"[parse_channels_only] Memory after creating iterparse: {process.memory_info().rss / 1024 / 1024:.2f} MB") channel_count = 0 total_elements_processed = 0 # Track total elements processed, not just channels - for _, elem in channel_parser: + + for elem in tv_root.iter('channel', 'programme'): total_elements_processed += 1 # Only process channel elements if elem.tag == 'channel':