Add the publishAt option to allow planned publication for your videos. See README for prerequisites

This commit is contained in:
LecygneNoir 2018-05-01 13:41:14 +02:00
parent 8968438af2
commit d2c6154738
5 changed files with 95 additions and 4 deletions

View file

@ -10,6 +10,9 @@ import copy
import json
from os.path import splitext, basename, exists
import google.oauth2.credentials
import datetime
import pytz
from tzlocal import get_localzone
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
@ -100,10 +103,19 @@ def initialize_upload(youtube, options):
},
"status": {
"privacyStatus": str(options.get('--privacy') or "private"),
"license": str(license or "youtube")
"license": str(license or "youtube"),
}
}
if options.get('--publishAt'):
# Youtube needs microsecond and the local timezone from ISO 8601
publishAt = options.get('--publishAt') + ".000001"
publishAt = datetime.datetime.strptime(publishAt, '%Y-%m-%dT%H:%M:%S.%f')
tz = get_localzone()
tz = pytz.timezone(str(tz))
publishAt = tz.localize(publishAt).isoformat()
body['status']['publishAt'] = str(publishAt)
# Call the API's videos.insert method to create and upload the video.
insert_request = youtube.videos().insert(
part=','.join(body.keys()),