diff --git a/src/dlhdhr/app.py b/src/dlhdhr/app.py index ee61c5f..f3f357c 100644 --- a/src/dlhdhr/app.py +++ b/src/dlhdhr/app.py @@ -22,7 +22,7 @@ async def channel_playlist_m3u8(request: Request) -> Response: channel_number: str = str(request.path_params["channel_number"]) dlhd = cast(DLHDClient, request.app.state.dlhd) - channel = await dlhd.get_channel(channel_number) + channel = dlhd.get_channel(channel_number) if not channel: return Response("", status_code=404) @@ -37,7 +37,7 @@ async def channel_segment_ts(request: Request) -> Response: dlhd = cast(DLHDClient, request.app.state.dlhd) dlhd = cast(DLHDClient, request.app.state.dlhd) - channel = await dlhd.get_channel(channel_number) + channel = dlhd.get_channel(channel_number) if not channel: return Response("", status_code=404) @@ -58,7 +58,7 @@ async def channel_proxy(request: Request) -> Response: dlhd = cast(DLHDClient, request.app.state.dlhd) - channel = await dlhd.get_channel(channel_number) + channel = dlhd.get_channel(channel_number) if not channel: return Response("", status_code=404) @@ -89,7 +89,7 @@ async def channel_proxy(request: Request) -> Response: async def listings_json(request: Request) -> JSONResponse: dlhd = cast(DLHDClient, request.app.state.dlhd) - channels = sorted(await dlhd.get_channels(), key=lambda c: int(c.number)) + channels = sorted(dlhd.get_channels(), key=lambda c: int(c.number)) return JSONResponse( [ @@ -138,19 +138,19 @@ async def xmltv_xml(request: Request) -> Response: dlhd = cast(DLHDClient, request.app.state.dlhd) epg = cast(EPG, request.app.state.epg) - dlhd_channels = await dlhd.get_channels() + dlhd_channels = dlhd.get_channels() return Response(await epg.generate_xmltv(dlhd_channels), media_type="application/xml; charset=utf-8") async def iptv_m3u(request: Request) -> Response: dlhd = cast(DLHDClient, request.app.state.dlhd) - dlhd_channels = await dlhd.get_channels() + dlhd_channels = dlhd.get_channels() output = "#EXTM3U\n" for channel in dlhd_channels: - if not channel.tvg_id: + if not channel.xmltv_id: continue - output += f'#EXTINF:-1 CUID="{channel.number}" tvg-id="{channel.tvg_id}" tvg-chno="{channel.number}" channel-id="{channel.number}",{channel.name}\n' + output += f'#EXTINF:-1 CUID="{channel.number}" tvg-id="{channel.xmltv_id}" tvg-chno="{channel.number}" channel-id="{channel.number}",{channel.name}\n' output += get_public_url(request, channel.channel_proxy) output += "\n" @@ -162,7 +162,7 @@ async def channel_key_proxy(request: Request) -> Response: proxy_url: bytes = base64.urlsafe_b64decode(request.path_params["proxy_url"]) dlhd = cast(DLHDClient, request.app.state.dlhd) - channel = await dlhd.get_channel(channel_number) + channel = dlhd.get_channel(channel_number) if not channel: return Response("", status_code=404) diff --git a/src/dlhdhr/dlhd/__init__.py b/src/dlhdhr/dlhd/__init__.py index ff2a570..d554696 100644 --- a/src/dlhdhr/dlhd/__init__.py +++ b/src/dlhdhr/dlhd/__init__.py @@ -1,5 +1,6 @@ import base64 import time +from typing import Iterator import urllib.parse import httpx @@ -34,10 +35,10 @@ class DLHDClient: timeout=3.0, ) - async def get_channels(self) -> list[DLHDChannel]: + def get_channels(self) -> Iterator[DLHDChannel]: return get_channels() - async def get_channel(self, channel_number: str) -> DLHDChannel | None: + def get_channel(self, channel_number: str) -> DLHDChannel | None: for channel in self.get_channels(): if channel.number == channel_number: return channel diff --git a/src/dlhdhr/dlhd/channels.py b/src/dlhdhr/dlhd/channels.py index 8ebfa58..2c61430 100644 --- a/src/dlhdhr/dlhd/channels.py +++ b/src/dlhdhr/dlhd/channels.py @@ -42,7 +42,7 @@ _CHANNELS = [ number="37", name="Sky Sports Action UK", country_code="uk", xmltv_id="SkySportsAction.uk", call_sign="" ), DLHDChannel( - number="38", name="Sky Sports Main Event", country_code="gb", xmltv_id="SkySportsMainEvent.uk", call_sign="" + number="38", name="Sky Sports Main Event", country_code="uk", xmltv_id="SkySportsMainEvent.uk", call_sign="" ), DLHDChannel(number="39", name="Fox Sports 1 USA", country_code="us", xmltv_id="FoxSports1.us", call_sign=""), DLHDChannel(number="40", name="Tennis Channel", country_code="us", xmltv_id="TennisChannel.us", call_sign="TENNIS"), diff --git a/src/dlhdhr/epg/__init__.py b/src/dlhdhr/epg/__init__.py index f034d3f..9fbea69 100644 --- a/src/dlhdhr/epg/__init__.py +++ b/src/dlhdhr/epg/__init__.py @@ -1,4 +1,5 @@ from dataclasses import dataclass, field +from typing import Iterable from xml.etree.ElementTree import Element, tostring @@ -20,7 +21,7 @@ class EPG: return [] - async def generate_xmltv(self, channels: list[DLHDChannel]) -> bytes: + async def generate_xmltv(self, channels: Iterable[DLHDChannel]) -> bytes: tv = Element("tv", attrib={"generator-info-name": "dlhdhr"}) channels = [c for c in channels if c.xmltv_id]