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
ec3fe948
Unverified
Commit
ec3fe948
authored
Jul 19, 2018
by
Andreas Valder
Browse files
changed function naming
parent
7e1d089e
Changes
1
Hide whitespace changes
Inline
Side-by-side
sorter.py
View file @
ec3fe948
...
...
@@ -73,7 +73,7 @@ def insert_transcoded_video(jobid, jobtype, data, state, status):
return
insert_video
(
data
[
'lecture_id'
],
data
[
'output'
][
'path'
],
data
[
'format_id'
],
status
[
'hash'
],
status
[
'filesize'
],
status
[
'duration'
],
data
[
'source_id'
]
)
def
parse
VideoF
ile
N
ame
(
splitFileName
):
def
parse
_f
ile
_n
ame
(
splitFileName
):
# filenames: <handle>-<sorter>-<format>.mp4
data
=
{
'keywords'
:
[]}
for
fileNameChunk
in
splitFileName
:
...
...
@@ -94,7 +94,7 @@ def parseVideoFileName(splitFileName):
data
[
'keywords'
].
append
(
fileNameChunk
)
return
data
def
matchDatetimeOnLectur
e
(
lectures
,
date
,
time
):
def
filter_lectures_by_datetim
e
(
lectures
,
date
,
time
):
matches
=
[]
if
date
or
time
:
for
lecture
in
lectures
:
...
...
@@ -107,7 +107,7 @@ def matchDatetimeOnLecture(lectures, date, time):
matches
.
append
(
lecture
)
return
matches
def
matchKeywordsOnLecture
(
lectures
,
keywords
):
def
filter_lectures_by_keywords
(
lectures
,
keywords
):
for
field
in
[
'title'
,
'speaker'
,
'comment'
,
'internal'
]:
for
lecture
in
lectures
:
for
keyword
in
keywords
:
...
...
@@ -117,7 +117,7 @@ def matchKeywordsOnLecture(lectures, keywords):
return
[
lecture
]
return
[]
def
matchF
ile
N
ame
OnFormat
(
splitFileName
):
def
filter_formats_by_f
ile
n
ame
(
splitFileName
):
# default format is "unknown", with id 0
formats
=
query
(
'SELECT * FROM formats ORDER BY prio DESC'
)
for
videoformat
in
formats
:
...
...
@@ -141,19 +141,19 @@ def sort_file(filename, course=None, lectures=None):
if
not
lectures
:
lectures
=
query
(
'SELECT * from lectures where course_id = ?'
,
course
[
'id'
])
# parse all data from the file name
data
=
parse
VideoF
ile
N
ame
(
splitFileName
)
data
=
parse
_f
ile
_n
ame
(
splitFileName
)
# try to match the file on a single lecture
matches
=
matchDatetimeOnLectur
e
(
lectures
,
data
.
get
(
'date'
),
data
.
get
(
'time'
))
matches
=
filter_lectures_by_datetim
e
(
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
)):
if
not
len
(
matches
)
==
0
:
# only test lectures with the correct date/time, if we have any
matches
=
matchKeywordsOnLecture
(
matches
,
data
[
'keywords'
])
matches
=
filter_lectures_by_keywords
(
matches
,
data
[
'keywords'
])
else
:
# Else test for matches in all lectures of this course
matches
=
matchKeywordsOnLecture
(
lectures
,
data
[
'keywords'
])
matches
=
filter_lectures_by_keywords
(
lectures
,
data
[
'keywords'
])
# now we should have found exactly one match
fmt
=
matchF
ile
N
ame
OnFormat
(
splitFileName
)
fmt
=
filter_formats_by_f
ile
n
ame
(
splitFileName
)
return
matches
,
fmt
def
log_sort_error
(
course_id
,
path
,
matches
):
...
...
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