forked from yusufusta/ytstudio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate.py
32 lines (24 loc) · 1.2 KB
/
create.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
from json import load
from rich import progress
from ytstudio.ytstudio import Studio
from ytstudio.ytstudio.typing import Visibility
file = 'test_video.mp4'
with open('login.json') as fp:
cookies = load(fp)
with Studio(cookies) as studio:
# upload file without progress bar and using default fields
with open(file, 'rb') as data: # open as byte stream to prevent entire file from being read into memory
video_id = studio.create_video(data)
print(f'Successfully uploaded! videoId: {video_id}')
# upload file with rich progress bar and using default fields
with progress.open(file, 'rb') as data:
video_id = studio.create_video(data)
print(f'Successfully uploaded! videoId: {video_id}')
# upload file with rich progress bar and using custom fields
with progress.open(file, 'rb') as data:
video_id = studio.create_video(data, 'New title', 'New description\nAnd stuff!', Visibility.UNLISTED, draft=False)
print(f'Successfully uploaded! videoId: {video_id}')
# upload arbitrary data stream
data = 'aaaaaaaaaaa BBBBBBBBBBBBBBB ccccccccccccccc'
video_id = studio.create_video(data)
print(f'Successfully uploaded! videoId: {video_id}')