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':