From 7182a33857881ca51a797b2d8ba1a19fefcb216b Mon Sep 17 00:00:00 2001
From: Julian Rother <julianr@fsmpi.rwth-aachen.de>
Date: Mon, 4 Dec 2017 21:56:44 +0100
Subject: [PATCH] Moved handlers to the right places

---
 chapters.py | 17 +++++++++++++++++
 encoding.py | 29 -----------------------------
 sorter.py   | 12 ++++++++++++
 3 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/chapters.py b/chapters.py
index 4e1dfa7..e8bd555 100644
--- a/chapters.py
+++ b/chapters.py
@@ -1,6 +1,23 @@
 import json
 from server import *
 
+@job_handler('probe', 'probe-raw')
+def import_xmp_chapters(jobid, jobtype, data, state, status):
+	if 'lecture_id' not in data and data.get('import-chapters', False):
+		return
+	times = set()
+	# Only add new chapters, deleted chapters are taken into account here
+	for chapter in query('SELECT * FROM chapters WHERE lecture_id = ?', data['lecture_id']):
+		for offset in range(5):
+			times.add(chapter['time']-offset)
+			times.add(chapter['time']+offset)
+	for chapter in status.get('xmp_chapters', []):
+		if int(chapter['time']) in times:
+			continue
+		modify('INSERT INTO chapters (lecture_id, time, text, visible, time_created, time_updated) VALUES (?, ?, ?, 0, ?, ?)',
+				data['lecture_id'], int(chapter['time']), chapter['text'],
+				datetime.now(), datetime.now())
+
 @app.route('/internal/newchapter/<int:lectureid>', methods=['POST', 'GET'])
 def suggest_chapter(lectureid):
 	time = request.values['time']
diff --git a/encoding.py b/encoding.py
index 562c1c2..51cee17 100644
--- a/encoding.py
+++ b/encoding.py
@@ -1,34 +1,5 @@
 from server import *
 
-@job_handler('probe', 'probe-raw')
-def import_xmp_chapters(jobid, jobtype, data, state, status):
-	if 'lecture_id' not in data and data.get('import-chapters', False):
-		return
-	times = set()
-	# Only add new chapters, deleted chapters are taken into account here
-	for chapter in query('SELECT * FROM chapters WHERE lecture_id = ?', data['lecture_id']):
-		for offset in range(5):
-			times.add(chapter['time']-offset)
-			times.add(chapter['time']+offset)
-	for chapter in status.get('xmp_chapters', []):
-		if int(chapter['time']) in times:
-			continue
-		modify('INSERT INTO chapters (lecture_id, time, text, visible, time_created, time_updated) VALUES (?, ?, ?, 0, ?, ?)',
-				data['lecture_id'], int(chapter['time']), chapter['text'],
-				datetime.now(), datetime.now())
-
-@job_handler('probe', 'remux', 'transcode')
-def update_video_metadata(jobid, jobtype, data, state, status):
-	if 'video_id' not in data:
-		return
-	if jobtype not in ['remux', 'transcode']:
-		video = query('SELECT * FROM videos WHERE id = ?', data['video_id'])[0]
-		if video['hash'] and video['hash'] != status['hash']:
-			print('Hash mismatch for video', data['video_id'])
-			return
-	modify('UPDATE videos_data SET hash = ?, file_size = ? WHERE id = ?',
-			status['hash'], status['filesize'], data['video_id'])
-
 def schedule_remux(lectureid):
 	lecture = query('SELECT * FROM lectures WHERE id = ?', lectureid)[0]
 	course = query('SELECT * FROM courses WHERE id = ?', lecture['course_id'])[0]
diff --git a/sorter.py b/sorter.py
index 0c8e7ee..50b4e69 100644
--- a/sorter.py
+++ b/sorter.py
@@ -25,6 +25,18 @@ def to_ascii(inputstring):
 		asciistring = asciistring.replace(charset[0],charset[1])
 	return asciistring
 
+@job_handler('probe', 'remux', 'transcode')
+def update_video_metadata(jobid, jobtype, data, state, status):
+	if 'video_id' not in data:
+		return
+	if jobtype not in ['remux', 'transcode']:
+		video = query('SELECT * FROM videos WHERE id = ?', data['video_id'])[0]
+		if video['hash'] and video['hash'] != status['hash']:
+			print('Hash mismatch for video', data['video_id'])
+			return
+	modify('UPDATE videos_data SET hash = ?, file_size = ? WHERE id = ?',
+			status['hash'], status['filesize'], data['video_id'])
+
 def insert_video(lectureid, dbfilepath, fileformatid, hash="", filesize=-1):
 	video_id = modify('''INSERT INTO videos_data 
 		(lecture_id, visible, path, video_format, title, comment, internal, file_modified, time_created, time_updated, created_by, hash, file_size)
-- 
GitLab