Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Jannik Hellenkamp
website
Commits
25900280
Unverified
Commit
25900280
authored
Jul 18, 2018
by
Andreas Valder
Browse files
clean up comments in sorter
parent
edfacd0a
Changes
1
Hide whitespace changes
Inline
Side-by-side
sorter.py
View file @
25900280
...
...
@@ -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'
]
)
def
parseVideoFileName
(
splitFileName
):
# filenames: <handle>-<sorter>-<format>.mp4
data
=
{
'keywords'
:
[]}
for
fileNameChunk
in
splitFileName
:
fileNameChunk
=
fileNameChunk
.
replace
(
'.mp4'
,
''
)
...
...
@@ -95,7 +96,6 @@ def parseVideoFileName(splitFileName):
def
matchDatetimeOnLecture
(
lectures
,
date
,
time
):
matches
=
[]
# first try date and time (if one of them is set)
if
date
or
time
:
print
(
1
)
for
lecture
in
lectures
:
...
...
@@ -129,8 +129,6 @@ def matchFileNameOnFormat(splitFileName):
return
0
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 '-'
splitFileName
=
filename
.
replace
(
'_'
,
'-'
).
replace
(
' '
,
'-'
).
split
(
'-'
)
if
not
course
:
...
...
@@ -143,16 +141,18 @@ def sort_file(filename, course=None, lectures=None):
course
=
courses
[
0
]
if
not
lectures
:
lectures
=
query
(
'SELECT * from lectures where course_id = ?'
,
course
[
'id'
])
# parse all data from the file name
data
=
parseVideoFileName
(
splitFileName
)
# try to match the file on a single lecture
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
((
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
len
(
matches
)
==
0
:
matches
=
matchKeywordsOnLecture
(
lectures
,
data
[
'keywords'
])
else
:
if
not
len
(
matches
)
==
0
:
# only test lectures with the correct date/time, if we have any
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
fmt
=
matchFileNameOnFormat
(
splitFileName
)
return
matches
,
fmt
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment