5 Commits

5 changed files with 30 additions and 9 deletions
Split View
  1. +0
    -1
      src/dlhdhr/app.py
  2. +15
    -5
      src/dlhdhr/dlhd/__init__.py
  3. +1
    -1
      src/dlhdhr/dlhd/channels.py
  4. +9
    -1
      src/dlhdhr/epg/program.py
  5. +5
    -1
      src/dlhdhr/epg/zaptv.py

+ 0
- 1
src/dlhdhr/app.py View File

@ -174,7 +174,6 @@ async def channel_key_proxy(request: Request) -> Response:
def create_app() -> Starlette:
dlhd_client = DLHDClient()
tuner_manager = TunerManager()
epg = EPG()
app = Starlette()
app.state.dlhd = dlhd_client


+ 15
- 5
src/dlhdhr/dlhd/__init__.py View File

@ -21,13 +21,11 @@ class DLHDClient:
_channels_last_fetch: float = 0
_base_urls: dict[DLHDChannel, (float, str)]
_referers: dict[DLHDChannel, str]
_cookies: dict[str, str]
def __init__(self):
self._channels = {}
self._base_urls = {}
self._referers = {}
self._cookies = {}
async def _log_request(self, request):
if config.DEBUG:
@ -38,12 +36,24 @@ class DLHDClient:
request = response.request
print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}")
self._cookies.update(response.cookies)
def _get_client(self, referer: str = ""):
parsed = urllib.parse.urlparse(referer)
origin = f"{parsed.scheme}://{parsed.netloc}"
referer = f"{parsed.scheme}://{parsed.netloc}/"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:122.0) Gecko/20100101 Firefox/122.0",
"Origin": origin,
"Referer": referer,
"Accept": "*/*",
"Accept-Language": "en-US,en;q=0.5",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "cross-site",
"Sec-GPC": "1",
"Pragma": "no-cache",
"Cache-Control": "no-cache",
"TE": "trailers",
}
return httpx.AsyncClient(
base_url=config.DLHD_BASE_URL,
@ -51,7 +61,6 @@ class DLHDClient:
max_redirects=2,
verify=True,
timeout=8.0,
cookies=self._cookies,
event_hooks={"request": [self._log_request], "response": [self._log_response]},
)
@ -140,6 +149,7 @@ class DLHDClient:
async def get_channel_key(self, channel: DLHDChannel, proxy_url: str) -> bytes:
referer = await self.get_channel_referer(channel)
async with self._get_client(referer=referer) as client:
res = await client.get(proxy_url)
res.raise_for_status()


+ 1
- 1
src/dlhdhr/dlhd/channels.py View File

@ -229,7 +229,7 @@ _CHANNELS = [
),
DLHDChannel(number="309", name="CNBC USA", country_code="us", xmltv_id="CNBC.us", call_sign="CNBC"),
DLHDChannel(
number="310", name="Comedy Central", country_code="us", xmltv_id="ComedyCentral.us", call_sign="COMEDYP"
number="310", name="Comedy Central", country_code="us", xmltv_id="ComedyCentral.us", call_sign="COMEDY"
),
DLHDChannel(number="311", name="Discovery Life Channel", country_code="us", xmltv_id="", call_sign=""),
DLHDChannel(number="312", name="Disney Channel", country_code="us", xmltv_id="DisneyChannel.us", call_sign="DISN"),


+ 9
- 1
src/dlhdhr/epg/program.py View File

@ -25,18 +25,26 @@ class Program:
rating: Rating | None
release_year: str | None
@property
def duration_minutes(self) -> int:
return int((self.end_time - self.start_time).total_seconds() / 60)
def to_xmltv(self, channel: DLHDChannel) -> Element | None:
start_time = self.start_time.strftime("%Y%m%d%H%M%S %z")
end_time = self.start_time.strftime("%Y%m%d%H%M%S %z")
end_time = self.end_time.strftime("%Y%m%d%H%M%S %z")
programme = Element("programme", attrib={"start": start_time, "stop": end_time, "channel": str(channel.number)})
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
else:
SubElement(programme, "sub-title", attrib={"lang": "en"}).text = self.title
if self.description:
SubElement(programme, "desc", attrib={"lang": "en"}).text = self.description
SubElement(programme, "length", attrib={"units": "minutes"}).text = str(self.duration_minutes)
if self.release_year:
SubElement(programme, "date").text = self.release_year


+ 5
- 1
src/dlhdhr/epg/zaptv.py View File

@ -87,6 +87,10 @@ class ZapTV:
if release_year is not None:
release_year = str(release_year)
thumbnail = evt_data["image"] or None
if thumbnail is not None and thumbnail.startswith("//"):
thumbnail = f"https:{thumbnail}"
programs.append(
Program(
start_time=datetime.datetime.fromisoformat(evt_data["startsAt"]),
@ -98,7 +102,7 @@ class ZapTV:
episode=episode,
tags=[],
release_year=release_year,
thumbnail=evt_data["image"] or None,
thumbnail=thumbnail,
rating=None,
)
)


Loading…
Cancel
Save