This commit is contained in:
@@ -48,16 +48,23 @@ def schedule_epoch_utc() -> datetime:
|
||||
class EPGBuilder:
|
||||
"""Builds XMLTV EPG for all channels."""
|
||||
|
||||
def __init__(self, schedule_builder, tmdb_client, channel_repo):
|
||||
def __init__(self, schedule_builder, tmdb_client, channel_repo, cache_manager=None):
|
||||
self._schedule = schedule_builder
|
||||
self._tmdb = tmdb_client
|
||||
self._channels = channel_repo
|
||||
self._cache = cache_manager
|
||||
|
||||
def build_xml(self) -> str:
|
||||
"""
|
||||
Build XMLTV EPG for all channels. Schedule repeats from midnight UTC.
|
||||
Programmes generated for EPG_TIMESPAN_DAYS.
|
||||
"""
|
||||
if self._cache:
|
||||
cached = self._cache.get_epg()
|
||||
if cached is not None:
|
||||
logger.debug("EPG served from cache")
|
||||
return cached
|
||||
|
||||
epg_start = time.monotonic()
|
||||
channels = self._channels.get_all()
|
||||
if not channels:
|
||||
@@ -181,7 +188,10 @@ class EPGBuilder:
|
||||
ET.indent(root, space=" ")
|
||||
epg_elapsed = time.monotonic() - epg_start
|
||||
logger.info("EPG build finished in %.1fs (%s programmes total)", epg_elapsed, total_programmes)
|
||||
return (
|
||||
xml = (
|
||||
'<?xml version="1.0" encoding="UTF-8"?>\n'
|
||||
+ ET.tostring(root, encoding="unicode", default_namespace=None)
|
||||
)
|
||||
if self._cache:
|
||||
self._cache.set_epg(xml)
|
||||
return xml
|
||||
|
||||
Reference in New Issue
Block a user