]> jfr.im git - yt-dlp.git/blob - yt_dlp/utils/networking.py
[networking] Add module (#2861)
[yt-dlp.git] / yt_dlp / utils / networking.py
1 import random
2
3
4 def random_user_agent():
5 _USER_AGENT_TPL = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Safari/537.36'
6 _CHROME_VERSIONS = (
7 '90.0.4430.212',
8 '90.0.4430.24',
9 '90.0.4430.70',
10 '90.0.4430.72',
11 '90.0.4430.85',
12 '90.0.4430.93',
13 '91.0.4472.101',
14 '91.0.4472.106',
15 '91.0.4472.114',
16 '91.0.4472.124',
17 '91.0.4472.164',
18 '91.0.4472.19',
19 '91.0.4472.77',
20 '92.0.4515.107',
21 '92.0.4515.115',
22 '92.0.4515.131',
23 '92.0.4515.159',
24 '92.0.4515.43',
25 '93.0.4556.0',
26 '93.0.4577.15',
27 '93.0.4577.63',
28 '93.0.4577.82',
29 '94.0.4606.41',
30 '94.0.4606.54',
31 '94.0.4606.61',
32 '94.0.4606.71',
33 '94.0.4606.81',
34 '94.0.4606.85',
35 '95.0.4638.17',
36 '95.0.4638.50',
37 '95.0.4638.54',
38 '95.0.4638.69',
39 '95.0.4638.74',
40 '96.0.4664.18',
41 '96.0.4664.45',
42 '96.0.4664.55',
43 '96.0.4664.93',
44 '97.0.4692.20',
45 )
46 return _USER_AGENT_TPL % random.choice(_CHROME_VERSIONS)
47
48
49 std_headers = {
50 'User-Agent': random_user_agent(),
51 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
52 'Accept-Language': 'en-us,en;q=0.5',
53 'Sec-Fetch-Mode': 'navigate',
54 }
55
56
57 def clean_headers(headers):
58 if 'Youtubedl-no-compression' in headers: # compat
59 del headers['Youtubedl-no-compression']
60 headers['Accept-Encoding'] = 'identity'