45 lines
1.7 KiB
Python
45 lines
1.7 KiB
Python
from flask import Blueprint, render_template, request, flash, redirect, url_for
|
|
from ..nosql import get_nosql
|
|
from ..extensions import caching, caching_v_parameter, caching_unless
|
|
|
|
bp = Blueprint('watch', __name__, url_prefix='/watch')
|
|
|
|
@bp.route('', methods=['GET', 'POST'])
|
|
@caching.cached(make_cache_key=caching_v_parameter, unless=caching_unless)
|
|
def base():
|
|
vGet = request.args.get('v')
|
|
|
|
if not vGet:
|
|
flash('Thats not how it works pal')
|
|
return redirect(url_for('index.base'))
|
|
|
|
if not get_nosql().check_exists(vGet):
|
|
flash('The requested video is not in the archive')
|
|
return redirect(url_for('index.base'))
|
|
|
|
render = {}
|
|
|
|
if request.method == 'POST':
|
|
reason = request.form.get('reason')
|
|
|
|
if reason not in ['auto-video', 'metadata', 'illegal']:
|
|
flash('Invalid report reason')
|
|
return redirect(url_for('watch.base', v=vGet))
|
|
else:
|
|
reportId = get_nosql().insert_report(vGet, reason)
|
|
if reportId:
|
|
flash(f'Report has been received: {reportId}')
|
|
return redirect(url_for('watch.base', v=vGet))
|
|
else:
|
|
flash('Something went wrong with reporting')
|
|
return redirect(url_for('watch.base', v=vGet))
|
|
|
|
render['info'] = get_nosql().get_video_info(vGet)
|
|
render['params'] = request.args.get('v')
|
|
|
|
if render['info']['_status'] != 'available':
|
|
flash(render['info'].get('_status_description', 'Video unavailable because of technical errors. Come back later.'))
|
|
return redirect(url_for('index.base'))
|
|
|
|
return render_template('watch/index.html', render=render)
|