-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathyoutube_upload.py
48 lines (36 loc) · 1.4 KB
/
youtube_upload.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
import datetime
from Google import Create_Service
from googleapiclient.http import MediaFileUpload
import os
dir_path = os.path.dirname(os.path.realpath(__file__))
def youtube(video_id, video_title):
CLIENT_SECRET_FILE = 'client.json'
API_NAME = 'youtube'
API_VERSION = 'v3'
SCOPES = ['https://www.googleapis.com/auth/youtube.upload']
service = Create_Service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES)
upload_date_time = datetime.datetime(2020, 12, 25, 12, 30, 0).isoformat() + '.000Z'
request_body = {
'snippet': {
'categoryI': 19,
'title': video_title,
'description': 'Please Don\'t forget subscribe to my channel',
'tags': ['Slowed', 'Reverb', 'slowed and reverbed', 'reverb', 'slowed and reverb'],
},
'status': {
'privacyStatus': 'private',
'publishAt': upload_date_time,
'selfDeclaredMadeForKids': False,
},
'notifySubscribers': False
}
mediaFile = MediaFileUpload(dir_path + '/ready_to_upload/' + video_id + '.mp4')
response_upload = service.videos().insert(
part='snippet,status',
body=request_body,
media_body=mediaFile
).execute()
service.thumbnails().set(
videoId=response_upload.get('id'),
media_body=MediaFileUpload(dir_path + '/thumbnails/' + f'thumb-{video_id}' + '.jpg')
).execute()