PiPlanter 2 | Adding Youtube Upload Functionality

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? https://esologic.com/?page_id=1042' 
	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()
			break
		
		except:
			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 output

	if 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.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.