Repository: yt-dlp/yt-dlp

Issue:
[youtube] Age-gated videos requested over `player` endpoint fail with cookies
<!--

######################################################################
  WARNING!
  IGNORING THE FOLLOWING TEMPLATE WILL RESULT IN ISSUE CLOSED AS INCOMPLETE
######################################################################

-->


## Checklist

<!--
Carefully read and work through this check list in order to prevent the most common mistakes and misuse of yt-dlp:
- First of, make sure you are using the latest version of yt-dlp. Run `yt-dlp --version` and ensure your version is 2021.07.21. If it's not, see https://github.com/yt-dlp/yt-dlp on how to update. Issues with outdated version will be REJECTED.
- Make sure that all provided video/audio/playlist URLs (if any) are alive and playable in a browser.
- Make sure that all URLs and arguments with special characters are properly quoted or escaped as explained in https://github.com/yt-dlp/yt-dlp.
- Search the bugtracker for similar issues: https://github.com/yt-dlp/yt-dlp. DO NOT post duplicates.
- Read bugs section in FAQ: https://github.com/yt-dlp/yt-dlp
- Finally, put x into all relevant boxes like this [x] (Dont forget to delete the empty space)
-->

-  [X] I'm reporting a broken site support issue
- [X] I've verified that I'm running yt-dlp version **2021.07.21**
- [X] I've checked that all provided URLs are alive and playable in a browser
- [X] I've checked that all URLs and arguments with special characters are properly quoted or escaped
- [X] I've searched the bugtracker for similar bug reports including closed ones
- [X] I've read bugs section in FAQ


## Verbose log

<!--
Provide the complete verbose output of yt-dlp that clearly demonstrates the problem.
Add the `-v` flag to your command line you run yt-dlp with (`yt-dlp -v <your command line>`), copy the WHOLE output and insert it below. It should look similar to this:
 [debug] System config: []
 [debug] User config: []
 [debug] Command-line args: [u'-v', u'http://www.youtube.com/watch?v=BaW_jenozKc']
 [debug] Encodings: locale cp1251, fs mbcs, out cp866, pref cp1251
 [debug] yt-dlp version 2021.07.21
 [debug] Python version 2.7.11 - Windows-2003Server-5.2.3790-SP2
 [debug] exe versions: ffmpeg N-75573-g1d0487f, ffprobe N-75573-g1d0487f, rtmpdump 2.4
 [debug] Proxy map: {}
 <more lines>
-->

Tier 3 video:
```
yt-dlp Cr381pDsSsA --cookies cookies.txt --verbose -F --extractor-args youtube:player_client=android 
[debug] Command-line config: ['Cr381pDsSsA', '--cookies', 'cookies.txt', '--verbose', '-F', '--extractor-args', 'youtube:player_client=android']
[debug] Encodings: locale UTF-8, fs utf-8, out utf-8, pref UTF-8
[debug] yt-dlp version 2021.07.21 
[debug] Python version 3.9.5 (CPython 64bit) - Linux-5.12.9-1-MANJARO-x86_64-with-glibc2.33
[debug] exe versions: ffmpeg 4.4, ffprobe 4.4, phantomjs 2.1.1, rtmpdump 2.4
[debug] Proxy map: {}
[debug] [youtube] Extracting URL: Cr381pDsSsA
[youtube] Cr381pDsSsA: Downloading webpage
[debug] [youtube] Extracted SAPISID cookie
[youtube] Cr381pDsSsA: Downloading android player API JSON
[youtube] Cr381pDsSsA: Refetching age-gated android info webpage
WARNING: [youtube] unable to download video info webpage: HTTP Error 404: Not Found
WARNING: [youtube] Falling back to embedded-only age-gate workaround
[youtube] Cr381pDsSsA: Downloading android embedded player API JSON
ERROR: This video may be inappropriate for some users.
Traceback (most recent call last):
  File "/home/colethedj/.local/lib/python3.9/site-packages/yt_dlp/YoutubeDL.py", line 1152, in wrapper
    return func(self, *args, **kwargs)
  File "/home/colethedj/.local/lib/python3.9/site-packages/yt_dlp/YoutubeDL.py", line 1177, in __extract_info
    ie_result = ie.extract(url)
  File "/home/colethedj/.local/lib/python3.9/site-packages/yt_dlp/extractor/common.py", line 572, in extract
    ie_result = self._real_extract(url)
  File "/home/colethedj/.local/lib/python3.9/site-packages/yt_dlp/extractor/youtube.py", line 2716, in _real_extract
    self.raise_no_formats(reason, expected=True)
  File "/home/colethedj/.local/lib/python3.9/site-packages/yt_dlp/extractor/common.py", line 1056, in raise_no_formats
    raise ExtractorError(msg, expected=expected, video_id=video_id)
yt_dlp.utils.ExtractorError: This video may be inappropriate for some users.
```
With web client only (so no API calls):

```
yt-dlp Cr381pDsSsA --cookies cookies.txt --verbose -F --extractor-args youtube:player_client=web    
[debug] Command-line config: ['Cr381pDsSsA', '--cookies', cookies.txt', '--verbose', '-F', '--extractor-args', 'youtube:player_client=web']
[debug] Encodings: locale UTF-8, fs utf-8, out utf-8, pref UTF-8
[debug] yt-dlp version 2021.07.21 
[debug] Python version 3.9.5 (CPython 64bit) - Linux-5.12.9-1-MANJARO-x86_64-with-glibc2.33
[debug] exe versions: ffmpeg 4.4, ffprobe 4.4, phantomjs 2.1.1, rtmpdump 2.4
[debug] Proxy map: {}
[debug] [youtube] Extracting URL: Cr381pDsSsA
[youtube] Cr381pDsSsA: Downloading webpage
[debug] Formats sorted by: hasvid, ie_pref, lang, quality, res, fps, vcodec:vp9.2(10), acodec, filesize, fs_approx, tbr, vbr, abr, asr, proto, vext, aext, hasaud, source, id
[debug] Testing thumbnail 41
[debug] Unable to connect to thumbnail 41 URL "https://i.ytimg.com/vi_webp/Cr381pDsSsA/maxresdefault.webp" - HTTP Error 404: Not Found. Skipping...
[debug] Testing thumbnail 40
[debug] Unable to connect to thumbnail 40 URL "https://i.ytimg.com/vi/Cr381pDsSsA/maxresdefault.jpg" - HTTP Error 404: Not Found. Skipping...
[debug] Testing thumbnail 39
[debug] Unable to connect to thumbnail 39 URL "https://i.ytimg.com/vi_webp/Cr381pDsSsA/hq720.webp" - HTTP Error 404: Not Found. Skipping...
[debug] Testing thumbnail 38
[debug] Unable to connect to thumbnail 38 URL "https://i.ytimg.com/vi/Cr381pDsSsA/hq720.jpg" - HTTP Error 404: Not Found. Skipping...
[debug] Testing thumbnail 37
[info] Available formats for Cr381pDsSsA:
ID  EXT  RESOLUTION FPS |  FILESIZE    TBR PROTO | VCODEC        VBR ACODEC     ABR  ASR    MORE INFO
--- ---- ---------- --- - ---------- ----- ----- - ----------- ----- --------- ---- ------- ----------------------------------------
249 webm audio only     |  5.74MiB     50k https |                   opus       50k 48000Hz audio_quality_low, webm_dash, 48000Hz
250 webm audio only     |  7.44MiB     65k https |                   opus       65k 48000Hz audio_quality_low, webm_dash, 48000Hz
140 m4a  audio only     |  14.51MiB   127k https |                   mp4a.40.2 127k 44100Hz audio_quality_medium, m4a_dash, 44100Hz
251 webm audio only     |  14.32MiB   125k https |                   opus      125k 48000Hz audio_quality_medium, webm_dash, 48000Hz
160 mp4  256x144    30  |  8.64MiB     75k https | avc1.4d400c   75k                        144p, mp4_dash
278 webm 256x144    30  |  9.45MiB     82k https | vp9           82k                        144p, webm_dash
133 mp4  426x240    30  |  16.82MiB   147k https | avc1.4d4015  147k                        240p, mp4_dash
242 webm 426x240    30  |  18.67MiB   163k https | vp9          163k                        240p, webm_dash
134 mp4  640x360    30  |  39.35MiB   344k https | avc1.4d401e  344k                        360p, mp4_dash
18  mp4  640x360    30  |  68.95MiB   603k https | avc1.42001E  603k mp4a.40.2   0k 44100Hz 360p, 44100Hz
243 webm 640x360    30  |  33.57MiB   293k https | vp9          293k                        360p, webm_dash
135 mp4  854x480    30  |  71.37MiB   624k https | avc1.4d401f  624k                        480p, mp4_dash
244 webm 854x480    30  |  57.65MiB   504k https | vp9          504k                        480p, webm_dash
136 mp4  1280x720   30  |  133.29MiB 1166k https | avc1.4d401f 1166k                        720p, mp4_dash
22  mp4  1280x720   30  |            1922k https | avc1.64001F 1922k mp4a.40.2   0k 44100Hz 720p, 44100Hz
247 webm 1280x720   30  |  114.86MiB 1005k https | vp9         1005k                        720p, webm_dash
```

<!--
Do not remove the above ```
-->


## Description

<!--
Provide an explanation of your issue in an arbitrary form. Please make sure the description is worded well enough to be understood, see https://github.com/ytdl-org/youtube-dl#is-the-description-of-the-issue-itself-sufficient. Provide any additional information, suggested solution and as much context and examples as possible.
If work on your issue requires account credentials please provide them or explain how one can obtain them.
-->

**NOTE: This is a separate issue that is (likely) not related to the `get_video_info` bypass not working recently. See #319 and #511 for that. We are currently looking into this as well.**

First reported by @pukkandan on discord.

API calls when using cookies for age-gated videos should return the video data, but appear to be getting an age-gated error hence triggering the workaround to be used.

This appears to be subject to all player API requests, regardless of client.

It also appears to affect the previous release version, 2021.07.07


Discussion:

Resolving patch:
diff --git a/yt_dlp/extractor/youtube.py b/yt_dlp/extractor/youtube.py
--- a/yt_dlp/extractor/youtube.py
+++ b/yt_dlp/extractor/youtube.py
@@ -2343,7 +2343,8 @@ def _generate_player_context(sts=None):
             'playbackContext': {
                 'contentPlaybackContext': context
             },
-            'contentCheckOk': True
+            'contentCheckOk': True,
+            'racyCheckOk': True
         }
 
     @staticmethod


Test patch: