bundle.youtube.browser ====================== .. py:module:: bundle.youtube.browser Attributes ---------- .. autoapisummary:: bundle.youtube.browser.log bundle.youtube.browser.DEFAULT_EMBED_URL bundle.youtube.browser.REFERER_ORIGIN bundle.youtube.browser.REFERER_URL Classes ------- .. autoapisummary:: bundle.youtube.browser.PotoTokenEntity bundle.youtube.browser.PotoTokenBrowser Functions --------- .. autoapisummary:: bundle.youtube.browser.build_embed_url bundle.youtube.browser.run Module Contents --------------- .. py:data:: log .. py:data:: DEFAULT_EMBED_URL :value: 'https://www.youtube-nocookie.com/embed/ouEl3qTLc0M?autoplay=1&mute=1' .. py:data:: REFERER_ORIGIN :value: 'https://bundle.local' .. py:data:: REFERER_URL :value: 'https://bundle.local/youtube/token' .. py:function:: build_embed_url(embed_url: str) -> str .. py:class:: PotoTokenEntity(/, **data: Any) Bases: :py:obj:`bundle.core.entity.Entity` Entity holding the extracted poto token and visitor data. .. py:attribute:: name :type: str :value: None .. py:attribute:: potoken :type: str :value: None .. py:attribute:: visitor_data :type: str :value: None .. py:class:: PotoTokenBrowser(/, **data: Any) Bases: :py:obj:`bundle.core.browser.Browser` Extension of the Playwright-based Browser that implements poto token extraction. .. py:attribute:: token_info :type: PotoTokenEntity :value: None .. py:attribute:: extraction_event :type: asyncio.Event :value: None .. py:method:: handle_request(request: playwright.async_api.Request) -> None :async: Inspect outgoing requests and extract the poto token if the request matches the expected criteria. .. py:method:: click_player(page: playwright.async_api.Page, timeout: float = 10000) -> None :async: Wait for the video player element and click it to trigger the token request. .. py:method:: wait_for_extraction(timeout: float = 30.0) -> None :async: Wait until the extraction event is set, indicating that token extraction is complete. .. py:method:: extract_token(url: str | None = None, timeout: float = 30.0) -> PotoTokenEntity :async: Orchestrates the token extraction process. Steps: 1. Open a new page. 2. Attach the request handler to capture outgoing requests. 3. Navigate to the target URL. 4. Click the video player element to trigger the token request. 5. Wait for the token extraction to complete. 6. Close the page and return the extracted token. :param url: The YouTube embed URL for token extraction. :param timeout: Maximum time (in seconds) to wait for the extraction process. :returns: A PotoTokenEntity with the extracted token data, or None if extraction times out. .. py:function:: run() :async: