Commit bc240936 authored by Andreas Valder's avatar Andreas Valder
Browse files

fixed sorter

parent 080cdbc5
......@@ -23,22 +23,15 @@ def sort_log():
@app.route('/sort/now')
@mod_required
@sched_func(600)
def sort_now():
return sort_wraper()
@sched_func(60)
def sort_auto():
pass
# return sort_wraper()
def sort_wraper():
courses = query('SELECT * FROM courses')
formats = query('SELECT * FROM formats ORDER BY prio')
for c in courses:
for basepath in config['VIDEOMOUNT']:
for mountpoint in config['VIDEOMOUNT']:
existingvideos = query('SELECT videos.path FROM videos JOIN lectures ON (videos.lecture_id = lectures.id) WHERE lectures.course_id = ?',c['id'])
lectures = query('SELECT * from lectures where course_id = ?',c['id'])
coursepath = basepath+c['handle']
coursepath = mountpoint['mountpoint']+c['handle']
try:
files = os.listdir(coursepath)
except FileNotFoundError:
......@@ -49,8 +42,8 @@ def sort_wraper():
exists = False
for e in existingvideos:
# vpnonline/08ws-swt/08ws-swt-081118.mp4
e_filename = e['path'].split('/',2)[1]
if f == e_filename:
e_filename = e['path']
if os.path.basename(f) == os.path.basename(e_filename):
exists = True
break
if exists:
......@@ -118,16 +111,17 @@ def sort_wraper():
if not 'format' in data:
data['format'] = 0
modify('BEGIN')
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'],c['handle']+'/'+f,data['format'],datetime.now(),datetime.now(),datetime.now(),-1,os.stat(coursepath+'/'+f).st_size)
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'],mountpoint['prefix']+c['handle']+'/'+f,data['format'],datetime.now(),datetime.now(),datetime.now(),-1,os.stat(coursepath+'/'+f).st_size)
query('INSERT INTO sortlog (lecture_id,video_id,path,`when`) VALUES (?,?,?,?)',matches[0]['id'],video_id,c['handle']+'/'+f,datetime.now())
modify('COMMIT')
# for debuging only
# else:
# d = []
# for m in matches:
# d.append(m['id'])
# print('failed',{"data":data,"path":f,"results":d})
except Exception:
# for debuging only
else:
d = []
for m in matches:
d.append(m['id'])
print('failed',{"data":data,"path":f,"results":d})
except Exception as exc:
# raise exc
pass
......
Supports Markdown
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