Created
July 21, 2014 09:25
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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