Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Video AG Infrastruktur
website
Commits
aa180d51
Unverified
Commit
aa180d51
authored
Jul 19, 2018
by
Andreas Valder
Browse files
cleaned up sorter
parent
ec3fe948
Changes
1
Hide whitespace changes
Inline
Side-by-side
sorter.py
View file @
aa180d51
...
@@ -73,7 +73,11 @@ def insert_transcoded_video(jobid, jobtype, data, state, status):
...
@@ -73,7 +73,11 @@ def insert_transcoded_video(jobid, jobtype, data, state, status):
return
return
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
parse_file_name
(
splitFileName
):
def
split_filename
(
filename
):
# '_' and ' ' are handled like '-'
return
filename
.
replace
(
'_'
,
'-'
).
replace
(
' '
,
'-'
).
split
(
'-'
)
def
parse_filename
(
splitFileName
):
# filenames: <handle>-<sorter>-<format>.mp4
# filenames: <handle>-<sorter>-<format>.mp4
data
=
{
'keywords'
:
[]}
data
=
{
'keywords'
:
[]}
for
fileNameChunk
in
splitFileName
:
for
fileNameChunk
in
splitFileName
:
...
@@ -117,19 +121,21 @@ def filter_lectures_by_keywords(lectures, keywords):
...
@@ -117,19 +121,21 @@ def filter_lectures_by_keywords(lectures, keywords):
return
[
lecture
]
return
[
lecture
]
return
[]
return
[]
def
extract_format_keyword_from_filename
(
splitFileName
):
return
splitFileName
[
-
1
].
split
(
'.'
,
1
)[
0
].
lower
()
def
filter_formats_by_filename
(
splitFileName
):
def
filter_formats_by_filename
(
splitFileName
):
# default format is "unknown", with id 0
formatstring
=
extract_format_keyword_from_filename
(
splitFileName
)
formats
=
query
(
'SELECT * FROM formats ORDER BY prio DESC'
)
formats
=
query
(
'SELECT * FROM formats ORDER BY prio DESC'
)
for
videoformat
in
formats
:
for
videoformat
in
formats
:
# we match the last part of the file name without the extension
# we match the last part of the file name without the extension
formatstring
=
splitFileName
[
-
1
].
split
(
'.'
,
1
)[
0
].
lower
()
if
formatstring
in
videoformat
[
'keywords'
].
replace
(
','
,
' '
).
split
(
' '
):
if
formatstring
in
videoformat
[
'keywords'
].
replace
(
','
,
' '
).
split
(
' '
):
return
videoformat
[
'id'
]
return
videoformat
[
'id'
]
# default format is "unknown", with id 0
return
0
return
0
def
sort_file
(
filename
,
course
=
None
,
lectures
=
None
):
def
sort_file
(
filename
,
course
=
None
,
lectures
=
None
):
# '_' and ' ' are handled like '-'
splitFileName
=
split_filename
(
filename
)
splitFileName
=
filename
.
replace
(
'_'
,
'-'
).
replace
(
' '
,
'-'
).
split
(
'-'
)
if
not
course
:
if
not
course
:
handle
=
splitFileName
[
0
]
handle
=
splitFileName
[
0
]
if
splitFileName
[
0
].
endswith
(
'ws'
)
or
splitFileName
[
0
].
endswith
(
'ss'
):
if
splitFileName
[
0
].
endswith
(
'ws'
)
or
splitFileName
[
0
].
endswith
(
'ss'
):
...
@@ -141,7 +147,7 @@ def sort_file(filename, course=None, lectures=None):
...
@@ -141,7 +147,7 @@ def sort_file(filename, course=None, lectures=None):
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
# parse all data from the file name
data
=
parse_file
_
name
(
splitFileName
)
data
=
parse_filename
(
splitFileName
)
# try to match the file on a single lecture
# try to match the file on a single lecture
matches
=
filter_lectures_by_datetime
(
lectures
,
data
.
get
(
'date'
),
data
.
get
(
'time'
))
matches
=
filter_lectures_by_datetime
(
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
...
...
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