diff --git a/sorter.py b/sorter.py
index af01c081c1eee2d5934ac23456297425a3ac5b65..b41213e70cc0d9fbdf9d33da2fc0d988872e3b8c 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 = []