feat(yandextv): add yandextv schedule api

This commit is contained in:
2026-04-16 18:43:12 +03:00
parent a886322d0e
commit 29fa6435ce
17 changed files with 275 additions and 40 deletions

View File

@@ -1,14 +1,14 @@
import datetime
from ..api import Api
from .model import Schedule
from .model import ChannelId, Schedule
class ScheduleApi(Api):
async def get_channels(self) -> list[str]:
async def get_channels(self) -> list[ChannelId]:
raise NotImplementedError
async def get_channel_schedule(
self, channel_id: str, date: datetime.date
self, channel_id: ChannelId, date: datetime.date
) -> Schedule:
raise NotImplementedError

View File

@@ -3,20 +3,22 @@ import datetime
from aiocache import cached
from gallery.sketch.cached import CachedApi
from gallery.util import TimeUnit
from .api import ScheduleApi
from .model import Schedule
from .model import ChannelId, Schedule
class CachedScheduleApi(ScheduleApi, CachedApi[ScheduleApi]):
CACHE_KEY = "schedule"
CACHE_TTL = TimeUnit.HOUR * 6
@cached(
key_builder=lambda fun, self: f"api.{self.CACHE_KEY}.{self.provider}.channels",
alias=CachedApi.CACHE_ALIAS,
ttl=CachedApi.CACHE_TTL,
)
async def get_channels(self) -> list[str]:
async def get_channels(self) -> list[ChannelId]:
return await self._api.get_channels()
@cached(
@@ -27,6 +29,6 @@ class CachedScheduleApi(ScheduleApi, CachedApi[ScheduleApi]):
ttl=CachedApi.CACHE_TTL,
)
async def get_channel_schedule(
self, channel_id: str, date: datetime.date
self, channel_id: ChannelId, date: datetime.date
) -> Schedule:
return await self._api.get_channel_schedule(channel_id, date)

View File

@@ -1,22 +1,6 @@
from enum import Enum
from gallery.sketch.catalog import CatalogBundle
from .model import Channel
class ChannelId(str, Enum):
MATCH_TV = "matchtv"
MATCH_IGRA = "igra"
MATCH_ARENA = "arena"
MATCH_FUTBOL_1 = "futbol-1"
MATCH_FUTBOL_2 = "futbol-2"
MATCH_FUTBOL_3 = "futbol-3"
MATCH_STRANA = "strana"
def __str__(self) -> str:
return self.value
from .model import Channel, ChannelId
BUNDLE = CatalogBundle(
[
@@ -27,5 +11,11 @@ BUNDLE = CatalogBundle(
Channel(id=ChannelId.MATCH_FUTBOL_2, name="Футбол 2"),
Channel(id=ChannelId.MATCH_FUTBOL_3, name="Футбол 3"),
Channel(id=ChannelId.MATCH_STRANA, name="Матч! Страна"),
Channel(id=ChannelId.MATCH_PLANETA, name="Матч! Планета"),
Channel(id=ChannelId.MATCH_PLANETA, name="Матч! Планета"),
Channel(id=ChannelId.EUROSPORT, name="Europsort"),
Channel(id=ChannelId.EUROSPORT_2, name="Europsort 2"),
Channel(id=ChannelId.START, name="Старт!"),
Channel(id=ChannelId.TEST, name="Тест"),
]
)

View File

@@ -1,4 +1,5 @@
import datetime
from enum import StrEnum
from pydantic import BaseModel
@@ -8,8 +9,26 @@ class Model(BaseModel):
use_enum_values = True
class ChannelId(StrEnum):
MATCH_TV = "matchtv"
MATCH_IGRA = "igra"
MATCH_ARENA = "arena"
MATCH_FUTBOL_1 = "futbol-1"
MATCH_FUTBOL_2 = "futbol-2"
MATCH_FUTBOL_3 = "futbol-3"
MATCH_STRANA = "strana"
MATCH_PLANETA = "planeta"
EUROSPORT = "eurosport"
EUROSPORT_2 = "eurosport-2"
START = "start"
TEST = "test"
def __str__(self) -> str:
return self.value
class Channel(Model):
id: str
id: ChannelId
name: str