2 Commits

2 changed files with 33 additions and 15 deletions
Split View
  1. +7
    -5
      src/dlhdhr/dlhd/__init__.py
  2. +26
    -10
      src/dlhdhr/epg/zap2it.py

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

@ -63,7 +63,8 @@ class DLHDClient:
return None
async def get_channel_playlist(self, channel: DLHDChannel) -> m3u8.M3U8:
referer = f"https://weblivehdplay.ru/premiumtv/daddyhd.php?id={channel.number}"
base_url = f"https://weblivehdplay.ru/premiumtv/daddyhd.php?id={channel.number}"
referer = base_url
async with self._get_client(referer=referer) as client:
res = await client.get(referer, follow_redirects=True)
res.raise_for_status()
@ -120,13 +121,13 @@ class DLHDClient:
segment.key = new_key
mono_playlist.keys = new_keys
self._base_urls[channel] = (time.time(), referer)
self._base_urls[channel] = (time.time(), mono_url)
return mono_playlist
async def get_channel_key(self, channel: DLHDChannel, proxy_url: str) -> bytes:
base_url = await self.get_channel_base_url(channel)
async with self._get_client(referer=base_url) as client:
referer = f"https://weblivehdplay.ru/premiumtv/daddyhd.php?id={channel.number}"
async with self._get_client(referer=referer) as client:
res = await client.get(proxy_url)
res.raise_for_status()
@ -146,10 +147,11 @@ class DLHDClient:
return base_url
async def stream_segment(self, channel: DLHDChannel, segment_path: str):
referer = "https://claplivehdplay.ru/"
base_url = await self.get_channel_base_url(channel)
segment_url = urllib.parse.urljoin(base_url, segment_path)
async with self._get_client(referer=base_url) as client:
async with self._get_client(referer=referer) as client:
async with client.stream("GET", segment_url, follow_redirects=True) as res:
async for chunk in res.aiter_bytes():
yield chunk

+ 26
- 10
src/dlhdhr/epg/zap2it.py View File

@ -59,17 +59,30 @@ class Zap2it:
listings: dict[str, list[Program]] = {}
now = datetime.datetime.now(datetime.UTC)
async with self._get_client() as client:
res = await client.get("/grid", params=params)
res.raise_for_status()
data = res.json()
for ch_data in data["channels"]:
call_sign = ch_data["callSign"]
channels = set()
events = {}
# Fetch up to 18 hours into the future
for i in range(1, 3, 1):
params["time"] = str(int(time.time()) + (21600 * i))
res = await client.get("/grid", params=params)
res.raise_for_status()
data = res.json()
for ch_data in data["channels"]:
call_sign = ch_data["callSign"]
channels.add(call_sign)
if call_sign not in events:
events[call_sign] = {}
for evt in ch_data["events"]:
key = (evt["startTime"], evt["endTime"])
if key not in events[call_sign]:
events[call_sign][key] = evt
for call_sign in channels:
programs = []
listings[call_sign] = programs
for evt_data in ch_data["events"]:
for evt_data in events[call_sign].values():
end_time = datetime.datetime.fromisoformat(evt_data["endTime"])
if end_time < now:
continue
@ -92,6 +105,9 @@ class Zap2it:
rating=rating,
)
)
listings[call_sign] = sorted(programs, key=lambda p: p.start_time, reverse=True)
return listings
async def _refresh_listings(self) -> dict[str, list[Program]]:


Loading…
Cancel
Save