def GET(self, name): if name.split('.')[-1] != 'flv': what = 'hd' else: what = 'key' db = SQL.SQLtools() S3 = AWS.AWSS3() rate = float( db.lookup(table='videos', which='rate', A=what, name=name)[0][0]) desc = db.lookup(table='videos', which='des', A=what, name=name)[0][0] Name = db.lookup(table='videos', which='name', A=what, name=name)[0][0] bucketname = db.lookup(table='videos', which='bucket', A=what, name=name)[0][0] des = S3.get_string(bucket=bucketname, name=desc) try: down = db.lookup(table='front', which='dom_name', A='bucket', name=bucketname)[0][0] stream = db.lookup(table='front', which='dom_name', A='bucket', name=bucketname + 'str')[0][0] url = 'http://' + stream + '/' + name urld = 'http://' + down + '/' + name except: url = 'https://s3.amazonaws.com/' + bucketname + '/' + name urld = 'https://s3.amazonaws.com/' + bucketname + '/' + name return render.video(url, urld, Name, des, rate)
def POST(self): i = web.input() S3 = AWS.AWSS3() db = SQL.SQLtools() try: S3.create_bucket(name=i.name) except: return render.wrong('Can not Use This Name.') if 'front' in i: download, stream = S3.create_cloudfront(i.name) db.insert('front', 'bucket', value=i.name) db.insert('front', 'bucket', value=i.name + 'str') db.update('front', 'dis_id', value=download.id, where='bucket', name=i.name) db.update('front', 'dom_name', value=download.domain_name, where='bucket', name=i.name) db.update('front', 'dis_id', value=stream.id, where='bucket', name=i.name + 'str') db.update('front', 'dom_name', value=stream.domain_name, where='bucket', name=i.name + 'str') print 'added' raise web.seeother('/upload')
def GET(self): if logged(): userName = User.find_by_id(session.userId)[1] all_room = Room.show_all() print all_room titles = [] des = [] rid = [] pics = [] owner = [] for room in all_room: titles.append(room[3]) des.append(room[4]) rid.append(room[0]) s3 = AWS.AWSS3() tmp_bucket = s3.get_bucket(room[6]) key = tmp_bucket.get_all_keys() pic = 'https://s3.amazonaws.com/' + tmp_bucket.name + '/' + key[ 0].name pics.append(pic) temp_name = User.find_by_id(room[1])[1] owner.append(temp_name) return render.index(userName, titles, rid, pics, owner) else: print 'not logged in' return render.login()
def POST(self): x = web.input() S3 = AWS.AWSS3() bucket = S3.get_bucket(x.bucketname) S3.delFile(x.keyname, x.bucketname) message = x.keyname + ' is Deleted' return render.new([message], x.rid, bucket, x.tit, x.des, x.price, x.location, x.status)
def GET(self, rid): S3 = AWS.AWSS3() room = Room.find_by_id(rid) title = room[2] des = room[3] loc = room[4] price = room[5] bucket_name = room[6] bucket = S3.get_bucket(bucket_name) status = room[7] return render.show(title, des, loc, price, bucket, status)
def GET(self, id=None): if logged(): message = web.input(message=None).message print id if id == None: rid, bucket, title, des, price, location, status = None, None, None, None, None, None, None else: rid, uid, title, des, location, price, bucketname, status = Room.find_by_id( id) print Room.find_by_id(id) s3 = AWS.AWSS3() bucket = s3.get_bucket(bucketname) return render.new(message, rid, bucket, title, des, price, location, status) else: return render.login()
def POST(self): S3 = AWS.AWSS3() uid = session.userId title = web.input().tit des = web.input().des price = web.input().price location = web.input().loc status = web.input().status rid = web.input().rid if not rid: num = 0 while num < 10: try: bname = 'rental_id_' + str(random.randint(1000, 9999)) S3.create_bucket(bname) break except: num += 1 pass room_data = [uid, title, des, location, price, bname, 0] print room_data Room.insert(room_data) rid = Room.find_my_id(bname) else: bname = Room.find_by_id(rid)[6] bucket_name = bname bucket = S3.get_bucket(bucket_name) f = web.input(file2up={}) room_type = web.input().rooms print room_type filename = f.file2up.filename ext = filename.split('.')[-1] if validName(web.input().name): name = web.input().name + '.' + ext else: errors = ['name error.'] return render.new(errors, rid, bucket, title, des, price, location, status) s3_file = room_type + '/' + name saved = S3.saveFile(bucket=bucket, name=s3_file, file1=f.file2up.file) smessage = saved[4:] + ' has been saved!' return render.new([smessage], rid, bucket, title, des, price, location, status)
def POST(self): name, passwd = web.input().user, web.input().passwd print name, passwd try: ps = User.validate_passwd(name) for p in ps: if hashlib.md5(passwd).hexdigest() == p[0]: session.userId = p[1] privilege = 1 # check privilege by name in DB session.privilege = privilege userName = User.find_by_id(session.userId)[1] print "-----id-----" print userName if not logged(): print 'not logged in' all_room = Room.show_all() print all_room titles = [] des = [] rid = [] pics = [] owner = [] for room in all_room: titles.append(room[3]) des.append(room[4]) rid.append(room[0]) s3 = AWS.AWSS3() tmp_bucket = s3.get_bucket(room[6]) key = tmp_bucket.get_all_keys() pic = 'https://s3.amazonaws.com/' + tmp_bucket.name + '/' + key[ 0].name pics.append(pic) temp_name = User.find_by_id(room[1])[1] owner.append(temp_name) return render.index(userName, titles, rid, pics, owner) except: session.userId = 0 session.privilege = 0 return render.login_error()
def GET(self, name): S3 = AWS.AWSS3() db = SQL.SQLtools() hdfilename = db.lookup(table='videos', which='hd', A='key', name=name)[0][0] desfilename = db.lookup(table='videos', which='des', A='key', name=name)[0][0] bucketname = db.lookup(table='videos', which='bucket', A='key', name=name)[0][0] web.debug(hdfilename) web.debug(bucketname) S3.delFile(name=name, bucket=bucketname) S3.delFile(name=hdfilename, bucket=bucketname) S3.delFile(name=desfilename, bucket=bucketname) db.delraw(name) return web.redirect('/')
def POST(self): b = web.input(bucket={}) db = SQL.SQLtools() S3 = AWS.AWSS3() print 'ckecking' try: print S3.c.get_distribution_info( db.lookup(table='front', which='dis_id', A='bucket', name=b.bucket)[0][0]).status if S3.c.get_distribution_info( db.lookup(table='front', which='dis_id', A='bucket', name=b.bucket)[0][0]).status == u'InProgress': return render.wrong('please wait for the Distribution.') except: print 'go on.' x = web.input(video={}) if x.video.filename == '': return render.wrong('You did not choose a file~!') d = web.input(videoDes={}) if d.videoDes == '': d.videoDes = 'This gay left nothing to describe his video.' i = web.input(videoName={}) if i.videoName == '': return render.wrong('You video must have a Name~ right?') web.debug(x['video'].filename) #web.debug(x['video'].value) web.debug(i.videoName) web.debug(x.video.filename) filedir = '/home/ec2-user/uploads' #'Users/TTc9082/uploads'#' change this to the directory you want to store the file in. if 'video' in x: # to check if the file-object is created filepath = x.video.filename.replace( '\\', '/') # replaces the windows-style slashes with linux ones. filename = filepath.split('/')[-1] ext = filename.split('.')[-1] filenoext = filename.split('.')[0] fout = open( filedir + '/' + filename, 'wb' ) # creates the file where the uploaded file should be stored fout.write(x.video.file.read() ) # writes the uploaded file to the newly created file. fout.close() # closes the file, upload complete. if ext not in ['mp3', 'mp4', 'flv', 'MOV', 'avi', 'wma']: e = "The extension is not legal.(legal extensions:['mp3', 'mp4', 'flv', 'MOV', 'avi', 'wma']" return render.wrong(e) finalfile = filedir + '/' + filename finalflv = filedir + '/' + filenoext + '.flv' os.system('ffmpeg -i "%s" -ar 44100 -ab 96 -f flv "%s"' % (finalfile, finalflv)) keyname1 = i.videoName + str(random.randint(1000, 9999)) + '.flv' keyname2 = i.videoName + str(random.randint(1000, 9999)) + '.' + ext S3 = AWS.AWSS3() db = SQL.SQLtools() db.insert('videos', 'name', value=i.videoName) S3.save_string(bucket=b.bucket, name=(i.videoName + '.txt'), value=d.videoDes) flvName = S3.saveFile(bucket=b.bucket, name=keyname1, filename=finalflv) mp4Name = S3.saveFile(bucket=b.bucket, name=keyname2, filename=finalfile) os.remove(filedir + '/' + filename) os.remove(filedir + '/' + filenoext + '.flv') db.update('videos', 'key', value=keyname1, where='name', name=i.videoName) db.update('videos', 'hd', value=keyname2, where='name', name=i.videoName) db.update('videos', 'bucket', value=b.bucket, where='name', name=i.videoName) db.update('videos', 'des', value=(i.videoName + '.txt'), where='name', name=i.videoName) return web.redirect('/sort')
def GET(self): S3 = AWS.AWSS3() buckets = S3.get_all_buckets() return render.upload(buckets)