simplifiy youtube call make space for tik tok

pull/1310/head
streetRAT 4 years ago
parent 4593fc346d
commit d3c31850e1

1
.gitignore vendored

@ -248,3 +248,4 @@ results/client_secrets.json
results/client_secrets.json.template
results/upload_video.py-oauth2.json
results/*/*.mp4
results/test.py

@ -93,7 +93,9 @@ def get_authenticated_service(args):
)
def initialize_upload(youtube, options, i, next_upload_time):
def initialize_upload(options, next_upload_time):
args = argparser.parse_args()
youtube = get_authenticated_service(args)
tags = None
if options["keywords"]:
tags = options["keywords"].split(",")
@ -120,12 +122,12 @@ def initialize_upload(youtube, options, i, next_upload_time):
media_body=MediaFileUpload(options["file"], chunksize=-1, resumable=True),
)
resumable_upload(insert_request, i, next_upload_time)
resumable_upload(insert_request, next_upload_time)
# This method implements an exponential backoff strategy to resume a
# failed upload.
def resumable_upload(insert_request, i, next_upload_time):
def resumable_upload(insert_request, next_upload_time):
response = None
error = None
retry = 0
@ -135,7 +137,11 @@ def resumable_upload(insert_request, i, next_upload_time):
status, response = insert_request.next_chunk()
if response is not None:
if "id" in response:
print("Video id '%s' was successfully uploaded." % response["id"])
print(
"Video id {0} was successfully uploaded and will be published at {1}".format(
response["id"], next_upload_time
)
)
## upload success
updateUploadedStatus(i, next_upload_time)
@ -180,23 +186,11 @@ def updateUploadedStatus(currIndex, time):
outfile.write(json_obj)
if __name__ == "__main__":
# opens the json containing video_creation data (used for logic and upload data)
f = open("..\\video_creation\\data\\videos.json")
# loads videos.json into a dictionary
video_data = json.load(f)
options = {}
uploaded = 0
for i, video in enumerate(video_data):
if video["uploaded"] == False:
if uploaded < 6:
prev_video = list(video_data)[i - 1]
############# 2022-10-19 16:39:46.887878
def upload_youtube(video, prev_video):
format_data = "%Y-%m-%d %H:%M:%S"
next_upload = datetime.strptime(
prev_video["uploaded_at"], format_data
) + timedelta(hours=4)
next_upload = datetime.strptime(prev_video["uploaded_at"], format_data) + timedelta(
hours=4
)
file_name = video["subreddit"] + "/" + video["filename"]
title = "r/" + video["subreddit"] + " : " + video["reddit_title"]
description = (
@ -224,20 +218,33 @@ if __name__ == "__main__":
"publishTime": next_upload.isoformat(),
}
args = argparser.parse_args()
if not os.path.exists(options["file"]):
print(options["file"])
exit("Please specify a valid file using the --file= parameter ")
# print(options["file"])
exit(
"could not find the specified file --> {0} / {1}".format(
options["file"].split("/")[0], options["file"].split("/")[1]
)
)
youtube = get_authenticated_service(args)
initialize_upload(options, next_upload)
if __name__ == "__main__":
# opens the json containing video_creation data (used for logic and upload data)
f = open("..\\video_creation\\data\\videos.json")
# loads videos.json into a dictionary
video_data = json.load(f)
options = {}
uploaded = 0
for i, video in enumerate(video_data):
if video["uploaded"] == False:
if uploaded < 6:
prev_video = list(video_data)[i - 1]
try:
print(options)
# initialize_upload(youtube, options, i, next_upload)
upload_youtube(video, prev_video)
video["uploaded_at"] = next_upload.strftime(format_data)
uploaded += 1
# print(options["file"])
# print(options["title"])
# video["uploaded_at"] = next_upload.strftime(format_data)
except HttpError as e:
print("An HTTP error %d occurred:\n%s" % (e.resp.status, e.content))

Loading…
Cancel
Save