diff --git a/encoding.py b/encoding.py index 0b66e7f8deaf1bc792f54d497c533b3f196772e6..3b912f078346cefc2ba80dcbb4d7cc093be6f49b 100644 --- a/encoding.py +++ b/encoding.py @@ -10,17 +10,7 @@ def set_metadata(dest, course, lecture): dest['metadata'] = metadata dest['chapters'] = chapters -@app.route('/internal/jobs/add/remux', methods=['GET', 'POST']) -@mod_required -@csrf_protect -def schedule_remux(lectureid=None, videoid=None): - ret = None - if not lectureid: - 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'] - ret = redirect(request.values.get('ref', url_for('jobs_overview'))) +def schedule_remux(lectureid, videoid=None): lecture = query('SELECT * FROM lectures WHERE id = ?', lectureid)[0] course = query('SELECT * FROM courses WHERE id = ?', lecture['course_id'])[0] videos = query('''SELECT videos.*, sources.path AS srcpath, sources.hash AS srchash, formats.options AS fmtopts @@ -41,7 +31,17 @@ def schedule_remux(lectureid=None, videoid=None): data['options'] = fmt.get('options', {}) set_metadata(data, course, lecture) schedule_job('remux', data) - return ret + +@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'))) def schedule_transcode(source, fmt_id=None, video=None): if video: @@ -78,7 +78,7 @@ def schedule_transcode(source, fmt_id=None, video=None): @mod_required @csrf_protect @handle_errors('jobs_overview', 'Video nicht gefunden!', 404, IndexError) -def schedule_reencode(): +def add_reencode_job(): video = query('SELECT * FROM videos WHERE id = ?', request.values['videoid'])[0] if not video['source']: flash('Manuell erstellte Videos können nicht neukodiert werden!') diff --git a/sorter.py b/sorter.py index d4c757b5aa6e447806bae4b4af34771a7e7ceeeb..78a5bc6728913911089693a1f3f3dd032a399969 100644 --- a/sorter.py +++ b/sorter.py @@ -53,15 +53,7 @@ def insert_video(lectureid, dbfilepath, fileformatid, hash="", filesize=-1, dura course = query('SELECT * FROM courses WHERE id = ?', lecture['course_id'])[0] notify_mods('new_video', course['id'], course=course, lecture=lecture, video=video) -@app.route('/internal/jobs/add/thumbnail', methods=['GET', 'POST']) -@mod_required -@csrf_protect -@handle_errors('jobs_overview', 'Zu dieser Veranstaltung existieren keine Videos!', 404, IndexError) -def schedule_thumbnail(lectureid=None): - ret = None - if not lectureid: - lectureid = request.values['lectureid'] - ret = redirect(request.values.get('ref', url_for('jobs_overview'))) +def schedule_thumbnail(lectureid): videos = query(''' SELECT videos.path FROM videos @@ -69,7 +61,14 @@ def schedule_thumbnail(lectureid=None): WHERE videos.lecture_id = ? ORDER BY formats.prio DESC''', lectureid) schedule_job('thumbnail', {'lectureid': str(lectureid), 'path': videos[0]['path']}) - return ret + +@app.route('/internal/jobs/add/thumbnail', methods=['GET', 'POST']) +@mod_required +@csrf_protect +@handle_errors('jobs_overview', 'Zu dieser Veranstaltung existieren keine Videos!', 404, IndexError) +def add_thumbnail_job(): + schedule_thumbnail(request.values['lectureid']) + return redirect(request.values.get('ref', url_for('jobs_overview'))) @job_handler('transcode') def insert_transcoded_video(jobid, jobtype, data, state, status): diff --git a/templates/jobs_overview.html b/templates/jobs_overview.html index 233238cf476662385521e78e58f772c42982491f..87aa4a070b58dfae214246fce93216f79f8fa1a2 100644 --- a/templates/jobs_overview.html +++ b/templates/jobs_overview.html @@ -18,7 +18,7 @@ </ul> <div class="tab-content" style="margin-top: 10px;"> <div role="tabpanel" class="tab-pane active" id="add_thumbnail"> - <form class="form-inline" action="{{url_for('schedule_thumbnail', ref=request.url)}}" method="post"> + <form class="form-inline" action="{{url_for('add_thumbnail_job', ref=request.url)}}" method="post"> <div class="form-group"> <input type="text" class="form-control" placeholder="Lecture ID" name="lectureid"> <button type="submit" class="btn btn-primary">Thumbnail erzeugen</button> @@ -26,13 +26,13 @@ </form> </div> <div role="tabpanel" class="tab-pane" id="add_remux"> - <form class="form-inline" action="{{url_for('schedule_remux', ref=request.url)}}" method="post"> + <form class="form-inline" action="{{url_for('add_remux_job', ref=request.url)}}" method="post"> <div class="form-group"> <input type="text" class="form-control" placeholder="Lecture ID" name="lectureid"> <button type="submit" class="btn btn-primary">Videos remuxen</button> </div> </form><br> - <form class="form-inline" action="{{url_for('schedule_remux', ref=request.url)}}" method="post"> + <form class="form-inline" action="{{url_for('add_remux_job', ref=request.url)}}" method="post"> <div class="form-group"> <input type="text" class="form-control" placeholder="Video ID" name="videoid"> <button type="submit" class="btn btn-primary">Einzelnes Video remuxen</button> @@ -40,7 +40,7 @@ </form> </div> <div role="tabpanel" class="tab-pane" id="add_reencode"> - <form class="form-inline" action="{{url_for('schedule_reencode', ref=request.url)}}" method="post"> + <form class="form-inline" action="{{url_for('add_reencode_job', ref=request.url)}}" method="post"> <div class="form-group"> <input type="text" class="form-control" placeholder="Video ID" name="videoid"> <button type="submit" class="btn btn-primary">Video neukodieren</button>