.. _pot_token: PoToken ======= The proof of origin (PO) token is a parameter that YouTube requires to be sent with video playback requests from some clients. Without it, format URL requests from affected customers may return HTTP error 403, error with bot detection, or result in your account or IP address being blocked. This token is generated by BotGuard (Web) / DroidGuard (Android) to attest the requests are coming from a genuine client. This guide will be assuming the use of a PO Token generated by BotGuard, for use with the `web` client. Automatic PO Token generation with nodejs ----------------------------------------- .. _nodejs-wheel-binaries: https://pypi.org/project/nodejs-wheel-binaries/ Pytubefix has the ability to generate a PoToken automatically using nodejs, all you need is to change the client to some poToken client, for example *WEB* client: .. code:: python from pytubefix import YouTube url = input("url >") yt = YouTube(url, 'WEB') print(yt.title) ys = yt.streams.get_highest_resolution() ys.download() Nodejs is automatically installed using the nodejs-wheel-binaries_ dependency. Manually acquiring a PO Token from a browser for use when logged out -------------------------------------------------------------------- This process involves manually obtaining a PO token generated from YouTube in a web browser and then manually passing it to pytubefix via the :code:`use_po_token=True` argument. Steps: 1. Open a browser and go to any video on YouTube Music or YouTube Embedded (e.g. https://www.youtube.com/embed/aqz-KE-bpKQ). **Make sure you are not logged in to any account!** 2. Open the developer console (F12), then go to the "Network" tab and filter by `v1/player` 3. Click the video to play and a player request will appear in the network tab 4. In the request payload JSON, find the PO Token at `serviceIntegrityDimensions.poToken` and save that value 5. In the request payload JSON, find the visitorData at `context.client.visitorData` and save that value 6. In the pytubefix code, pass the parameter :code:`use_po_token=True`, to send the visitorData and PoToken: .. code:: python from pytubefix import YouTube url = input("url >") yt = YouTube(url, use_po_token=True) print(yt.title) ys = yt.streams.get_highest_resolution() ys.download() FAQ --- .. _proxy: https://pytubefix.readthedocs.io/en/latest/user/proxy.html .. _oauth: https://pytubefix.readthedocs.io/en/latest/user/auth.html Detected as a bot even using PoToken ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The main purpose of passing PO Token is to help prevent getting blocked (if on non-DC IP) and allow formats from web clients to work. If you are being detected as a bot even after passing the PoToken, there are only two alternatives: 1. Log in with oauth_ (and risk getting your account banned) 2. Use a proxy_ to change your IP address If even after these attempts you continue to be detected, unfortunately there is nothing we can do.