From 134e2b1546cce383e95663de5f6ea5c73c98fb42 Mon Sep 17 00:00:00 2001
From: Andreas <andreasv@fsmpi.rwth-aachen.de>
Date: Mon, 10 Oct 2016 01:04:41 +0200
Subject: [PATCH] moved inserting of video in own function

---
 sorter.py | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/sorter.py b/sorter.py
index af01c08..b41213e 100644
--- a/sorter.py
+++ b/sorter.py
@@ -26,6 +26,15 @@ def to_ascii(inputstring):
 		asciistring = asciistring.replace(charset[0],charset[1])
 	return asciistring
 
+def insert_video(lectureid,dbfilepath,filepath,fileformatid):
+	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)
+		VALUES 
+		(?,0,?,?,"","","",?,?,?,?,"",?)''',
+		lectureid, dbfilepath, fileformatid, datetime.now(), datetime.now(), datetime.now(), -1, os.stat(filepath).st_size)
+	query('INSERT INTO sortlog (lecture_id,video_id,path,`when`) VALUES (?,?,?,?)', lectureid, video_id, dbfilepath, datetime.now())
+
+
 @app.route('/sort/now')
 @mod_required
 @sched_func(600)
@@ -130,13 +139,7 @@ def sort_now():
 						if not 'format' in data:
 							data['format'] = 0
 						# insert the video into videos_data and log
-						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)
-							VALUES 
-								(?,0,?,?,"","","",?,?,?,?,"",?)''',
-							matches[0]['id'], dbfilepath, data['format'], datetime.now(), datetime.now(), datetime.now(), -1, os.stat(filepath).st_size)
-						query('INSERT INTO sortlog (lecture_id,video_id,path,`when`) VALUES (?,?,?,?)', matches[0]['id'], video_id, dbfilepath, datetime.now())
+						insert_video( matches[0]['id'], dbfilepath, filepath, fileformatid)
 					else:
 						# if we couldn't match the video on exactly one lecture, log an error
 						matches_id = []
-- 
GitLab