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

extended sorter to work with old folder strukture

parent 1adfa144
Branches
No related tags found
No related merge requests found
# Defaults for development ,do not use in production!
DEBUG = False
VIDEOPREFIX = 'https://videoag.fsmpi.rwth-aachen.de'
VIDEOMOUNT = 'files/'
VIDEOMOUNT = ['files/protected/','files/pub/','files/vpnonline/']
#SECRET_KEY = 'something random'
DB_SCHEMA = 'db_schema.sql'
......
......@@ -19,22 +19,32 @@ def sort_log():
'''))
@app.route('/sort/now')
@sched_func(60)
@mod_required
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']:
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 = config['VIDEOMOUNT']+c['handle']
coursepath = basepath+c['handle']
try:
files = os.listdir(coursepath)
except FileNotFoundError:
files = []
for f in files:
try:
# if the video is in the table "videos" already, skip it
exists = False
for e in existingvideos:
......@@ -45,7 +55,6 @@ def sort_now():
break
if exists:
continue
filepath = coursepath + '/' + f
# filenames: <handle>-<sorter>-<format>.mp4
# sorter musst be found with fuzzy matching. musst be one or more of the following: (inside the loop)
......@@ -109,7 +118,7 @@ def sort_now():
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(),session['user']['givenName'],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'],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
......@@ -118,6 +127,8 @@ def sort_now():
# for m in matches:
# d.append(m['id'])
# print('failed',{"data":data,"path":f,"results":d})
except Exception:
pass
if 'ref' in request.values:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment