Skip to content
Snippets Groups Projects
Commit bc240936 authored by Andreas Valder's avatar Andreas Valder
Browse files

fixed sorter

parent 080cdbc5
No related branches found
No related tags found
No related merge requests found
...@@ -23,22 +23,15 @@ def sort_log(): ...@@ -23,22 +23,15 @@ def sort_log():
@app.route('/sort/now') @app.route('/sort/now')
@mod_required @mod_required
@sched_func(600)
def sort_now(): def sort_now():
return sort_wraper()
@sched_func(60)
def sort_auto():
pass
# return sort_wraper()
def sort_wraper():
courses = query('SELECT * FROM courses') courses = query('SELECT * FROM courses')
formats = query('SELECT * FROM formats ORDER BY prio') formats = query('SELECT * FROM formats ORDER BY prio')
for c in courses: 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']) 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']) lectures = query('SELECT * from lectures where course_id = ?',c['id'])
coursepath = basepath+c['handle'] coursepath = mountpoint['mountpoint']+c['handle']
try: try:
files = os.listdir(coursepath) files = os.listdir(coursepath)
except FileNotFoundError: except FileNotFoundError:
...@@ -49,8 +42,8 @@ def sort_wraper(): ...@@ -49,8 +42,8 @@ def sort_wraper():
exists = False exists = False
for e in existingvideos: for e in existingvideos:
# vpnonline/08ws-swt/08ws-swt-081118.mp4 # vpnonline/08ws-swt/08ws-swt-081118.mp4
e_filename = e['path'].split('/',2)[1] e_filename = e['path']
if f == e_filename: if os.path.basename(f) == os.path.basename(e_filename):
exists = True exists = True
break break
if exists: if exists:
...@@ -118,16 +111,17 @@ def sort_wraper(): ...@@ -118,16 +111,17 @@ def sort_wraper():
if not 'format' in data: if not 'format' in data:
data['format'] = 0 data['format'] = 0
modify('BEGIN') 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()) query('INSERT INTO sortlog (lecture_id,video_id,path,`when`) VALUES (?,?,?,?)',matches[0]['id'],video_id,c['handle']+'/'+f,datetime.now())
modify('COMMIT') modify('COMMIT')
# for debuging only # for debuging only
# else: else:
# d = [] d = []
# for m in matches: for m in matches:
# d.append(m['id']) d.append(m['id'])
# print('failed',{"data":data,"path":f,"results":d}) print('failed',{"data":data,"path":f,"results":d})
except Exception: except Exception as exc:
# raise exc
pass pass
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment