Browse Source

xmltv: add subtitle, keep now - 3 hours of episode data

main
Brett Langdon 2 years ago
parent
commit
fba7f5b5d6
No known key found for this signature in database GPG Key ID: 9BAD4322A65AD78B
3 changed files with 23 additions and 6 deletions
  1. +7
    -0
      src/dlhdhr/epg/program.py
  2. +5
    -2
      src/dlhdhr/epg/zap2it.py
  3. +11
    -4
      src/dlhdhr/epg/zaptv.py

+ 7
- 0
src/dlhdhr/epg/program.py View File

@ -18,6 +18,7 @@ class Program:
title: str
description: str
tags: list[str]
subtitle: str | None
thumbnail: str | None
season: int | None
episode: int | None
@ -34,6 +35,8 @@ class Program:
programme = Element("programme", attrib={"start": start_time, "stop": end_time, "channel": channel.xmltv_id})
if self.title:
SubElement(programme, "title", attrib={"lang": "en"}).text = self.title
if self.subtitle:
SubElement(programme, "sub-title", attrib={"lang": "en"}).text = self.subtitle
if self.description:
SubElement(programme, "desc", attrib={"lang": "en"}).text = self.description
@ -50,6 +53,10 @@ class Program:
season_id = self.season or ""
episode_id = self.episode or ""
SubElement(programme, "episode-num", attrib={"system": "xmltv_ns"}).text = f"{season_id}.{episode_id}."
if self.season and self.episode:
SubElement(
programme, "episode-num", attrib={"system": "onscreen"}
).text = f"S{self.season} E{self.episode}"
if self.rating:
rating = SubElement(programme, "rating", attrib={"system": self.rating.system})


+ 5
- 2
src/dlhdhr/epg/zap2it.py View File

@ -31,10 +31,11 @@ class Zap2it:
def _cleanup_listings(self) -> None:
now = datetime.datetime.now(datetime.UTC)
cutoff = now - datetime.timedelta(hours=3)
updated: dict[str, list[Program]] = {}
for call_sign, programs in self._listings.items():
updated_programs = [p for p in programs if p.end_time > now]
updated_programs = [p for p in programs if p.end_time > cutoff]
if updated_programs:
updated[call_sign] = updated_programs
self._listings = updated
@ -58,6 +59,7 @@ class Zap2it:
listings: dict[str, list[Program]] = {}
now = datetime.datetime.now(datetime.UTC)
cutoff = now - datetime.timedelta(hours=3)
async with self._get_client() as client:
channels = set()
events = {}
@ -84,7 +86,7 @@ class Zap2it:
programs = []
for evt_data in events[call_sign].values():
end_time = datetime.datetime.fromisoformat(evt_data["endTime"])
if end_time < now:
if end_time < cutoff:
continue
rating = None
@ -96,6 +98,7 @@ class Zap2it:
start_time=datetime.datetime.fromisoformat(evt_data["startTime"]),
end_time=end_time,
title=evt_data["program"]["title"],
subtitle=evt_data["program"].get("episodeTitle") or None,
description=evt_data["program"]["shortDesc"],
season=evt_data["program"]["season"],
episode=evt_data["program"]["episode"],


+ 11
- 4
src/dlhdhr/epg/zaptv.py View File

@ -31,10 +31,11 @@ class ZapTV:
def _cleanup_listings(self) -> None:
now = datetime.datetime.now(datetime.UTC)
cutoff = now - datetime.timedelta(hours=3)
updated: dict[str, list[Program]] = {}
for call_sign, programs in self._listings.items():
updated_programs = [p for p in programs if p.end_time > now]
updated_programs = [p for p in programs if p.end_time > cutoff]
if updated_programs:
updated[call_sign] = updated_programs
self._listings = updated
@ -42,6 +43,7 @@ class ZapTV:
async def _fetch_listings(self) -> dict[str, list[Program]]:
listings: dict[str, list[Program]] = {}
now = datetime.datetime.now(datetime.UTC)
cutoff = now - datetime.timedelta(hours=3)
async with self._get_client() as client:
channels = set()
events = {}
@ -66,17 +68,21 @@ class ZapTV:
programs = []
for evt_data in events[code].values():
end_time = datetime.datetime.fromisoformat(evt_data["endsAt"])
if end_time < now:
if end_time < cutoff:
continue
ep_data = evt_data["metadata"].get("episode") or {}
season = ep_data.get("season") or None
season: str | None = ep_data.get("season") or None
if season is not None:
season = str(season)
episode = ep_data.get("number") or None
episode: str | None = ep_data.get("number") or None
if episode is not None:
episode = str(episode)
episode_title: str | None = ep_data.get("title") or None
if episode_title is not None:
episode_title = str(episode_title)
release_year = evt_data["metadata"].get("year")
if release_year is not None:
release_year = str(release_year)
@ -87,6 +93,7 @@ class ZapTV:
end_time=end_time,
title=evt_data["title"],
description="",
subtitle=episode_title,
season=season,
episode=episode,
tags=[],


Loading…
Cancel
Save