예제 #1
0
def ask_slow_solo():
	gcm = GCM(current_app.config['GCM_APIKEY'])
	msg = ''
	try:
		user_id = int(request.form['user_id'])
		teacher_id = int(request.form['teacher_id'])
		lesson_type = False
		video = None
		club_type = int(request.form['club_type'])
		question = request.form['question']

		if 'lesson_id' in request.form:
			before_lesson = queries.get_lesson_question(request.form['lesson_id'])
			video = before_lesson.video
		elif 'video' not in request.files or not request.files['video']:
			raise

		user = auth_queries.get_user(user_id)
		teacher = auth_queries.get_teacher(teacher_id)
		if user.point < teacher.price / 100:
			msg = '골프공이 부족합니다'
			raise

		user.point -= teacher.price / 100
			
		lesson_question = Lesson_Question(
			user_id, teacher_id, False, lesson_type, 
			video, club_type, question, teacher.price / 100)

		if video is None:
			lesson_question = queries.add_lesson_question_video(lesson_question)
			thumbnail = lesson_question.thumbnail
			#TODO: 파일 처리 완료 후 DB에 들어가게 설정

			# Video Processing
			temp_file_path = os.path.join(current_app.config['UPLOAD_FOLDER'], 
				'temp_' + lesson_question.video)
			file_path = os.path.join(current_app.config['UPLOAD_FOLDER'], lesson_question.video)
			file = request.files['video']
			file.save(temp_file_path)

			try:
				os.system('/usr/local/bin/MP4Box -hint %s' % temp_file_path)
				rotation = get_video_rotation(temp_file_path)

				option = 'setpts=4.0*PTS,scale=iw/2:-1'
				os.system("/usr/local/bin/ffmpeg -i %s -vpre singlo -filter:v '%s' -an -f mp4 %s" % (temp_file_path, option, file_path))
			except:
				pass

			try:
				with open(file_path): pass
			except:
				os.system("mv %s %s" % (temp_file_path, file_path))

			get_video_capture(file_path, 0, thumbnail)
		else:
			lesson_question.thumbnail = before_lesson.thumbnail
			lesson_question = queries.add_lesson_question(lesson_question)

		reg_id = teacher_queries.get_teacher_reg_id(teacher_id)
		if reg_id is not None:
			gcm.plaintext_request(registration_id=reg_id, 
				data={'message':'새로운 레슨 신청이 들어왔습니다.'})

		return render_template('ask.json', lesson=lesson_question, userPoint=user.point)
	except Exception, e:
		print e
		return render_template('error.json')
예제 #2
0
def ask_slow():
	# 해당 기능 막아놓기로 하였음.
	return render_template('error.json')
	gcm = GCM(current_app.config['GCM_APIKEY'])
	try:
		user_id = int(request.form['user_id'])
		teacher_id_list = request.form.getlist('teacher_id[]')
		lesson_type = False
		video = None
		thumbnail = None
		club_type = int(request.form['club_type'])
		question = request.form['question']

		if 'video' not in request.files or not request.files['video']:
			raise

		lesson_question_list = []
		for teacher_id in teacher_id_list:
			lesson_question = Lesson_Question(
				user_id, teacher_id, False, lesson_type, 
				video, club_type, question)

			if video is None:
				lesson_question = queries.add_lesson_question_video(lesson_question)
				video = lesson_question.video
				thumbnail = lesson_question.thumbnail
			else:
				lesson_question.thumbnail = thumbnail
				lesson_question = queries.add_lesson_question(lesson_question)

			lesson_question_list.append(lesson_question)
			reg_id = teacher_queries.get_teacher_reg_id(teacher_id)
			if reg_id is not None:
				gcm.plaintext_request(registration_id=reg_id, 
					data={'message':'새로운 레슨 신청이 들어왔습니다.'})

		#TODO: 파일 처리 완료 후 DB에 들어가게 설정

		temp_file_path = os.path.join(current_app.config['UPLOAD_FOLDER'], 
			'temp_' + lesson_question.video)
		file_path = os.path.join(current_app.config['UPLOAD_FOLDER'], lesson_question.video)

		file = request.files['video']
		file.save(temp_file_path)
		os.system('/usr/local/bin/MP4Box -hint %s' % temp_file_path)
		rotation = get_video_rotation(temp_file_path)

		option = 'setpts=4.0*PTS,scale=iw/2:-1'
#		if rotation == 90:
#			option += ',transpose=1'
#		elif rotation == 180:
#			option += ',vflip,hflip'
#		elif rotation == 270:
#			option += ',transpose=2'

		os.system("/usr/local/bin/ffmpeg -i %s -vpre singlo -filter:v '%s' -an -f mp4 %s" % (temp_file_path, option, file_path))
		try:
			with open(file_path): pass
		except:
			os.system("mv %s %s" % (temp_file_path, file_path))

		get_video_capture(file_path, 0, thumbnail)

		return render_template('success.json')
	except Exception, e:
		print e
		return render_template('error.json')