encoding.py 2.88 KB
Newer Older
1
from server import *
Julian Rother's avatar
Julian Rother committed
2
import os.path
3
from jobtypes import schedule_remux, schedule_transcode
4 5 6 7 8 9 10 11 12 13 14

@app.route('/internal/jobs/add/remux', methods=['GET', 'POST'])
@mod_required
@csrf_protect
def add_remux_job():
	lectureid = request.values.get('lectureid')
	videoid = int(request.values.get('videoid', 0))
	if not lectureid:
		lectureid = query('SELECT lecture_id FROM videos WHERE id = ?', videoid)[0]['lecture_id']
	schedule_remux(lectureid, videoid)
	return redirect(request.values.get('ref', url_for('jobs_overview')))
15

16 17 18 19
@app.route('/internal/jobs/add/reencode', methods=['GET', 'POST'])
@mod_required
@csrf_protect
@handle_errors('jobs_overview', 'Video nicht gefunden!', 404, IndexError)
20
def add_reencode_job():
21 22 23 24 25 26 27 28
	video = query('SELECT * FROM videos WHERE id = ?', request.values['videoid'])[0]
	if not video['source']:
		flash('Manuell erstellte Videos können nicht neukodiert werden!')
	else:
		source = query('''SELECT sources.* FROM sources WHERE sources.id = ? ORDER BY time_created''', video['source'])[-1]
		schedule_transcode(source, video=video)
	return redirect(request.values.get('ref', url_for('jobs_overview')))

Julian Rother's avatar
Julian Rother committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
@job_handler('probe-raw')
def update_lecture_videos(jobid, jobtype, data, state, status):
	if 'lecture_id' not in data:
		return
	if 'source_id' not in data:
		modify('INSERT INTO sources (lecture_id, path, type, hash, time_created) VALUES (?, ?, ?, ?, ?)',
				data['lecture_id'], data['path'], 'plain', status['hash'], datetime.now())
	sources = query('SELECT * FROM sources WHERE sources.lecture_id = ? ORDER BY time_created', data['lecture_id'])
	if not sources:
		return
	latest = sources[-1]
	videos = query('SELECT * FROM videos WHERE videos.lecture_id = ?', data['lecture_id'])
	current_fmts = [v['video_format'] for v in videos]
	formats = query('''SELECT formats.* FROM formats
			JOIN profiles ON formats.id = profiles.format
			JOIN courses ON profiles.name = courses.profile
			JOIN lectures ON courses.id = lectures.course_id
			WHERE lectures.id = ?''', data['lecture_id'])
	for fmt in formats:
		if fmt['id'] not in current_fmts:
			schedule_transcode(latest, fmt_id=fmt['id'])
	for video in videos:
		if video['source'] != latest['id']:
			schedule_transcode(latest, video=video)

54
@edit_handler('chapters')
55
def chapter_changed(table, column, value, id, user):
56 57 58 59 60 61 62 63
	chapters = query('SELECT * FROM chapters WHERE id = ?', id)
	if not chapters:
		return
	chapter = chapters[0]
	if column in ['visible', 'deleted'] or (chapter['visible'] and not chapter['deleted']):
		schedule_remux(chapter['lecture_id'])

@edit_handler('courses')
64
def course_changed(table, column, value, id, user):
65 66 67 68 69 70 71
	if column not in ['title', 'organizer']:
		return
	lectures = query('SELECT * FROM lectures WHERE course_id = ?', id)
	for lecture in lectures:
		schedule_remux(lecture['id'])

@edit_handler('lectures')
72
def lecture_changed(table, column, value, id, user):
73 74 75
	if column in ['title', 'comment', 'time', 'speaker']:
		schedule_remux(id)