Module hdrezka.stream.player
General user-friendly interface to HDRezka
Functions
async def Player(url_or_path: Any) ‑> PlayerMovie | PlayerSeries-
Expand source code
async def player(url_or_path: Any) -> PlayerMovie | PlayerSeries: """ Returns either Player Series if series, or PlayerMovie if movie, otherwise raises UnknownContentType """ cast = PlayerBase(url_or_path) cached = CACHE.get(cast.post.url) if cached is not None: return cached await cast value: PlayerMovie | PlayerSeries match cast.post.type: case 'tv_series': value = PlayerSeries(cast) case 'movie': value = PlayerMovie(cast) case _ as e: raise UnknownContentType(e) CACHE.set(cast.post.url, value) return valueReturns either Player Series if series, or PlayerMovie if movie, otherwise raises UnknownContentType
Classes
class PlayerBase (url_or_cast: Any)-
Expand source code
class PlayerBase: """Base type of Player""" __slots__ = ('post',) def __init__(self, url_or_cast: Any): """Need await""" if isinstance(url_or_cast, PlayerBase): self.post: Post = url_or_cast.post return elif not isinstance(url_or_cast, str): url_or_cast = str(url_or_cast) self.post = Post(url_or_cast) def __await__(self): """ Initialize `self.post` Do not call twice! """ yield from self.post.__await__() return self async def get_trailer_iframe(self) -> str: """Get trailer <iframe> HTML""" return (await AJAX.get_trailer_video(self.post.id)).get('code', '') def _translator(self, translator_id: Optional[SupportsInt] = None) -> int: if translator_id is None: return self.post.translator_id translator_id = int(translator_id) return self.post.translators.ids[abs(translator_id)] if translator_id <= 0 else translator_id def __repr__(self): return f'{self.__class__.__qualname__}({self.post.url!r})'Base type of Player
Need await
Subclasses
Instance variables
var post-
Expand source code
class PlayerBase: """Base type of Player""" __slots__ = ('post',) def __init__(self, url_or_cast: Any): """Need await""" if isinstance(url_or_cast, PlayerBase): self.post: Post = url_or_cast.post return elif not isinstance(url_or_cast, str): url_or_cast = str(url_or_cast) self.post = Post(url_or_cast) def __await__(self): """ Initialize `self.post` Do not call twice! """ yield from self.post.__await__() return self async def get_trailer_iframe(self) -> str: """Get trailer <iframe> HTML""" return (await AJAX.get_trailer_video(self.post.id)).get('code', '') def _translator(self, translator_id: Optional[SupportsInt] = None) -> int: if translator_id is None: return self.post.translator_id translator_id = int(translator_id) return self.post.translators.ids[abs(translator_id)] if translator_id <= 0 else translator_id def __repr__(self): return f'{self.__class__.__qualname__}({self.post.url!r})'
Methods
async def get_trailer_iframe(self) ‑> str-
Expand source code
async def get_trailer_iframe(self) -> str: """Get trailer <iframe> HTML""" return (await AJAX.get_trailer_video(self.post.id)).get('code', '')Get trailer
class PlayerMovie (url_or_cast: Any)-
Expand source code
class PlayerMovie(PlayerBase): """Movies Player Type""" __slots__ = () async def get_stream(self, translator_id: Optional[SupportsInt] = None) -> URLs: """Returns movie stream `URLs`""" return urls_from_ajax_response(await AJAX.get_movie(self.post.id, self._translator(translator_id)))Movies Player Type
Need await
Ancestors
Methods
async def get_stream(self, translator_id:| None = None) ‑> URLs -
Expand source code
async def get_stream(self, translator_id: Optional[SupportsInt] = None) -> URLs: """Returns movie stream `URLs`""" return urls_from_ajax_response(await AJAX.get_movie(self.post.id, self._translator(translator_id)))Returns movie stream
URLs
Inherited members
class PlayerSeries (url_or_cast: Any)-
Expand source code
class PlayerSeries(PlayerBase): __slots__ = () async def get_episodes(self, translator_id: Optional[SupportsInt] = None) -> defaultdict[int, tuple[int, ...]]: """Returns available episodes""" episodes = BeautifulSoup((await AJAX.get_episodes(self.post.id, self._translator(translator_id)))['episodes'], builder=BUILDER) result: defaultdict[int, tuple[int, ...]] = defaultdict(tuple) for i in episodes.find_all(class_='b-simple_episode__item', attrs=('data-season_id', 'data-episode_id')): result[int(i.attrs.get('data-season_id'))] += int(i.attrs.get('data-episode_id', '0')), return result async def get_stream(self, season: int, episode: int, translator_id: Optional[SupportsInt] = None) -> URLs: """Returns episode stream `URLs`""" return urls_from_ajax_response( await AJAX.get_stream(self.post.id, self._translator(translator_id), season, episode))Base type of Player
Need await
Ancestors
Methods
async def get_episodes(self, translator_id:| None = None) ‑> collections.defaultdict[int, tuple[int, ...]] -
Expand source code
async def get_episodes(self, translator_id: Optional[SupportsInt] = None) -> defaultdict[int, tuple[int, ...]]: """Returns available episodes""" episodes = BeautifulSoup((await AJAX.get_episodes(self.post.id, self._translator(translator_id)))['episodes'], builder=BUILDER) result: defaultdict[int, tuple[int, ...]] = defaultdict(tuple) for i in episodes.find_all(class_='b-simple_episode__item', attrs=('data-season_id', 'data-episode_id')): result[int(i.attrs.get('data-season_id'))] += int(i.attrs.get('data-episode_id', '0')), return resultReturns available episodes
async def get_stream(self,
season: int,
episode: int,
translator_id:| None = None) ‑> URLs -
Expand source code
async def get_stream(self, season: int, episode: int, translator_id: Optional[SupportsInt] = None) -> URLs: """Returns episode stream `URLs`""" return urls_from_ajax_response( await AJAX.get_stream(self.post.id, self._translator(translator_id), season, episode))Returns episode stream
URLs
Inherited members