-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupl.py
51 lines (39 loc) · 1.46 KB
/
upl.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
from googleapiclient.http import MediaFileUpload
import os
import google
import google_auth_oauthlib
import ast
DEVELOPER_KEY = "AIzaSyDaZXxMgzuYQzRg5o9xvhQbiiLv-tuHSNc"
scopes = ["https://www.googleapis.com/auth/youtube.upload"]
client_secrets_file = "cred.json"
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
flow = google_auth_oauthlib.flow. InstalledAppFlow.from_client_secrets_file(client_secrets_file, scopes)
credentials = flow.run_console()
youtube = build('youtube', 'v3', credentials=credentials)
def upload():
try:
file_metadata = {'name': 'video.mp4'}
media = MediaFileUpload('video.mp4', mimetype='video/mp4')
request = youtube.videos().insert(
part='snippet, status',
body={
'snippet': {
'title': 'My video #shorts',
'description': '#shorts',
'tags': ['reddit', 'interesting', 'story',"shorts"],
'categoryId': '22'
},
'status': {
'privacyStatus': 'public'
}
},
media_body=media
)
# execute the request
response = request.execute()
# print the response
print(response)
except HttpError as error:
print(f'An error occurred: {error}')