In order to keep things moving quickly, I’ve decided to take a shortcut when it comes to uploading timelapse videos to youtube. I’ve decided to basically create a function that passes data to youtube-upload, a command line utility for linux that can upload videos very simply.
Here’s the function:
def UploadVideo(video,email,password):
humantime = str(datetime.now().strftime(“%m/%d/%Y”))
title = ‘Time Lapse of Tomato Plants of the Three Days Prior To ‘ + str(humantime)
description = ‘Confused? http://ift.tt/22fLKk7;
category = ‘Tech’
keywords = ‘piplanter’
uploadcommand = ‘youtube-upload –email=’ + email + ‘ –password=’ + password + ‘ –title=”‘ + title +'”‘+ ‘ –description=”‘ + description + ‘”‘ + ‘ –category=’ + category + ‘ –keywords=’ + keywords + ‘ ‘ + os.path.normpath(video)
ConsoleDebug(‘Upload Command: ‘ + uploadcommand)for i in range(10):
try:
ConsoleDebug(‘Attempt [‘ + str(i) + ‘] To Upload: ‘ + str(video))
proc = subprocess.Popen(uploadcommand, shell=True, stdout=subprocess.PIPE)
output = proc.stdout.read()
breakexcept:
ConsoleDebug(‘Upload Failed, Retrying’)
ConsoleDebug(‘Upload Error: ‘ + str(output))
i = i + 1
time.sleep(15)if i < 10:
ConsoleDebug(‘Uploaded After ‘ + str(i) + ‘ Attempts, Details: URL [ ‘ + str(output) + ‘]’ )
return outputif i == 10:
ConsoleDebug(‘Upload Was a Failure’)
return ‘Upload was a Failure’
It should remind you a lot of “TryTweet” from the main version of the PiPlanter.
View more at: http://yoursmart.mobi
Post a Comment