Ejemplo n.º 1
0
	def process_form(obj_response, values):
		# Add a check to see if user_data has actually changed...later
		print(values)
		limit = values['limit']
		query = values['query']
		upduration = values['upduration']
		loduration = values['loduration']
		if len(values) > 4:
			categories = get_categories(values)
		else:
			categories = []
		user_data = [limit, query, upduration, loduration, categories]
		videoID = get_new_video(user_data)
		if videoID == "Timeout":
			print('Timeout')
			videoID = 'Kdgt1ZHkvnM?autoplay=1&iv_load_policy=3'
			video_code = "http://www.youtube.com/embed/" + videoID
			obj_response.css('#timeout', 'display', 'block')
			obj_response.attr('#player', 'src', video_code)
		elif 'mode' in values:
			#This is were something contititus should be
			print('contitios mode')
			video_code = "http://www.youtube.com/embed/" + videoID + '?enablejsapi=1'
			obj_response.css('#timeout', 'display', 'none')
			obj_response.attr('#player', 'src', video_code)
		else:
			video_code = "http://www.youtube.com/embed/" + videoID
			obj_response.css('#timeout', 'display', 'none')
			obj_response.attr('#player', 'src', video_code)
Ejemplo n.º 2
0
def get_video_id():
	user_data = ['', '', '', '', []]
	videoID = get_new_video(user_data)
	video_code = "http://www.youtube.com/embed/" + videoID
	# video_embed = '\"src\", \"' + video_code'\"'
	# print(video_embed)
	return jsonify(result=video_code)
Ejemplo n.º 3
0
def video():
	global img
	user_data = ['', '', '', '', []]
	if request.method == 'POST':
		try:
			# If continuous mode is turned on
			mode = request.form['mode']
			videoID, user_data = get_video()
			if videoID == "Timeout":
				videoID = "Kdgt1ZHkvnM?autoplay=1&iv_load_policy=3"
				return render_template('video.html', id=videoID, img=img,
															mode='checked',
															limit=user_data[0],
															query=user_data[1],
															upduration=user_data[2],
															loduration=user_data[3],
															category=user_data[4],
															opendisp="block")
			else:
				return render_template('video.html', id=videoID, img=img,
															mode='checked',
															limit=user_data[0],
															query=user_data[1],
															upduration=user_data[2],
															loduration=user_data[3],
															category=user_data[4],
															opendisp="none")
		except:
			# If continous mode is turned off
			videoID, user_data = get_video()
			if videoID == "Timeout":
				videoID = "Kdgt1ZHkvnM?autoplay=1&iv_load_policy=3"
				return render_template('video.html', id=videoID, img=img,
															mode='unchecked',
															limit=user_data[0],
															query=user_data[1],
															upduration=user_data[2],
															loduration=user_data[3],
															category=user_data[4],
															opendisp="block")
			else:
				return render_template('video.html', id=videoID, img=img,
															mode='unchecked',
															limit=user_data[0],
															query=user_data[1],
															upduration=user_data[2],
															loduration=user_data[3],
															category=user_data[4],
															opendisp="none")
	else:
		user_data = ['', '', '', '', []]
		videoID = get_new_video(user_data)  # GET Sparar tid om kommenterad
		return render_template('video.html', id=videoID, img=img,
													limit=user_data[0],
													query=user_data[1],
													upduration=user_data[2],
													loduration=user_data[3],
													category=user_data[4],
													opendisp="none")
Ejemplo n.º 4
0
def get_video():
	user_data = ['', '', '', '', []]
	categories = ["aut", "com", "edu", "ent", "fil", "how", "mus",
															"new",
															"non",
															"peo",
															"pet",
															"sci",
															"spo",
															"tra"]
	# Perhaps a condition to skip all of this if user_input hasn't changed
	limit = request.form['limit']
	if limit:
		user_data[0] = limit
	else:
		user_data[0] = ''
	query = request.form['query']
	if query:
		user_data[1] = query
	else:
		user_data[1] = ''
	upduration = request.form['upduration']
	if upduration:
		user_data[2] = upduration
	else:
		user_data[2] = ''
	loduration = request.form['loduration']
	if loduration:
		user_data[3] = loduration
	else:
		user_data[3] = ''
	category = []
	for cat in categories:
		try:
			category.append(request.form[cat])
		except Exception:
			pass
	user_data[4] = category  # Default input: []. Otherwise list with strings
	videoID = get_new_video(user_data)  # POST Sparar tid om kommenterad
	for x, c in enumerate(user_data[4]):  # Replaces every &
			user_data[4][x] = c.replace("&", "&")
	return(videoID, user_data)
Ejemplo n.º 5
0
def video():
	def get_categories(values):
		#Förenkling med en for-loop som kollar all värden i "values" och sen använder dem som nycklar i en dic
		categories = []
		if 'aut' in values:
			categories.append('Autos & Vehicles')
		if 'com' in values:
			categories.append('Comedy')
		if 'edu' in values:
			categories.append('People & Blogs')
		if 'ent' in values:
			categories.append('Autos & Vehicles')
		if 'fil' in values:
			categories.append('Film & Animation')
		if 'how' in values:
			categories.append('Howto & Style')
		if 'mus' in values:
			categories.append('Music')
		if 'new' in values:
			categories.append('News & Politics')
		if 'non' in values:
			categories.append('Nonprofits & Activism')
		if 'peo' in values:
			categories.append('People & Blogs')
		if 'pet' in values:
			categories.append('Pets & Animals')
		if 'sci' in values:
			categories.append('Science & Technology')
		if 'spo' in values:
			categories.append('Sports')
		if 'tra' in values:
			categories.append('Travel & Events')
		return(categories)

	def process_form(obj_response, values):
		# Add a check to see if user_data has actually changed...later
		print(values)
		limit = values['limit']
		query = values['query']
		upduration = values['upduration']
		loduration = values['loduration']
		if len(values) > 4:
			categories = get_categories(values)
		else:
			categories = []
		user_data = [limit, query, upduration, loduration, categories]
		videoID = get_new_video(user_data)
		if videoID == "Timeout":
			print('Timeout')
			videoID = 'Kdgt1ZHkvnM?autoplay=1&iv_load_policy=3'
			video_code = "http://www.youtube.com/embed/" + videoID
			obj_response.css('#timeout', 'display', 'block')
			obj_response.attr('#player', 'src', video_code)
		elif 'mode' in values:
			#This is were something contititus should be
			print('contitios mode')
			video_code = "http://www.youtube.com/embed/" + videoID + '?enablejsapi=1'
			obj_response.css('#timeout', 'display', 'none')
			obj_response.attr('#player', 'src', video_code)
		else:
			video_code = "http://www.youtube.com/embed/" + videoID
			obj_response.css('#timeout', 'display', 'none')
			obj_response.attr('#player', 'src', video_code)
	if g.sijax.is_sijax_request:
		# Sijax request detected - let Sijax handle it
		g.sijax.register_callback('process_form', process_form)
		return g.sijax.process_request()

	# Regular (non-Sijax request) - render the page template
	img = rotate_background()
	user_data = ['', '', '', '', []]
	videoID = get_new_video(user_data)  # GET Sparar tid om kommenterad
	return render_template('video.html', id=videoID, img=img)