Browse Source

xmltv: fetch channel icons for zap2it channels

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

+ 4
- 4
src/dlhdhr/epg/__init__.py View File

@ -27,9 +27,11 @@ class EPG:
return [] return []
async def get_channel_icon_from_epg(self, channel: DLHDChannel) -> str | None: async def get_channel_icon_from_epg(self, channel: DLHDChannel) -> str | None:
if channel.country_code == "uk":
if channel.country_code == "us":
return await self.zap2it.get_channel_icon(channel)
elif channel.country_code == "uk":
if channel.epgsky_id: if channel.epgsky_id:
return f"https://d2n0069hmnqmmx.cloudfront.net/epgdata/1.0/newchanlogos/80/35/skychb{channel.epgsky_id}.png"
return self.epgsky.get_channel_icon(channel)
return None return None
async def generate_xmltv(self, channels: Iterable[DLHDChannel]) -> bytes: async def generate_xmltv(self, channels: Iterable[DLHDChannel]) -> bytes:
@ -42,8 +44,6 @@ class EPG:
programs = await self.get_channel_programs(channel) programs = await self.get_channel_programs(channel)
# Note: The order of the elements in the <programme /> matters
# title, desc, date, category, icon, episode-num, rating
for program in programs: for program in programs:
node = program.to_xmltv(channel) node = program.to_xmltv(channel)
if node: if node:


+ 5
- 0
src/dlhdhr/epg/epgsky.py View File

@ -107,3 +107,8 @@ class EPGSky:
return [] return []
return self._listings[channel.epgsky_id] return self._listings[channel.epgsky_id]
def get_channel_icon(self, channel: DLHDChannel) -> str | None:
if not channel.epgsky_id:
return None
return f"https://d2n0069hmnqmmx.cloudfront.net/epgdata/1.0/newchanlogos/80/35/skychb{channel.epgsky_id}.png"

+ 14
- 0
src/dlhdhr/epg/zap2it.py View File

@ -15,6 +15,7 @@ class Zap2it:
_BASE_URL = "https://tvlistings.zap2it.com/api/" _BASE_URL = "https://tvlistings.zap2it.com/api/"
_listings: dict[str, Program] = field(default_factory=dict) _listings: dict[str, Program] = field(default_factory=dict)
_last_fetch: float = 0 _last_fetch: float = 0
_channel_icons: dict[str, str] = field(default_factory=dict)
def _get_client(self) -> httpx.AsyncClient: def _get_client(self) -> httpx.AsyncClient:
return httpx.AsyncClient( return httpx.AsyncClient(
@ -77,6 +78,12 @@ class Zap2it:
if call_sign not in events: if call_sign not in events:
events[call_sign] = {} events[call_sign] = {}
if ch_data.get("thumbnail"):
thumbnail = ch_data["thumbnail"]
if thumbnail.startswith("//"):
thumbnail = f"https:{thumbnail}"
self._channel_icons[call_sign] = thumbnail
for evt in ch_data["events"]: for evt in ch_data["events"]:
key = (evt["startTime"], evt["endTime"]) key = (evt["startTime"], evt["endTime"])
if key not in events[call_sign]: if key not in events[call_sign]:
@ -149,3 +156,10 @@ class Zap2it:
return [] return []
return self._listings[channel.call_sign] return self._listings[channel.call_sign]
async def get_channel_icon(self, channel: DLHDChannel) -> str | None:
if not channel.call_sign:
return None
await self._refresh_listings()
return self._channel_icons.get(channel.call_sign)

Loading…
Cancel
Save