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 value

Returns 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