Update epg tasks.py

Added gzip support for unzipping EPG files
This commit is contained in:
Dispatcharr 2025-03-06 20:40:18 -06:00
parent 1dcbf8875f
commit 725c21ed56

View file

@ -1,4 +1,5 @@
import logging
import gzip # <-- New import for gzip support
from celery import shared_task
from .models import EPGSource, EPGData, ProgramData
from django.utils import timezone
@ -29,7 +30,16 @@ def fetch_xmltv(source):
response = requests.get(source.url, timeout=30)
response.raise_for_status()
logger.debug("XMLTV data fetched successfully.")
root = ET.fromstring(response.content)
# If the URL ends with '.gz', decompress the response content
if source.url.lower().endswith('.gz'):
logger.debug("Detected .gz file. Decompressing...")
decompressed_bytes = gzip.decompress(response.content)
xml_data = decompressed_bytes.decode('utf-8')
else:
xml_data = response.text
root = ET.fromstring(xml_data)
logger.debug("Parsed XMLTV XML content.")
# Group programmes by their tvg_id from the XMLTV file