-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
34 lines (26 loc) · 1.03 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import requests
def video_download(video_id: str):
cl = requests.session()
print('Parsing video info...')
v_info = cl.post('https://www.youtube.com/youtubei/v1/player',
params={
'key': 'AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8'
},
json={
"context": {
"client": {
"clientName": "WEB",
"clientVersion": "2.20220311.01.00"
}
},
"videoId": video_id
})
v_formats = v_info.json().get('streamingData').get('formats')
print('Parsing video of first format...')
v_content = cl.get(v_formats[0].get('url')).content
print('Writing to file...')
v_file = open(video_id + '.mp4', 'wb')
v_file.write(v_content)
v_file.close()
# Example
video_download('0eaBEs01heA') # from https://www.youtube.com/watch?v=0eaBEs01heA