Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
website
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Roman Karwacik
website
Commits
03b27a0a
Commit
03b27a0a
authored
7 years ago
by
Julian Rother
Browse files
Options
Downloads
Patches
Plain Diff
Moved sorting algorithm out of sort_now
parent
336c92d7
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
sorter.py
+76
-64
76 additions, 64 deletions
sorter.py
with
76 additions
and
64 deletions
sorter.py
+
76
−
64
View file @
03b27a0a
...
@@ -52,44 +52,20 @@ def schedule_thumbnail(lectureid, filePath=None):
...
@@ -52,44 +52,20 @@ def schedule_thumbnail(lectureid, filePath=None):
data
=
'
{
"
lectureid
"
:
"'
+
str
(
lectureid
)
+
'"
,
"
path
"
:
"'
+
path
+
'"
}
'
data
=
'
{
"
lectureid
"
:
"'
+
str
(
lectureid
)
+
'"
,
"
path
"
:
"'
+
path
+
'"
}
'
query
(
'
INSERT INTO jobs (type, data, time_created) VALUES (
"
thumbnail
"
, ?, ?)
'
,
data
,
datetime
.
now
());
query
(
'
INSERT INTO jobs (type, data, time_created) VALUES (
"
thumbnail
"
, ?, ?)
'
,
data
,
datetime
.
now
());
@app.route
(
'
/internal/sort/now
'
)
def
sort_file
(
filename
,
course
=
None
,
lectures
=
None
):
@mod_required
@sched_func
(
600
)
def
sort_now
():
courses
=
query
(
'
SELECT * FROM courses
'
)
formats
=
query
(
'
SELECT * FROM formats ORDER BY prio
'
)
for
course
in
courses
:
modify
(
'
BEGIN
'
)
for
mountpoint
in
config
[
'
VIDEOMOUNT
'
]:
existingvideos
=
query
(
'
SELECT videos.path FROM videos JOIN lectures ON (videos.lecture_id = lectures.id) WHERE lectures.course_id = ?
'
,
course
[
'
id
'
])
knownerrors
=
query
(
'
SELECT sorterrorlog.path FROM sorterrorlog WHERE sorterrorlog.course_id = ?
'
,
course
[
'
id
'
])
ignorefiles
=
existingvideos
+
knownerrors
lectures
=
query
(
'
SELECT * from lectures where course_id = ?
'
,
course
[
'
id
'
])
coursepath
=
mountpoint
[
'
mountpoint
'
]
+
course
[
'
handle
'
]
try
:
files
=
os
.
listdir
(
coursepath
)
except
FileNotFoundError
:
files
=
[]
for
filename
in
files
:
try
:
# if the video is in the table "videos" already (with the correct course), skip it
ignore
=
False
for
file_to_ignore
in
ignorefiles
:
# path is something like
# vpnonline/08ws-swt/08ws-swt-081118.mp4
if
os
.
path
.
basename
(
filename
)
==
os
.
path
.
basename
(
file_to_ignore
[
'
path
'
]):
ignore
=
True
break
if
ignore
:
continue
filepath
=
coursepath
+
'
/
'
+
filename
# filenames: <handle>-<sorter>-<format>.mp4
# 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)
# "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
os
.
path
.
splitext
(
filename
)[
1
]
==
'
.mp4
'
:
if
not
course
:
continue
handle
=
'
-
'
.
join
(
splitfilename
[:
2
])
courses
=
query
(
'
SELECT * FROM courses WHERE handle = ?
'
,
handle
)
if
not
courses
:
return
[]
course
=
courses
[
0
]
if
not
lectures
:
lectures
=
query
(
'
SELECT * from lectures where course_id = ?
'
,
course
[
'
id
'
])
# we save all extraced data in a dict
# we save all extraced data in a dict
data
=
{
'
keywords
'
:
[]}
data
=
{
'
keywords
'
:
[]}
# parse the file name and save all data in 'data'
# parse the file name and save all data in 'data'
...
@@ -143,20 +119,56 @@ def sort_now():
...
@@ -143,20 +119,56 @@ def sort_now():
if
found
:
if
found
:
break
break
# now we should have found exactly one match
# now we should have found exactly one match
return
matches
@app.route
(
'
/internal/sort/now
'
)
@mod_required
@sched_func
(
600
)
def
sort_now
():
courses
=
query
(
'
SELECT * FROM courses
'
)
formats
=
query
(
'
SELECT * FROM formats ORDER BY prio
'
)
for
course
in
courses
:
modify
(
'
BEGIN
'
)
for
mountpoint
in
config
[
'
VIDEOMOUNT
'
]:
existingvideos
=
query
(
'
SELECT videos.path FROM videos JOIN lectures ON (videos.lecture_id = lectures.id) WHERE lectures.course_id = ?
'
,
course
[
'
id
'
])
knownerrors
=
query
(
'
SELECT sorterrorlog.path FROM sorterrorlog WHERE sorterrorlog.course_id = ?
'
,
course
[
'
id
'
])
ignorefiles
=
existingvideos
+
knownerrors
lectures
=
query
(
'
SELECT * from lectures where course_id = ?
'
,
course
[
'
id
'
])
coursepath
=
mountpoint
[
'
mountpoint
'
]
+
course
[
'
handle
'
]
try
:
files
=
os
.
listdir
(
coursepath
)
except
FileNotFoundError
:
files
=
[]
for
filename
in
files
:
try
:
# if the video is in the table "videos" already (with the correct course), skip it
ignore
=
False
for
file_to_ignore
in
ignorefiles
:
# path is something like
# vpnonline/08ws-swt/08ws-swt-081118.mp4
if
os
.
path
.
basename
(
filename
)
==
os
.
path
.
basename
(
file_to_ignore
[
'
path
'
]):
ignore
=
True
break
if
ignore
:
continue
filepath
=
coursepath
+
'
/
'
+
filename
if
not
os
.
path
.
splitext
(
filename
)[
1
]
==
'
.mp4
'
:
continue
matches
=
sort_file
(
filename
,
course
=
course
,
lectures
=
lectures
)
dbfilepath
=
mountpoint
[
'
prefix
'
]
+
course
[
'
handle
'
]
+
'
/
'
+
filename
dbfilepath
=
mountpoint
[
'
prefix
'
]
+
course
[
'
handle
'
]
+
'
/
'
+
filename
if
len
(
matches
)
==
1
:
if
len
(
matches
)
==
1
:
# now match the format
# now match the format
splitfilename
=
filename
.
replace
(
'
_
'
,
'
-
'
).
replace
(
'
'
,
'
-
'
).
split
(
'
-
'
)
# default format is "unknown", with id 0
fmt
=
0
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
()
formatstring
=
splitfilename
[
-
1
].
split
(
'
.
'
,
1
)[
0
].
lower
()
if
formatstring
in
videoformat
[
'
keywords
'
].
replace
(
'
,
'
,
'
'
).
split
(
'
'
):
if
formatstring
in
videoformat
[
'
keywords
'
].
replace
(
'
,
'
,
'
'
).
split
(
'
'
):
data
[
'
format
'
]
=
videoformat
[
'
id
'
]
fmt
=
videoformat
[
'
id
'
]
break
break
# default format is "unknown", with id 0
if
not
'
format
'
in
data
:
data
[
'
format
'
]
=
0
# insert the video into videos_data and log
# insert the video into videos_data and log
insert_video
(
matches
[
0
][
'
id
'
],
dbfilepath
,
filepath
,
data
[
'
format
'
]
)
insert_video
(
matches
[
0
][
'
id
'
],
dbfilepath
,
filepath
,
fmt
)
else
:
else
:
# if we couldn't match the video on exactly one lecture, log an error
# if we couldn't match the video on exactly one lecture, log an error
matches_id
=
[]
matches_id
=
[]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment