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
No related branches found
No related tags found
No related merge requests found
# Defaults for development ,do not use in production! # Defaults for development ,do not use in production!
DEBUG = False DEBUG = False
VIDEOPREFIX = 'https://videoag.fsmpi.rwth-aachen.de' VIDEOPREFIX = 'https://videoag.fsmpi.rwth-aachen.de'
VIDEOMOUNT = 'files/' VIDEOMOUNT = ['files/protected/','files/pub/','files/vpnonline/']
#SECRET_KEY = 'something random' #SECRET_KEY = 'something random'
DB_SCHEMA = 'db_schema.sql' DB_SCHEMA = 'db_schema.sql'
......
...@@ -19,22 +19,32 @@ def sort_log(): ...@@ -19,22 +19,32 @@ def sort_log():
''')) '''))
@app.route('/sort/now') @app.route('/sort/now')
@sched_func(60)
@mod_required @mod_required
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']:
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 = config['VIDEOMOUNT']+c['handle'] coursepath = basepath+c['handle']
try: try:
files = os.listdir(coursepath) files = os.listdir(coursepath)
except FileNotFoundError: except FileNotFoundError:
files = [] files = []
for f in files: for f in files:
try:
# if the video is in the table "videos" already, skip it # if the video is in the table "videos" already, skip it
exists = False exists = False
for e in existingvideos: for e in existingvideos:
...@@ -45,7 +55,6 @@ def sort_now(): ...@@ -45,7 +55,6 @@ def sort_now():
break break
if exists: if exists:
continue continue
filepath = coursepath + '/' + f filepath = coursepath + '/' + f
# filenames: <handle>-<sorter>-<format>.mp4 # filenames: <handle>-<sorter>-<format>.mp4
# sorter musst be found with fuzzy matching. musst be one or more of the following: (inside the loop) # 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(): ...@@ -109,7 +118,7 @@ def sort_now():
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(),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()) 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
...@@ -118,6 +127,8 @@ def sort_now(): ...@@ -118,6 +127,8 @@ def sort_now():
# 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:
pass
if 'ref' in request.values: 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