Commit 50ac6417 authored by Andreas Valder's avatar Andreas Valder

moved all schedule_* functions to jobtypes

parent ddefbbfc
import json
from server import *
from jobmanagement import job_handler
@job_handler('probe', 'probe-raw')
def import_xmp_chapters(jobid, jobtype, data, state, status):
......
from server import *
import os.path
from jobmanagement import schedule_job
def set_metadata(dest, course, lecture):
chapters = query('SELECT text, time FROM chapters WHERE lecture_id = ? AND visible ORDER BY time', lecture['id'])
metadata = {'title': lecture['title'], 'album': course['title'],
'description': lecture['comment'],
'date': lecture['time'].strftime('%m/%d/%Y'),
'artist': lecture['speaker'] if lecture['speaker'] else course['organizer']}
dest['metadata'] = metadata
dest['chapters'] = chapters
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
FROM videos
JOIN sources ON videos.source = sources.id
JOIN formats ON videos.video_format = formats.id
WHERE videos.lecture_id = ?''', lectureid)
for video in videos:
if not video['source']:
continue
if videoid and video['id'] != videoid:
continue
data = {'path': video['path'], 'srcpath': video['srcpath'],
'srchash': video['srchash'], 'video_id': video['id']}
fmt = json.loads(video['fmtopts'])
if 'format' in fmt:
data['format'] = fmt['format']
data['options'] = fmt.get('options', {})
set_metadata(data, course, lecture)
schedule_job('remux', data)
from jobtypes import schedule_remux, schedule_transcode
@app.route('/internal/jobs/add/remux', methods=['GET', 'POST'])
@mod_required
......@@ -44,37 +13,6 @@ def add_remux_job():
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:
fmt_id = video['video_format']
assert(video['lecture_id'] == source['lecture_id'])
assert(fmt_id != None)
fmt = query('SELECT * FROM formats WHERE id = ?', fmt_id)[0]
lecture = query('SELECT * FROM lectures WHERE id = ?', source['lecture_id'])[0]
course = query('SELECT * FROM courses WHERE id = ?', lecture['course_id'])[0]
data = {'input': {'path': source['path'], 'streams': []}, 'output': json.loads(fmt['options']), 'filters': []}
if source['type'] == 'plain':
stream = {'name': 'video', 'type': 'video'}
data['input']['streams'].append(stream)
stream = {'name': 'audio', 'type': 'audio'}
data['input']['streams'].append(stream)
else:
assert(False)
set_metadata(data['output'], course, lecture)
basename = os.path.basename(source['path']).rsplit('.', 1)[0]
data['output']['path'] = 'pub/'+course['handle']+'/'+basename+fmt['suffix']
if video:
old_source = query('SELECT * FROM sources WHERE id = ?', video['source'])[0]
data['output']['path'] = video['path']
data['video_id'] = video['id']
data['srcpath'] = old_source['path']
data['srchash'] = old_source['hash']
else:
data['lecture_id'] = lecture['id']
data['format_id'] = fmt['id']
data['source_id'] = source['id']
schedule_job('transcode', data, queue="background")
@app.route('/internal/jobs/add/reencode', methods=['GET', 'POST'])
@mod_required
@csrf_protect
......
from server import modify, query, date_json_handler, sched_func
from datetime import datetime, timedelta
import traceback
import json
job_handlers = {}
......
from server import *
import traceback
import json
import random
from time import sleep
......
from jobmanagement import schedule_job
import json
from server import query
def set_metadata(dest, course, lecture):
chapters = query('SELECT text, time FROM chapters WHERE lecture_id = ? AND visible ORDER BY time', lecture['id'])
metadata = {'title': lecture['title'], 'album': course['title'],
'description': lecture['comment'],
'date': lecture['time'].strftime('%m/%d/%Y'),
'artist': lecture['speaker'] if lecture['speaker'] else course['organizer']}
dest['metadata'] = metadata
dest['chapters'] = chapters
def schedule_thumbnail(lectureid):
videos = query('''
SELECT videos.path
FROM videos
JOIN formats ON (videos.video_format = formats.id)
WHERE videos.lecture_id = ?
ORDER BY formats.prio DESC''', lectureid)
schedule_job('thumbnail', {'lectureid': str(lectureid), 'path': videos[0]['path']})
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
FROM videos
JOIN sources ON videos.source = sources.id
JOIN formats ON videos.video_format = formats.id
WHERE videos.lecture_id = ?''', lectureid)
for video in videos:
if not video['source']:
continue
if videoid and video['id'] != videoid:
continue
data = {'path': video['path'], 'srcpath': video['srcpath'],
'srchash': video['srchash'], 'video_id': video['id']}
fmt = json.loads(video['fmtopts'])
if 'format' in fmt:
data['format'] = fmt['format']
data['options'] = fmt.get('options', {})
set_metadata(data, course, lecture)
schedule_job('remux', data)
def schedule_transcode(source, fmt_id=None, video=None):
if video:
fmt_id = video['video_format']
assert(video['lecture_id'] == source['lecture_id'])
assert(fmt_id != None)
fmt = query('SELECT * FROM formats WHERE id = ?', fmt_id)[0]
lecture = query('SELECT * FROM lectures WHERE id = ?', source['lecture_id'])[0]
course = query('SELECT * FROM courses WHERE id = ?', lecture['course_id'])[0]
data = {'input': {'path': source['path'], 'streams': []}, 'output': json.loads(fmt['options']), 'filters': []}
if source['type'] == 'plain':
stream = {'name': 'video', 'type': 'video'}
data['input']['streams'].append(stream)
stream = {'name': 'audio', 'type': 'audio'}
data['input']['streams'].append(stream)
else:
assert(False)
set_metadata(data['output'], course, lecture)
basename = os.path.basename(source['path']).rsplit('.', 1)[0]
data['output']['path'] = 'pub/'+course['handle']+'/'+basename+fmt['suffix']
if video:
old_source = query('SELECT * FROM sources WHERE id = ?', video['source'])[0]
data['output']['path'] = video['path']
data['video_id'] = video['id']
data['srcpath'] = old_source['path']
data['srchash'] = old_source['hash']
else:
data['lecture_id'] = lecture['id']
data['format_id'] = fmt['id']
data['source_id'] = source['id']
schedule_job('transcode', data, queue="background")
from server import *
from jobmanagement import schedule_job, restart_job
from jobmanagement import cancel_job, restart_job, schedule_job, job_handler
@app.route('/internal/streaming/legacy_auth', methods=['GET', 'POST'])
@app.route('/internal/streaming/legacy_auth/<server>', methods=['GET', 'POST'])
......
......@@ -476,7 +476,7 @@ def dbstatus():
def date_json_handler(obj):
return obj.isoformat() if hasattr(obj, 'isoformat') else obj
from jobs import job_handler, schedule_job, cancel_job, restart_job
import jobs
from edit import edit_handler
import feeds
import importer
......@@ -484,7 +484,6 @@ import stats
if 'ICAL_URL' in config:
import meetings
import l2pauth
from encoding import schedule_remux
import sorter
import timetable
import chapters
......
from server import *
from jobmanagement import schedule_job
from jobmanagement import schedule_job, job_handler
from jobtypes import schedule_thumbnail
import traceback
import os.path
......@@ -54,15 +55,6 @@ 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)
def schedule_thumbnail(lectureid):
videos = query('''
SELECT videos.path
FROM videos
JOIN formats ON (videos.video_format = formats.id)
WHERE videos.lecture_id = ?
ORDER BY formats.prio DESC''', lectureid)
schedule_job('thumbnail', {'lectureid': str(lectureid), 'path': videos[0]['path']})
@app.route('/internal/jobs/add/thumbnail', methods=['GET', 'POST'])
@mod_required
@csrf_protect
......
......@@ -5,11 +5,9 @@ import server
import flask
from flask import url_for
class VideoTestCase(unittest.TestCase):
def tearDown(self):
pass
#os.unlink(server.app.config['SQLITE_DB'])
def setUp(self):
server.app.testing = True
......@@ -262,6 +260,7 @@ class VideoTestCase(unittest.TestCase):
assert len(match) == 1
assert match[0]['id'] == 6095
# @unittest.skip("too slow")
def test_campusimport(self):
with self.app as c:
self.login(c)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment