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

clean up comments in sorter

parent edfacd0a
Branches
No related tags found
No related merge requests found
...@@ -74,6 +74,7 @@ def insert_transcoded_video(jobid, jobtype, data, state, status): ...@@ -74,6 +74,7 @@ def insert_transcoded_video(jobid, jobtype, data, state, status):
insert_video(data['lecture_id'], data['output']['path'], data['format_id'], status['hash'], status['filesize'], status['duration'], data['source_id'] ) insert_video(data['lecture_id'], data['output']['path'], data['format_id'], status['hash'], status['filesize'], status['duration'], data['source_id'] )
def parseVideoFileName(splitFileName): def parseVideoFileName(splitFileName):
# filenames: <handle>-<sorter>-<format>.mp4
data = {'keywords': []} data = {'keywords': []}
for fileNameChunk in splitFileName: for fileNameChunk in splitFileName:
fileNameChunk = fileNameChunk.replace('.mp4','') fileNameChunk = fileNameChunk.replace('.mp4','')
...@@ -95,7 +96,6 @@ def parseVideoFileName(splitFileName): ...@@ -95,7 +96,6 @@ def parseVideoFileName(splitFileName):
def matchDatetimeOnLecture(lectures, date, time): def matchDatetimeOnLecture(lectures, date, time):
matches = [] matches = []
# first try date and time (if one of them is set)
if date or time: if date or time:
print(1) print(1)
for lecture in lectures: for lecture in lectures:
...@@ -129,8 +129,6 @@ def matchFileNameOnFormat(splitFileName): ...@@ -129,8 +129,6 @@ def matchFileNameOnFormat(splitFileName):
return 0 return 0
def sort_file(filename, course=None, lectures=None): def sort_file(filename, course=None, lectures=None):
# filenames: <handle>-<sorter>-<format>.mp4
# "sorter" musst be found with fuzzy matching. "sorter" musst be one or more of the following types: (inside the loop)
# '_' and ' ' are handled like '-' # '_' and ' ' are handled like '-'
splitFileName = filename.replace('_','-').replace(' ','-').split('-') splitFileName = filename.replace('_','-').replace(' ','-').split('-')
if not course: if not course:
...@@ -143,16 +141,18 @@ def sort_file(filename, course=None, lectures=None): ...@@ -143,16 +141,18 @@ def sort_file(filename, course=None, lectures=None):
course = courses[0] course = courses[0]
if not lectures: if not lectures:
lectures = query('SELECT * from lectures where course_id = ?', course['id']) lectures = query('SELECT * from lectures where course_id = ?', course['id'])
# parse all data from the file name
data = parseVideoFileName(splitFileName) data = parseVideoFileName(splitFileName)
# try to match the file on a single lecture # try to match the file on a single lecture
matches = matchDatetimeOnLecture(lectures, data.get('date'), data.get('time')) matches = matchDatetimeOnLecture(lectures, data.get('date'), data.get('time'))
# if we can't match exactly based on date and time, we have to match keywords # if we can't match exactly based on date and time, we have to match keywords
if ((len(matches) != 1) and (len(data['keywords']) > 0)): if ((len(matches) != 1) and (len(data['keywords']) > 0)):
#only test lectures with the correct date/time, if we have any. Else test for matches in all lectures of this course if not len(matches) == 0:
if len(matches) == 0: # only test lectures with the correct date/time, if we have any
matches = matchKeywordsOnLecture(lectures, data['keywords'])
else:
matches = matchKeywordsOnLecture(matches, data['keywords']) matches = matchKeywordsOnLecture(matches, data['keywords'])
else:
# Else test for matches in all lectures of this course
matches = matchKeywordsOnLecture(lectures, data['keywords'])
# now we should have found exactly one match # now we should have found exactly one match
fmt = matchFileNameOnFormat(splitFileName) fmt = matchFileNameOnFormat(splitFileName)
return matches, fmt return matches, fmt
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment