Skip to content

Instantly share code, notes, and snippets.

@shantanuo
Created July 21, 2014 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shantanuo/b43c294aeabb0258a4c4 to your computer and use it in GitHub Desktop.
Save shantanuo/b43c294aeabb0258a4c4 to your computer and use it in GitHub Desktop.
Download youtube video and upload it to S3 that can be viewed using s3 URL
import pafy
import re
import boto
cv = pafy.new("https://www.youtube.com/watch?v=0PGrtdcvlVE")
# use cv.title or cv.description for more info
best = cv.getbest()
myfile = best.title + "." + best.extension
filename = re.sub(r"[^a-zA-Z0-9.]+", "", myfile)
#best.download(quiet=False, filepath=filename)
access='YYYAKIAI7ORC4QXYBYS6STAXXX'
secret='YYYj4xZcBWogBTJLmVKtWroCcwye7GkGMle8Ze3Evw6XXX'
bucket_name='splitvalues'
from boto.s3.connection import OrdinaryCallingFormat
c = boto.connect_s3(access,secret,calling_format=OrdinaryCallingFormat())
mybucket = c.get_bucket(bucket_name)
from boto.s3.key import Key
k = Key(mybucket)
k.key = filename
mybucket.set_acl('public-read', filename)
k.set_contents_from_filename(filename)
path = 'http://' + bucket_name + '.s3.amazonaws.com/' + filename
print path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment